将Eclipse Luna与m2eclipse一起使用,我有一个父Maven项目(facturas_root
)和两个从它继承的Maven模块(sharepoint_ws
和api_sharepoint
)。
sharepoint_ws
仅用于生成JAXWS类以连接到Sharepoint WebServices,因此我下载了相关的WSDL并将其作为项目的资源包含在内。在generate-sources
阶段,它可以正常运行并在target\generated-sources\ws-consume\mypackage\
中生成来源。
现在,问题在于我api_sharepoint
导入sharepoint_ws
依赖项,但它没有检测到任何类。我认为这是因为生成的类不在src/main/java
,所以我添加了一个插件来复制它们。现在,问题是在sharepoint_ws
的编译阶段,它找到每个类的源文件的两倍并抛出错误。
我的pom.xml - >构建
<plugins>
<!-- clean /src/main/java and /target/generated-sources -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/src/main/java/es</directory>
</fileset>
<fileset>
<directory>${basedir}/target/generated-sources</directory>
</fileset>
</configuration>
</execution>
</executions>
</plugin>
<!-- generate jaxws -->
<plugin>
<groupId>org.jboss.ws.plugins</groupId>
<artifactId>maven-jaxws-tools-plugin</artifactId>
<version>1.1.2.Final</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsconsume</goal>
</goals>
<configuration>
<wsdls>
<wsdl>${basedir}/resources/lists.wsdl</wsdl>
</wsdls>
<targetPackage>es.ssib.otic.facturas.sharepoint_ws</targetPackage>
<outputDirectory>${basedir}/target/generated-sources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- copy sources -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target/generated-sources/wsconsume</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
为了尝试排除target/generated-sources
,我添加了这个:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<configuration>
<excludes>
<exclude>**/target/generated-sources/*.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
如上所述,我会评论&#34;复制&#34;插件,取决于sharepoint_ws
的模块没有任何类可用;我确实使用它,我在
每个生成的列表[ERROR] /C:/Users/s004256/workspace/facturas_root/sharepoint_ws/src/main/java/es/ssib/otic/facturas/sharepoint_ws/DeleteList.java:[34,8]重复类:es。 ssib.otic.facturas.sharepoint_ws.DeleteList
。
答案 0 :(得分:1)
首先,我建议你最好将target/generated-sources
声明为源文件夹,而不是在这里和那里复制文件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>initialize</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
这应该足以让Maven编译目标/ generated-sources / * .java并将它们全部打包在库中,并且Eclipse也可以将目标/生成源识别为源目录(在执行Maven之后)更新项目)。
顺便说一下:您应该按照正确的顺序将插件绑定到阶段 :如果将所有任务绑定到“generate-sources”,则无法保证以何种顺序他们会被处决吗? “编译”阶段也是如此:你必须在编译阶段之前正确设置源文件夹及其包含和排除。
查看Default Maven Lifecycle并尝试为您的任务选择不同的连续阶段。