jaxb circular dependency maven compile error - java

I've code which generates classes and these are referenced in main package
I'm using jaxb2 plugin and running on commandline. my code creates generate-sources ,but compile fails saying symbol can't find.
can somebody help me what's going wrong. here is my plugin in pom.xml
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaIncludes>
<schemaInclude>*-1.0.xsd</schemaInclude>
</schemaIncludes>
<bindingIncludes>
<bindingInclude>*bindings-1.0.xjb</bindingInclude>
</bindingIncludes>
</configuration>
</plugin>
</plugins>

Related

How to use JPA-Entities as a dependency with maven

I got in a multimodule-maven-project an entities project in which there are some Entity and DAO classes. Also there are some integration-tests which I'd like to seperate in an own project called entities-IT.
Now I've put the entities-project as an dependency to the entites-IT-project but if I run the build there occurs an error message like this:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project entities-IT: Compilation failure
[ERROR] /some/path/to/project/entities-IT/src/it/java/com/example/persistence/dao/ExampleDaoIT.java:[25,38] cannot access com.example.persistence.ExampleEntity
[ERROR] bad class file: /some/path/to/project/persistence/ExampleEntity.class
[ERROR] illegal start of class file
[ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath.
This is strange because in the target folder there are all of mentioned .class files and the folderstructure is also correct.
Is there anything to take notice if using Entities as a dependency in another project?
In the pom.xml of the entities-project there is some code-generation going on:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>process</id>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/metamodel</outputDirectory>
<compilerArguments>
-Aeclipselink.persistencexml=${project.basedir}/src/main/java/META-INF/persistence.xml
</compilerArguments>
<processors>
<processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
and then I have the dependency set in the entities-IT-project:
<dependency>
<groupId>example</groupId>
<artifactId>entities</artifactId>
<version>${parent.version}</version>
</dependency>
and run the tests with the failsafe-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/it/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

ClassNot found exception after buidling jar in maven

I creat application in javaFX. But after packaging it in maven it shows ClassNot Found exception : packageName.(Main Class Name).
I wonder I create it many application in maven but here it gives error what to do please give me any advice.
Here is my pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>uz.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
My main class located inside of uz package what might be wrong here ?

maven - why is my pom.xml NOT removing META-INF/*.SF, META-INF/*.DSA and META-INF/*.RSA?

On my pom.xml I have the following <plugin> section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludes>META-INF/*.SF</excludes>
<excludes>META-INF/*.DSA</excludes>
<excludes>META-INF/*.RSA</excludes>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes/lib/</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
But, whenever I build the project with a mvn clean install -U, some .SF, .DSA and .RSA are copied to the built jar file and I need to remove them manually.
How to correct this?
The correct usage of tag <excludes> is following:
<excludes>META-INF/*.SF,META-INF/*.DSA,META-INF/*.RSA</excludes>

Bind jar:test-jar to package phase

I have a pom snippet containing the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.jason.Main</mainClass>
</manifest>
<manifestEntries>
<Class-Path>resources/</Class-Path>
</manifestEntries>
</archive>
<executions>
<execution>
<id>package-test-jar</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
When i run "mvn package", the plugin does not execute and my test jar does not get created. When i run "mvn jar:test-jar" my jar gets created. Does anyone know why that might be?
Thank you kindly,
Jason
You misplaced the <executions> block: it should be outside of the <configuration> one.
As you wrote it, it means that you pass a structure of parameters named "executions" to the configuration of the maven jar plugin, which is simply ignored.
Here's the correct configuration:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
... your configuration data ...
</configuration>
<executions>
<execution>
<id>package-test-jar</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Note that specifying the "package" phase for your execution isn't necessary, since the maven jar plugin is attached by default to this phase.

Unable to access binding information for class

I know this question has been asked over and over again, and its always an Eclipse Maven JIXB problem. I don't think it has ever been resolved.
When I try to test my code I get the following error
Unable to access binding information for class com.generated.xml.addbooking.Request
Make sure the binding has been compiled
java.lang.NoSuchFieldException: JiBX_bindingList
at java.lang.Class.getDeclaredField(Class.java:1882)
at org.jibx.runtime.BindingDirectory.getBindingList(BindingDirectory.java:68)
Now I have generated the POJOs and have generated a binding.xml file using the following POM.
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.5</version>
<executions>
<execution>
<id>schemata-a</id>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<schemaLocation>src/main/resources/schemas</schemaLocation>
<includeSchemas>
<includeSchema>AddBookingRequest.xsd</includeSchema>
</includeSchemas>
<schemaBindingDirectory>src/main/java</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>binding.xml</includeSchemaBindings>
</includeSchemaBindings>
<options>
<package>com.generated.xml.addbooking</package>
</options>
</configuration>
</execution>
<execution>
<id>schemata-b</id>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<schemaLocation>src/main/resources/schemas</schemaLocation>
<includeSchemas>
<includeSchema>SearchHotelPriceRequest.xsd</includeSchema>
</includeSchemas>
<schemaBindingDirectory>src/main/java</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBindings>binding.xml</includeSchemaBindings>
</includeSchemaBindings>
<options>
<package>com.generated.xml.searchhotel</package>
</options>
</configuration>
</execution>
<execution>
<id>compile-binding</id>
<goals>
<goal>bind</goal>
</goals>
<configuration>
<schemaBindingDirectory>src/main/java</schemaBindingDirectory>
<includes>
<include>binding.xml</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
As you can see the POJOs are generated, the binding.xml is generated but the bind is not being run for some reason?
Need to add another plug in that points to 1.5 or above for some reason maven 2 plugins are compiling against 1.3. Was causing the binding problem which uses generics.
I added the following to my plugin
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument></compilerArgument>
</configuration>
</plugin>

Categories