score:13
What you should see in your project explorer is a container named "Maven Dependencies" in place of the usual "Referenced libraries". This means m2eclipse is managing your build path.
In my case, to achieve this, I checked "Include Modules" and unchecked "Skip Maven compiler plugin when processing resources" on the "Maven" section of Project->Properties.
score:0
To generate Java source files from .proto
files use Protocol Buffers Plugin which works out-of-the-box in eclipse Oxygen.
Basic usage (see here for detailed description):
make sure that native
protoc
compiler is installed on your systemupdate your
pom.xml
file:make sure you use at least Java 6 (Java 7+ is recommended)
add plugin invocation
add the corresponding dependency for
com.google.protobuf:protobuf-java
put your .proto files inside project's
src/main/proto
directoryupdate the project (via
Maven -> Update project...
)
Example pom.xml
:
<project>
...
<build>
<plugins>
<!-- Require at least Java 6 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Generate .java files from .proto definitions -->
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.1</version>
<configuration>
<protocExecutable>/usr/local/bin/protoc</protocExecutable>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.5.1</version>
</dependency>
...
</dependencies>
...
</project>
Some additional notes:
if
protoc
executable is in the PATH theprotocExecutable
configuration entry can be omittedtest-only protobuf message definitions can be put into project's
src/test/proto
directoryI recommend installing Protocol Buffer Descriptor Editor (marketplace link)
Good luck!
score:1
score:2
Did you try to refresh the Eclipse project?
(source: oyvindhauge.com)
When an external tool generate new files or updates old ones, Eclipse will not be able to detect the change until the next request.
Another option would be to define a new Custom builder, specifying for that builder to "refresh resources upon completion":
alt text http://www.cs.lth.se/EDA180/2005/Verktyg/eclipse_refresh.gif
score:4
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.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
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!
score:5
- Right-click project and select Properties
- Choose Java Build Pathfrom the left and select the Source tab
- Click Add Folder
- Select the bin directory and click OK
- (project/target/generated-sources/xxxx) Click OK and Refresh the project
score:9
I had this issue with code generated using Maven and wsdl2java and here's what I did in Eclipse Juno to resolve it. Assume my project is named project1:
- Right-click project1 and select Properties
- Choose Java Build Path from the left and select the Libraries tab
- Click Add Class Folder
- Select the bin directory and click OK (project1/target/generated-sources/bin)
- Click OK and Refresh the project
As an added bonus you can also attach the source code:
- Click the arrow next to the new class folder you just created
- Click on Source attachment
- Click the Edit button
- Set the Path to /project1/target/generated-sources/axis2/src
- Click OK
score:12
Personally I resolved this problem by setting up the generated classes as a seperate project and made it a dependency in my main (non-generated) project. I was using wsdl2java to generate webservice classes so the "source" in my sub-project was the wdsl and xsds. Worked well even when the wsdl was changing regularly.
score:26
m2eclipse doesn't support this. You must manually add the folder target/generated-sources
as a source folder. When you tell m2eclipse to "Update Project Configuration", this will be overwritten and you have to restore it.
Also, make sure that Eclipse looks for changes in the workspace.
There might be some issues, though. Eventually, you'll run into errors that some class can't be compiled because some other class can't be resolved. Code completion will work, though. The root cause of this issue is that Eclipse gets confused when Maven changes class files in target
.
To solve this, you must tell Eclipse to compile to a different place than Maven.
score:35
m2eclipse supports this. First, add the path to your build path:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<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>
Second, add support for that to m2e:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>parse-version</goal>
<goal>add-source</goal>
<goal>maven-version</goal>
<goal>add-resource</goal>
<goal>add-test-resource</goal>
<goal>add-test-source</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
The second step might not be necessary, if your eclipse installation has installed the "org.eclipse.m2e.discovery.lifecyclemapping.buildhelper.xml" plugin. This plugin is available via Window -> Preferences -> Maven -> Discovery. Currently, that does not work here at Eclipse Kepler, therefore, I fetched the JAR (linked from the xml shown in the Catalog URL) and extracted the fragments from org.eclipse.m2e.discovery.lifecyclemapping.buildhelper.xml
by hand.
Source: stackoverflow.com
Related Query
- How do I get Eclipse to resolve classes generated with Maven 2?
- How can I get Eclipse work with Maven and SVN correctly?
- When you get a stack trace in Eclipse with SDK classes in the stack, how can you see the SDK sources?
- Build with Maven in Eclipse Photon - How to get console colours?
- In Eclipse with m2e, how to get "Quick Javadoc" (F2) to display for Maven dependencies?
- How can I teach Eclipse with AngularJS Plugin to resolve directives and CSS classes in templates
- In Java eclipse IDE, how to get all classes with the corresponding methods of a project in one view
- How does Eclipse compile classes with only a JRE?
- How do I get verbose output from Maven in the Eclipse console?
- How to get rid of the warning: Use '$' instead of '.' for inner classes in Eclipse
- Maven - how to handle generated classes
- How to get gdb working with Eclipse CDT under windows (fails to find source code)
- How to run maven from eclipse with the -e switch
- How to download sources and javadoc artifacts with Maven Eclipse plugin from other repository?
- How do I get Eclipse to switch to SVN view on synchronize with repository?
- How to use the webservice-client classes generated with Eclipse?
- How to get angular2 to work in eclipse with typescript
- How to integrate maven generated vaadin project into eclipse vaadin plugin?
- How to get Eclipse SWT Browser component running on Ubuntu 11.04 (Natty Narwhal) with Webkit?
- How to create a Maven project in Eclipse with AspectJ support?
- How to use Tomcat with maven correctly in Eclipse
- How to integrate maven with eclipse
- How to use scope "test" and junit correctly with maven and eclipse
- How to get started with a bare-bones Eclipse + PyDev
- How to get Eclipse Warnings when compiling with maven?
- Java classes get compiled via external maven inside eclipse but not (with same maven) from command line
- How to run JSR269 annotaion processor in Eclipse Kepler with Java 7 & Maven
- How to configure Eclipse to automatically insert import statements for classes with a single package match
- How do I get Eclipse and Maven to download the JARs I need?
- Eclipse -> Run as -> Run on server - How to get it to work with JBoss?
More Query from same tag
- Reciprocal in Android code for calculator
- Errors in attrs.xml
- on save compile and deploy with maven eclipse and weblogic
- How to Configure IntelliJ IDEA 14 for your migration from Eclipse
- Selenium New Wait Until Condition Doesnt Work Forced to use Thread.Sleep
- Eclipse plug-in creates new workspace everytime when its executed
- Recommendations for preparing a configured Eclipse package for distribution to a dev team
- Perl Script to run Junit test cases and unistall apk
- PMD-Plugin in Eclipse/Juno not installable through marketplace
- Transitive dependencies unresolved at runtime in eclipse wtp
- Count the number of matching elements in two arrays in Java and how to generate more than 100
- Eclipse linking JDK
- Tycho raises error that Eclipse IDE does not: Cannot refer to a non-final variable
- How can I change project resource location in a project?
- unchecked generics usage warning on getAllClassMetadata() instance method of org.hibernate.SessionFactory
- How to resolve issue with Maven dependencies "Failed to execute goal on project"
- Duplicate variables (null copy) in loop?
- unalbe to create destination directory for ant target in eclipse
- OpenCV 2.4.13.4 dll link error
- In Eclipse what is the difference between "Open Type"/"Open Resource"?
- JFrame don't work when adding an Image
- GlassFish server not start in eclipse
- Eclipse / PyDev Stop button not working with OSError: [WinError 6] The handle is invalid error
- Unable to open Firefox browser with given URL using Java on eclipse
- Eclipse formatting of assignment via method call
- XMPP IQ result parsing issue
- upload maven project file on save to google app engine like netbeans
- Java - Exporting Runnable JAR that includes Referenced Libraries (ERROR: Invalid signature file digest for Manifest main attributes)
- com.thoughtworks.xstream.converters.ConversionException while running jmeter script using maven eclipse
- Eclipse: How to set the main method for a project?