M2E and having maven generated source folders as e

2019-01-04 06:10发布

I have a maven project in eclipse and have maven goals that run annotation processors to generate code. The output folder for this code is target/generated-sources/apt.

In order for eclipse to see this generated code I need to add target/generated-sources/apt as a source folder to the eclipse project.

However, this causes there to be an error of type "Maven Configuration Problem" saying

Project configuration is not up-to-date with pom.xml. Run project configuration update

I think I understand why this is the case as eclipse has a different set of source folders to maven's set. But I need this different set, as I need eclipse to be able to see the generated source folders...

When doing a pure maven built, these source folders will be included in the build, by maven.

btw, I have upgraded to the official eclipse release of the maven eclipse plugin, m2e 1.0 - what used to be m2eclipse. I'd like to see if I can find a work around/solution to this with the m2e plugin before I have to go back to the old m2eclipse version.

11条回答
在下西门庆
2楼-- · 2019-01-04 06:25

In m2e 1.0 the handling of Maven plugins has changed. You might be lacking a specific m2e extension for your code generating plugin. Here is all the documentation I managed to find.

This bug report may also be relevant.

查看更多
姐就是有狂的资本
3楼-- · 2019-01-04 06:26

This was what I found that worked good using spring 3.1.1 which does have the 3.0.6 version as well in it. Once I got the plugins setup and put into the correct area of the pom and included the argline and endorseddirs to have the java sources put out into the target/generated-sources/cxf folder then maven generated the sources ok.

....

 <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>

If your wsdl folder is in ${basedir}/src/main/resources it'll find it automatically

Hope this helps! ~wildbill

查看更多
我只想做你的唯一
4楼-- · 2019-01-04 06:27

After switching to new versions of m2e/maven/apt,... i had builderrors because of the duplicated files, caused by the added buildpath by the buildhelper, so i needed to remove the "apt-generated"-Folders from the buildhelper.

To fix the Problem in Eclipse, not adding the "apt-generated"-folder via Update Maven Configuration in M2E, i've written a M2E Plugin to fix this problem. It adds the outputDirectories configured in the maven-apt-plugin to the buildpath of the Project.

https://apt-m2e.googlecode.com

查看更多
劳资没心,怎么记你
5楼-- · 2019-01-04 06:28

You need to attach the source directory with the build-helper-plugin.

Like so:

 <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>

You will also need to:

查看更多
【Aperson】
6楼-- · 2019-01-04 06:34

Eclipse Java EE IDE for Web Developers. Version: Juno Service Release 1

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

mvn clean install

work perfectly.

But in eclipse I have the same error on Asinc class.

Just press F5 on project. Fix this problem.

查看更多
在下西门庆
7楼-- · 2019-01-04 06:34

the configuration to the build helper plugin did work for us.

but be aware, that the destination folder always has to be equal to the configuration of the plugin u're using for the annotation processing itself.

for example the maven-processor-plugin uses the target folder ${project.build.directory}/generated-sources/apt as default. if you wish another destination for your generated source files you can set it by the tag as shown below.

<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>
查看更多
登录 后发表回答