How do I get Eclipse to resolve classes generated with Maven 2?

前端 未结 9 893
日久生厌
日久生厌 2020-12-12 22:11

I\'m using Google Protocol Buffers to generate some Java classes for my project. Using Maven 2 and its \"antrun\" plugin, these classes are freshly generated before compile,

9条回答
  •  无人及你
    2020-12-12 22:30

    How can I get IDE support (code completion etc.) for the generated code?

    Typically I would add the m2e lifecycle-mapping plugin to the pom.xml file as described in @koppor's answer. However adding per-eclipse code to my pom.xml files is not an option at work which is mostly an IntelliJ shop.

    My solution first adds the build-helper-maven-plugin to the pom.xml which works fine from the command line but not in eclipse.

    
        org.codehaus.mojo
        build-helper-maven-plugin
        
            
                generate-sources
                
                    add-source
                
                
                    
                        ${project.build.directory}/generated-sources/
                    
                
            
        
    
    

    To fix eclipse I installed the Apt M2E Connector from the Eclipse Marketplace. I think things started working right after I restarted and then rebuilt all of my projects. I now see the following in my source dirs:

    src/main/java
    target/generated-sources
    ...
    

    Feature!

提交回复
热议问题