如何在Maven中为生成的源创建文件夹?(How to create folder for generated sources in Maven?)

编程入门 行业动态 更新时间:2024-10-19 17:34:28
如何在Maven中为生成的源创建文件夹?(How to create folder for generated sources in Maven?)

我必须使用wsimport生成源代码,我认为它应该转到/ target / generated-sources / wsimport而不是/ src / main / java。

问题是wsimport需要在执行之前创建目标文件夹并且失败。 我可以先使用任何maven插件创建该目录。 我可以用蚂蚁做,但我更喜欢把它保存在POM中。

I have to generate sources using wsimport and i assume that it should go to /target/generated-sources/wsimport rather than /src/main/java.

The problem is that wsimport needs target folder created before execution and it fails. Can I create that dir first using any maven plugin. I can do it using ant but i prefer to keep it in POM.

最满意答案

我必须使用wsimport生成源代码,我认为它应该转到/ target / generated-sources / wsimport而不是/ src / main / java。

这是一个正确的假设。

问题是wsimport需要在执行之前创建目标文件夹并且失败。 我可以先使用任何maven插件创建该目录。 我可以用蚂蚁做,但我更喜欢把它保存在POM中。

我从来没有注意到这个问题(并将其视为一个bug,一个插件必须处理这些事情)。

奇怪的是, WsImportMojo似乎通过调用File#mkdirs() :

public void execute() throws MojoExecutionException { // Need to build a URLClassloader since Maven removed it form the chain ClassLoader parent = this.getClass().getClassLoader(); String originalSystemClasspath = this.initClassLoader( parent ); try { sourceDestDir.mkdirs(); getDestDir().mkdirs(); File[] wsdls = getWSDLFiles(); if(wsdls.length == 0 && (wsdlUrls == null || wsdlUrls.size() ==0)){ getLog().info( "No WSDLs are found to process, Specify atleast one of the following parameters: wsdlFiles, wsdlDirectory or wsdlUrls."); return; } ... } ... }

你能说明你如何调用插件及其配置吗?

I have to generate sources using wsimport and i assume that it should go to /target/generated-sources/wsimport rather than /src/main/java.

This is a correct assumption.

The problem is that wsimport needs target folder created before execution and it fails. Can I create that dir first using any maven plugin. I can do it using ant but i prefer to keep it in POM.

I never noticed this problem (and would consider it as a bug, a plugin has to take care of such things).

The weird part is that WsImportMojo seems to do what is has to by calling File#mkdirs():

public void execute() throws MojoExecutionException { // Need to build a URLClassloader since Maven removed it form the chain ClassLoader parent = this.getClass().getClassLoader(); String originalSystemClasspath = this.initClassLoader( parent ); try { sourceDestDir.mkdirs(); getDestDir().mkdirs(); File[] wsdls = getWSDLFiles(); if(wsdls.length == 0 && (wsdlUrls == null || wsdlUrls.size() ==0)){ getLog().info( "No WSDLs are found to process, Specify atleast one of the following parameters: wsdlFiles, wsdlDirectory or wsdlUrls."); return; } ... } ... }

Could you show how you invoke the plugin and its configuration?

更多推荐

本文发布于:2023-08-01 01:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1351374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中为   文件夹   如何在   Maven   sources

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!