I use mvn compile and I have a pom that uses jaxws-maven-plugin to create client classes, which it does fine. I get all my classes inside target>generated-sources>wsimport> path. But the classes aren't being added to my classpath. So my project does not compile.
plugin in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
<packageName>org.tempuri</packageName>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
<!-- needs extension true otherwise wont generate trade web service stub. Still shows error SOAP binding 1.2 -->
<extension>true</extension>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The issue was the version of the plugin jaxws-maven-plugin. For some reason I was using version 2.3.1-b20150201.1248. When I changed to2.3 it worked fine.
The old version generated the proxy classes just fine but it did not add to classpath in Eclipse. There were no errors, But when I opened the project in Netbeans when I tried to generated the proxy classes from WSDL I got the error
No implementation for org.eclipse.aether.impl.ArtifactDescriptorReader
was bound.
So I changed version of the plugin like this answer said:
https://stackoverflow.com/a/25277703/1754020
and it worked fine.
Related
The Project I am working on has the regular src/main and src/test folders, but they recently introduced src/integration-test, which is supposed to contain, as the name suggests, integration-tests.
Unfortunately I can't seem to make this work with Maven and Eclipse. I tried adding a source folder, but Eclipse is not able to resolve the dependencies needed for the integration-tests and fails to compile the test-classes. I also can't start the tests with JUnit.
The source folder was added to the build path, but it did not help.
All other developers in my team use IntelliJ and report that they don't have these issues at all. But it´s bound to work with Eclipse as well, right?
You should handle this with maven by adding the source folder to the build:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
In this example the build will add a src/integration folder where you can put other test classes.
For more information check the build helper plugin documentation.
I have the following configuration for jaxb2-maven-plugin version 2.4
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceType>wsdl</sourceType>
<sources>
<source>src/main/resources/wsdl/osg_data_sync_service_1_0.wsdl</source>
<source>src/main/resources/wsdl/parlayx_sms_notification_service_2_2.wsdl</source>
</sources>
<outputDirectory>${project.basedir}/src/main/generated</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
But when i run mvn jaxb2:xjc, no classes are generated.
What could I be overlooking?
I have pasted one of the wsdl here
EDIT
As it was mentioned that this might be a possible duplicate, I downgraded the plugin to version 1.6 and changed configuration to the following and still no classes generated.
<configuration>
<wsdl>true</wsdl>
<xmlschema>false</xmlschema
<schemaFiles>osg_data_sync_interface_1_0.wsdl,parlayx_sms_notification_interface_2_2.wsdl</schemaFiles>
<schemaDirectory>src/main/resources/wsdl</schemaDirectory>
<outputDirectory>${project.basedir}/src/main/generated</outputDirectory>
</configuration>
Full pom here as site was complaining too much code
It finally works with version 1.6 after cleaning. Why does version 2.4 not work?
Finally got version 2.4 to work. I don't know exactly what the issue was but I was able to generate the classes by running mvn generate-sources instead of mvn jaxb2:xjc as suggested in the comments. I also had to run mvn clean first
I have used Maven plugin to generate classes in my project. However even after trying padding it explicitly from project build path, eclipse is unable to recognize it. It says,
"AbcBaseListener cannot be resolved to a type"
Project auto build is also ON.
Check 2 things:
1)
The important hint here is "class folder". Eclipse expects .class files in there, source code will be ignored.
To fix this, add this plugin to your POM:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
and update the project (Maven -> Update ...).
The other option would be to manually add another source folder to the build path but that will get lost whenever m2e updates the project configuration from the POM.
2) Make sure your generated files are having package names;
Use below code inside your g4 file after grammar Abc;
#header {
package antlr4;
}
I want to temporarily exclude some directory from compilation, so I configure maven-compiler-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/foo/**/*.java</exclude>
</excludes>
</configuration>
</plugin>
Everything works fine from the command line and Eclipse, but in IntelliJ IDEA I got compilation errors in excluded directory. Any idea what might be causing the problem?
It's an open issue, please follow for updates.
I had the same issue migrating maven projects.
I got it working by choosing below option:
File > Settings > Build, Execution, Deployment > Build Tools > Maven >
Runner
Check the 'Delegate IDE build/run actions to Maven' option.
Instruction is available here:
IntelliJ documentation
I found this question while trying to solve Java 9 module-info compilation in IntelliJ IDEA.
I want my library compiled with Java 8, but at the same time I want it to have module-info (which can be compiled only with JDK 9+). A solution of this problem suggested by Maven: exclude module-info from compilation with JDK 8 and include if JDK 9 is used. It works with command line but IDEA fails to compile such project. It is possible to adjust IDEA Compile configuration by adding module info to Excludes, but I wanted more clear solution.
It is possible to trick IDEA by adding Maven Profile with extended list of source directories:
<profile>
<!-- This profile enables two pass compilation:
1. Compile all sources with Java 9 target version (including module-info.java)
2. Recompile all sources with Java 8 target version, but module-info.java
After this all classes will have Java 8 bytecode (version 52), while
module-info.class will have Java 9 bytecode (version 53) -->
<id>J9-module</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>8</release>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
<configuration>
<compileSourceRoots>
<sourceRoot>${project.basedir}/src/main/java</sourceRoot>
<sourceRoot>${project.basedir}/src/main/java9</sourceRoot>
</compileSourceRoots>
<release>9</release>
</configuration>
</execution>
<execution>
<id>java-8-recompile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
With the profile shown above IDEA itself will compile only standard src/main/java.
For my team, I'd like to configure maven/eclipse build to automatically generate Java code from *.proto files (in a project that uses gRPC). Currently one needs to run mvn generate-source or mvn protobuf:compile (as in plugin usage page). Or what is the same add Run configuration to invoke maven goal compile.
Whenever Eclipse Maven project is refreshed (Alt+F5) or IDE is restarted, project is rebuilt but without what should appear in target/generated, thus turning project into red. So one need to generate and refresh project (F5). UPDATE Eclipse has needed source folders configured in .clathpath file.
As I know that should be m2e connector, but I could only find one https://github.com/masterzen/m2e-protoc-connector for the oldest Googles plugin com.google.protobuf.tools:maven-protoc-plugin, that is even not mentioned currently at https://github.com/grpc/grpc-java
We use exactly referenced/recommended
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
that is:
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.1.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Related:
Linking to generated Java protobuf code in Eclipse
looked at this but that author was using other older, not supported now plugin : Eclipse build loop caused by protobuf generated code (related to Maven Project Builder)
P.P.S That plugin https://github.com/igor-petruk/protobuf-maven-plugin however has continuation as https://github.com/os72/protoc-jar-maven-plugin
Instead of using org.xolstice.maven.plugins:protobuf-maven-plugin my team has used com.github.os72:protoc-jar-maven-plugin to generate the message classes. I believe they are the same since under the hood they all seem to be using the tools from Google.
I am not using any m2e connectors for this plugin (Edit: protoc-jar-maven-plugin's m2e connector is bundled with it so no extra installation is needed, which is why it seemed like I wasn't using one, but technically I was, but this doesn't really matter). Unfortunately the changes in the .proto file are not "automatically" propagated to the generated .java files, you need to manually run Maven or trigger the project to be built in Eclipse (instructions below), but fortunately the target/generated-sources file is not vanishing or emptying or anything strange like what you describe.
If you want to rebuild the .java files from the .proto classes without using mvn clean compile from the command line you can clean the Eclipse project . Project → Clean... → select your project → Select build option (only shows if you have "Build Automatically" from the Project menu is unchecked).
I was able to do this in the latest Eclipse Neon (it will probably work in later ones too, but I don't know for certain).
Below is the POM I am using. I don't think it requires any special explanation, my solution is to simply use a different plugin than the one you are using. (If some explanation is needed I'll be happy to provide it though.)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.jacksonbailey</groupId>
<artifactId>protobuf-m2e-sample</artifactId>
<version>0.1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.1.0.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocVersion>3.1.0</protocVersion>
<inputDirectories>
<include>src/main/resources</include>
</inputDirectories>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
for protobuf-maven-plugin
Thanks to sergei-ivanov answer in https://github.com/xolstice/protobuf-maven-plugin/issues/16, that gave link https://github.com/trustin/os-maven-plugin#issues-with-eclipse-m2e-or-other-ides :
One need to download os-maven-plugin-x.x.x.Final.jar (the version as in your pomx.ml) and put it into the <ECLIPSE_HOME>/plugins directory.
After that Eclipse will generate source on project clean, including after Maven -update project... (Alt+F5), but not after Project -> Build (or with default Build Automatically). Also on IDE start it will not compile.
Yes, that is illogical:
Project - Clean will generate and compile Java source
but
Project - Build will not.
P.S. Raised Bug 507412
Both eclipse and vscode can automatically compile proto when changed.
<plugin>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>detect</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.12.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.32.1:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
See: https://github.com/trustin/os-maven-plugin#issues-with-eclipse-m2e-or-other-ides