M2E和maven生成的源文件夹作为eclipse源文件夹

我在eclipse中有一个Maven项目,并且有运行注释处理器来生成代码的Maven目标。 这个代码的输出文件夹是target / generated-sources / apt。

为了让eclipse看到这个生成的代码,我需要将target / generated-sources / apt作为源文件夹添加到eclipse项目中。

但是,这会导致出现types为“Maven Configuration Problem”的错误

项目configuration与pom.xml不是最新的。 运行项目configuration更新

我想我明白为什么这是事实,因为eclipse有一组不同的源文件夹到maven的集合。 但我需要这个不同的设置,因为我需要日食能够看到生成的源文件夹…

在构build纯maven时,这些源文件夹将被maven包含在构build中。

顺便说一句,我已经升级到maven eclipse插件官方的eclipse发布,m2e 1.0 – 以前是m2eclipse。 我想看看是否可以在m2e插件之前find解决方法,然后再回到旧的m2eclipse版本。

您需要将源代码目录与build-helper插件连接起来 。

像这样:

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${project.build.directory}/generated-sources/java/</source> </sources> </configuration> </execution> </executions> </plugin> 

您还需要:

用鼠标右键单击错误消息:

项目configuration与pom.xml不同步运行项目configuration更新

在“问题视图”中select“ 快速修复” ,然后单击“ 完成”以select默认的更新项目configuration 。 这解决了它。

在切换到新版本的m2e / maven / apt之后,…因为由buildhelper添加的构buildpath导致了重复的文件,所以我需要从buildhelper中删除“apt-generated”-Folders。

为了解决Eclipse中的问题,不通过M2E中的更新Mavenconfiguration添加“apt-generated”文件夹,我写了一个M2E插件来解决这个问题。 它将maven-apt-plugin中configuration的outputDirectories添加到Project的构buildpath中。

https://apt-m2e.googlecode.com

在m2e 1.0中,Maven插件的处理已经改变。 您可能缺less代码生成插件的特定m2e扩展。 这是我设法find的所有文件 。

这个错误报告也可能是相关的。

https://bugs.eclipse.org/bugs/show_bug.cgi?id=350081

请求CXF JIRA(请参阅1 )在cxf-codegen插件本身中添加生命周期映射。 这需要m2e 1.1,但是我认为比cxf项目之外的连接器更好的方法是假设生命周期映射API的变化比cxf-codegen-plugin和cxf要less。

您也可以使用发现目录中可用的buildhelper m2e连接器。 我使用的是Eclipse 3.7

适用于Web开发人员的Eclipse Java EE IDE。 版本:Juno服务版本1

 mvn archetype:generate \ -DarchetypeGroupId=org.codehaus.mojo \ -DarchetypeArtifactId=gwt-maven-plugin \ -DarchetypeVersion=2.5.0 mvn clean install 

完美地工作。

但是在eclipse中,我在Asinc类中有同样的错误。

只需在项目上按F5。 解决这个问题。

这是我发现使用spring 3.1.1,它也有3.0.6版本。 一旦我得到了插件设置,并将其放入pom的正确区域,并包含argline和endorseddirs以将java源文件放到target / generated-sources / cxf文件夹中,那么maven就会生成源代码。

….

  <properties>... <dependencyManagement> <dependencies>..... </dependencyManagement> <dependencies> <dependency>.... </dependencies> <!-- *************************** Build process ************************************* --> <build> <finalName>eSurety</finalName> <plugins> <!-- Force Java 6 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.4</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <!-- Deployent on AS from console <plugin> <groupId>org.jboss.as.plugins</groupId> <artifactId>jboss-as-maven-plugin</artifactId> <version>${version.jboss.as.maven.plugin}</version> </plugin> --> <!-- wildbill added tomcat plugin --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.0</version> </plugin> <!-- Surefire plugin before 2.9 version is buggy. No need to declare here, it's being referenced below w/ the version <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.12</version> </plugin> --> <!-- developer added these --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <compilerArguments> <endorseddirs>target/generated-sources/cxf</endorseddirs> </compilerArguments> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12</version> <configuration> <forkMode>once</forkMode> <argLine>-Djava.endorsed.dirs=target/generated-sources/cxf</argLine> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <compilerArguments> <endorseddirs>target/generated-sources/cxf</endorseddirs> </compilerArguments> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <forkMode>once</forkMode> <argLine>-Djava.endorsed.dirs=target/generated-sources/cxf</argLine> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <configuration> <artifactItems> <artifactItem> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.2</version> </artifactItem> <artifactItem> <groupId>javax.xml.ws</groupId> <artifactId>jaxws-api</artifactId> <version>2.2</version> </artifactItem> </artifactItems> <outputDirectory>target/generated-sources/cxf</outputDirectory> </configuration> </plugin> </plugins> </build> <!-- *********************** Profiles ************************************ --> <profiles> <profile> <!-- When built in OpenShift the 'openshift' profile will be used when invoking mvn. --> <!-- Use this profile for any OpenShift specific customization your app will need. --> <!-- By default that is to put the resulting archive into the 'deployments' folder. --> <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html --> <id>projName</id> <build> <plugins> <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>2.5.2</version> <executions> <execution> <id>process-sources</id> <phase>generate-sources</phase> <configuration> <fork>once</fork> <additionalJvmArgs>-Djava.endorsed.dirs=target/generated-sources/cxf</additionalJvmArgs> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-xjc</artifactId> <version>2.2</version> </dependency> </dependencies> </plugin> <!-- Actual war created in default target dir --> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.2</version> </plugin> </plugins> </build> </profile> </profiles> 

如果你的wsdl文件夹在$ {basedir} / src / main / resources中,它会自动find它

希望这可以帮助! 〜wildbill

万一由于某种原因,你不能使用构build助手插件最简单的方法(尽pipe不是方便和有点乏味),我发现处理这是:

  1. 将生成的源代码分离到自己的项目或子模块中。
  2. 当您正在处理父项目时,您将希望保持该项目处于closures状态或不导入到Eclipse中。
  3. 在需要生成代码的父项目中,确保现在依赖于通过Maven Pom依赖项生成的源代码项目。
  4. 当您需要更新生成的代码时,请转到生成的代码项目并运行mvn install 。 现在通过右键单击并selectMaven-> Update Project …来刷新父项目

这通常适用于使用半静态源代码生成的项目,如SOAP WSDL(Apache CXF)或从数据库生成的代码(jOOQ)。 对于APT和其他类似于AspectJ的代码,它不能很好地工作,因为你经常编辑源代码。

构build帮助器插件的configuration对我们来说确实有效。

但请注意,目标文件夹总是必须等于插件用于注释处理本身的configuration。

例如maven-processor-plugin使用目标文件夹$ {project.build.directory} / generated-sources / apt作为默认值。 如果您希望生成的源文件的另一个目标位置,则可以通过如下所示的标记来设置它。

 <plugin> <groupId>org.bsc.maven</groupId> <artifactId>maven-processor-plugin</artifactId> <version>2.1.1</version> <executions> <execution> <id>process</id> <goals> <goal>process</goal> </goals> <phase>process-sources</phase> <configuration> <defaultOutputDirectory>apt_generated</defaultOutputDirectory> <processors> <processor>com.any.processor.invoker</processor> </processors> </configuration> </execution> </executions> </plugin> 

这是解决scheme

  1. 打开标记视图(窗口>显示视图
  2. 用鼠标右键单击错误消息
  3. select快速修复
  4. 点击完成