I am using bnd-export-maven-plugin to generate a runnable jar, with the pom.xml defined as follows:
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<testResources>
<testResource>
<directory>test</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>${bnd-maven-plugin-version}</version>
<executions>
<execution>
<id>default-bnd-process</id>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-export-maven-plugin</artifactId>
<version>${bnd-maven-plugin-version}</version>
<configuration>
<failOnChanges>false</failOnChanges>
<bndruns>
<bndrun>com.xyz.masterdata.application.services.bndrun</bndrun>
</bndruns>
</configuration>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.jaxrs</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.http.whiteboard</artifactId>
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>6.0.3</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>${swagger-maven-plugin-version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs-api-version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet-api-version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25</version>
</dependency>
<dependency>
<groupId>org.ops4j.pax.jdbc</groupId>
<artifactId>pax-jdbc-mysql</artifactId>
<version>1.3.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<dependency>
<groupId>com.xyz.foundation</groupId>
<artifactId>com.xyz.foundation.common.provider</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xyz.foundation</groupId>
<artifactId>com.xyz.foundation.common.provider</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xyz.foundation</groupId>
<artifactId>com.xyz.foundation.web.rest.provider</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xyz.masterdata.party</groupId>
<artifactId>com.xyz.masterdata.party.logic.provider</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xyz.masterdata.party</groupId>
<artifactId>com.xyz.masterdata.party.rest.provider</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
My bndrun file is given here:
-runfw: org.eclipse.osgi;version=3.13
-runee: JavaSE-1.8
-runprovidedcapabilities: ${native_capability}
-resolve.effective: active
-runproperties: \
osgi.console=,\
org.osgi.service.http.port=9001,\
osgi.console.enable.builtin=false
-runrequires: \
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)',\
bnd.identity;id='com.mysql.jdbc',\
bnd.identity;id='org.ops4j.pax.jdbc.mysql',\
bnd.identity;id='com.fasterxml.jackson.core.jackson-core',\
bnd.identity;id='com.fasterxml.jackson.core.jackson-databind',\
bnd.identity;id='com.fasterxml.jackson.jaxrs.jackson-jaxrs-base',\
bnd.identity;id='com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider',\
bnd.identity;id='com.xyz.foundation.common.provider',\
bnd.identity;id='com.xyz.foundation.web.rest.api',\
bnd.identity;id='com.xyz.foundation.web.rest.provider',\
bnd.identity;id='com.xyz.masterdata.party.logic.provider',\
bnd.identity;id='com.xyz.masterdata.party.rest.provider',\
osgi.identity;filter:='(osgi.identity=com.xyz.masterdata.application.services)'
-runbundles: \
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
com.xyz.masterdata.application.services;version='[1.0.0,1.0.1)',\
com.fourthiq.masterdata.party.logic.provider;version='[0.0.0,0.0.1)',\
com.mysql.jdbc;version='[5.1.46,5.1.47)',\
org.apache.aries.jpa.javax.persistence_2.1;version='[2.7.0,2.7.1)',\
org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\
org.apache.felix.configurator;version='[1.0.6,1.0.7)',\
org.apache.felix.gogo.command;version='[1.0.2,1.0.3)',\
org.apache.felix.gogo.runtime;version='[1.0.10,1.0.11)',\
org.apache.felix.gogo.shell;version='[1.0.0,1.0.1)',\
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
org.ops4j.pax.jdbc.mysql;version='[1.3.5,1.3.6)',\
org.osgi.service.transaction.control;version='[1.0.0,1.0.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
tx-control-provider-jdbc-xa;version='[1.0.0,1.0.1)',\
tx-control-service-xa;version='[1.0.0,1.0.1)',\
com.fasterxml.jackson.core.jackson-annotations;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.core.jackson-core;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.core.jackson-databind;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.jaxrs.jackson-jaxrs-base;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider;version='[2.9.8,2.9.9)',\
com.xyz.foundation.common.provider;version='[0.0.0,0.0.1)',\
com.xyz.foundation.web.rest.api;version='[0.0.0,0.0.1)',\
com.xyz.foundation.web.rest.provider;version='[0.0.0,0.0.1)',\
org.apache.aries.javax.jax.rs-api;version='[1.0.0,1.0.1)',\
com.xyz.masterdata.party.rest.provider;version='[0.0.0,0.0.1)',\
io.swagger.core.v3.swagger-annotations;version='[2.0.7,2.0.8)',\
org.apache.aries.jax.rs.whiteboard;version='[1.0.1,1.0.2)',\
org.apache.felix.http.jetty;version='[4.0.6,4.0.7)',\
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.apache.servicemix.specs.annotation-api-1.3;version='[1.3.0,1.3.1)',\
org.osgi.service.jaxrs;version='[1.0.0,1.0.1)',\
org.osgi.util.function;version='[1.1.0,1.1.1)',\
org.osgi.util.promise;version='[1.1.0,1.1.1)',\
tx-control-provider-jpa-xa;version='[1.0.0,1.0.1)'
Unfortunately, I get the following error when launching the application:
randy#MacBook-Pro target % java -jar com.xyz.masterdata.application.services.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/osgi/framework/ServiceListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at aQute.launcher.pre.EmbeddedLauncher.executeWithRunPath(EmbeddedLauncher.java:145)
at aQute.launcher.pre.EmbeddedLauncher.findAndExecute(EmbeddedLauncher.java:106)
at aQute.launcher.pre.EmbeddedLauncher.main(EmbeddedLauncher.java:51)
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.ServiceListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 14 more
Note that I may use the referenced .bndrun file to launch the application just fine from within Eclipse, and the application is generated just fine when using gradle.
The maven command I used to build this runnable jar file is simply as follows:
mvn clean package
I have further extracted the content of the runnable jar file, with the following showing embedded jar files.
So it is clear the required jar files are not making it into the runnable jar file. But it is unclear to me why this is.
I am making the transition from gradle to maven, however, and seem to be stuck on this last item. Pointers for resolving are appreciated.
Thanks,
Randy
Maybe you are missing a dependency to the felix framework. Not sure why it then works in bndtools though.
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>6.0.3</version>
</dependency>
I think the problem is that you specify "-runfw: org.eclipse.osgi;version=3.13" which selects the equinox framework. You should use bndtools view to switch to the felix framework.
Maybe it works in eclipse as eclipse runs on equinox .. not sure.
I am trying to run my sample project which uses Maven- testNG-cucumber and deploy it using docker . here is my Dockerfile
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
COPY testng.xml .
COPY src .
RUN mvn clean verify
POM.XML
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>Sample</projectName>
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
<buildNumber>1</buildNumber>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
above scenario works completely fine when i run the project locally using mvn verify .Then i try to build the image using docker build -t sample . . this time i have got the following error .
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project Sample: There are test failures.
[ERROR] Please refer to /docker/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] Cannot find class in classpath: TestRunner
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] Cannot find class in classpath: TestRunner
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork
(ForkStarter.java:673)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork
(ForkStarter.java:535)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run
(ForkStarter.java:280)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run
(ForkStarter.java:245)
[ERROR] at
org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider
(AbstractSurefireMojo.java:1124)
[ERROR] at
org.apache.maven.plugin.surefire.AbstractSurefireMojo.
executeAfterPreconditionsChecked(AbstractSurefireMojo.java:954)
Any help would be much appreciated
I had a similar issue and after using older version of maven-surefire-plugin solved my issue.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<!-- latest version does not work well with JUnit5 -->
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.3</version>
</dependency>
</dependencies>
</plugin>
I had the same issue, I just used the clean command for maven.
clean -f pom.xml
If you are working in IntelliJ you can use maven plugin instead.
On the right side click maven Tab -> plugins -> clean -> clean:clean
I faced the same issue but it got resolved with different solution, you can check below problems as well.
Actually i have given the wrong testNG.xml path in POM.XML that's why it was throwing me that error. Please cross verify your testNG.xml path.
The above exception log clearly states that it is unable to find the TestRunner class. Make sure your TestRunner class is on the classpath.
I was getting a similar exception due to there were few extra characters added in the Classes section of the TestNG XML file. Its worth checking TestNG XML file is correct and doesn't contain any extra chars than needed structure.
I faced the same issue. It got resolved after the maven clean build and then ran the test.
After updating Firefox I changed versions of libraries to higher ones. Following errors appeard:
[ERROR] Dependency convergence error for commons-collections:commons-collections:3.2.2 paths to dependency are:
[ERROR] +-net:serenity.pom.gradle:0.0.1-SNAPSHOT
[ERROR] +-net.serenity-bdd:serenity-core:1.1.29-rc.3
[ERROR] +-org.seleniumhq.selenium:htmlunit-driver:2.20
[ERROR] +-commons-collections:commons-collections:3.2.2
[ERROR] and
[ERROR] +-net:serenity.pom.gradle:0.0.1-SNAPSHOT
[ERROR] +-net.serenity-bdd:serenity-core:1.1.29-rc.3
[ERROR] +-io.appium:java-client:3.3.0
[ERROR] +-commons-validator:commons-validator:1.4.1
[ERROR] +-commons-collections:commons-collections:3.2.1
[ERROR] and
[ERROR] +-net:serenity.pom.gradle:0.0.1-SNAPSHOT
[ERROR] +-net.serenity-bdd:serenity-core:1.1.29-rc.3
[ERROR] +-commons-collections:commons-collections:3.2.2
[ERROR] ]
[ERROR] -> [Help 1]
Dependency tree looks like:
[INFO] +- net.serenity-bdd:serenity-core:jar:1.1.29-rc.3:test
[INFO] | +- org.seleniumhq.selenium:htmlunit-driver:jar:2.20:test
[INFO] | +- commons-collections:commons-collections:jar:3.2.2:test
[INFO] | +- io.appium:java-client:jar:3.3.0:test
[INFO] | | \- commons-validator:commons-validator:jar:1.4.1:test
[INFO] | | +- commons-beanutils:commons-beanutils:jar:1.8.3:test
[INFO] | | \- commons-digester:commons-digester:jar:1.8.1:test
How to solve this problem?
Can I manually switch the library?
PS
Here is my pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>1.1.29-rc.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-jbehave</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>verify</id>
<phase>validate</phase>
<goals>
<goal>enforce</goal>
</goals>
<inherited>true</inherited>
</execution>
</executions>
<configuration>
<failFast>true</failFast>
<rules>
<DependencyConvergence></DependencyConvergence>
<requireReleaseDeps>
<onlyWhenRelease>true</onlyWhenRelease>
</requireReleaseDeps>
<requireJavaVersion>
<version>${java.version}</version>
</requireJavaVersion>
</rules>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<configuration>
<includes>
<include>src/test/java/*.java </include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>1.1.29-rc.1</version>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>1.1.29-rc.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
See POM Reference, Exclusions:
Exclusions explicitly tell Maven that you don't want to include the specified project that is a dependency of this dependency (in other words, its transitive dependency).
See also Apache Maven Enforcer Rules, Dependency Convergence:
If a project has two dependencies, A and B, both depending on the same artifact, C, this rule will fail the build if A depends on a different version of C then the version of C depended on by B.
[...]
And this will succeed.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.6.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
I know I'm late to the party, but after scratching my head for 8-10 hours, I came around this solution which fixes the problem when you don't have control over different poms where the different versions of dependencies are used at different places. So, I thought it's worth sharing.
#Gerold's answer is an ideal one (source: Maven wiki). But, it works for the case when you are the owner of all the dependencies and have the time, luxury and write permission to fix the issue at the root. In my case, I was using a company-wide global parent pom which had different versions set in different places, so I was facing this issue. I wanted to find some way to fix this on my end without changing the global parent pom.
To fix this, in your project's parent pom, you can specify the exact version which matches with rest of the places and override the versions specified by the global parent poms at different places. You can add this block in your project's parent pom
<!-- ============================= -->
<!-- DEPENDENCY MANAGEMENT -->
<!-- ============================= -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<!-- This version should be consistent
with versions at other places -->
<version>3.2.2</version>
</dependency>
</dependencies>
</dependencyManagement>
HTH
Or just remove the maven enforcer all together if you really/temporarily need to get past this issue.
I'm writing a client (library) to consume a REST service in order to give users of the library simple get and set methods to work with, hiding complexities of REST APIs.
I'm using jackson 2.4.0 and jersey 2.6 to consume the REST service.
The goal is to create a uber.jar which will be a self-contained jar file with all the dependencies resolved. To achieve this, I'm using Maven shade plugin.
i'm also relocating all the dependent classes using the shade plugin.
My pom file is as below :
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jackson.version>2.4.0</jackson.version>
<jersey.version>2.6</jersey.version>
</properties>
<build>
<plugins>
<!-- Shade plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org</pattern>
<shadedPattern>shaded.org</shadedPattern>
</relocation>
<relocation>
<pattern>com</pattern>
<shadedPattern>shaded.com</shadedPattern>
<excludes>
<exclude>com.example.*</exclude>
</excludes>
</relocation>
<relocation>
<pattern>javax</pattern>
<shadedPattern>shaded.javax</shadedPattern>
<excludes>
<exclude>javax.xml.*</exclude>
</excludes>
</relocation>
<relocation>
<pattern>jersey</pattern>
<shadedPattern>shaded.jersey</shadedPattern>
</relocation>
<relocation>
<pattern>javassist</pattern>
<shadedPattern>shaded.javassist</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/.*</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- Shade plugin -->
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
</dependencies>
If i write a test class within the same project in which this library is, everything works fine. But, if i when i use this shaded library in a separate standalone project (which is what the goal is), i get following exception :
Feb 06, 2015 5:28:07 PM shaded.org.glassfish.hk2.internal.ServiceLocatorFactoryImpl getGenerator
WARNING: Cannot find a default implementation of the HK2 ServiceLocatorGenerator
Feb 06, 2015 5:28:08 PM shaded.org.glassfish.jersey.internal.Errors logErrors
WARNING: The following warnings have been detected: WARNING: HK2 service reification failed for [shaded.org.glassfish.jersey.message.internal.DataSourceProvider] with an exception:
MultiException stack 1 of 2
java.lang.NoClassDefFoundError: shaded/javax/activation/DataSource
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getDeclaredConstructors(Unknown Source)
at shaded.org.jvnet.hk2.internal.Utilities$7.run(Utilities.java:1316)
at shaded.org.jvnet.hk2.internal.Utilities$7.run(Utilities.java:1312)
at java.security.AccessController.doPrivileged(Native Method)
at shaded.org.jvnet.hk2.internal.Utilities.getAllConstructors(Utilities.java:1312)
at shaded.org.jvnet.hk2.internal.Utilities.findProducerConstructor(Utilities.java:1233)
at shaded.org.jvnet.hk2.internal.DefaultClassAnalyzer.getConstructor(DefaultClassAnalyzer.java:78)
at shaded.org.glassfish.jersey.internal.inject.JerseyClassAnalyzer.getConstructor(JerseyClassAnalyzer.java:143)
at shaded.org.jvnet.hk2.internal.Utilities.getConstructor(Utilities.java:203)
at shaded.org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:147)
at shaded.org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:200)
at shaded.org.jvnet.hk2.internal.SystemDescriptor.internalReify(SystemDescriptor.java:649)
........
........
Caused by: java.lang.ClassNotFoundException: shaded.javax.activation.DataSource
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 65 more
MultiException stack 2 of 2
java.lang.IllegalArgumentException: Errors were discovered while reifying SystemDescriptor(
implementation=shaded.org.glassfish.jersey.message.internal.DataSourceProvider
contracts={shaded.javax.ws.rs.ext.MessageBodyWriter,shaded.javax.ws.rs.ext.MessageBodyReader}
scope=shaded.javax.inject.Singleton
qualifiers={}
descriptorType=CLASS
descriptorVisibility=NORMAL
metadata=
rank=0
loader=shaded.org.glassfish.hk2.utilities.binding.AbstractBinder$2#4fb64261
proxiable=null
proxyForSameScope=null
analysisName=null
id=10
locatorId=1
identityHashCode=1113619023
reified=false)
at shaded.org.jvnet.hk2.internal.SystemDescriptor.reify(SystemDescriptor.java:615)
at shaded.org.jvnet.hk2.internal.ServiceLocatorImpl.reifyDescriptor(ServiceLocatorImpl.java:405)
at shaded.org.jvnet.hk2.internal.ServiceLocatorImpl.narrow(ServiceLocatorImpl.java:2046)
at shaded.org.jvnet.hk2.internal.ServiceLocatorImpl.access$700(ServiceLocatorImpl.java:116)
at shaded.org.jvnet.hk2.internal.ServiceLocatorImpl$8.compute(ServiceLocatorImpl.java:1207)
at shaded.org.jvnet.hk2.internal.ServiceLocatorImpl$8.compute(ServiceLocatorImpl.java:1202)
Any help will be appreciated.
Thanks.
My question is pretty straightforward.
Given the following POM:
<build>
<plugins>
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>maven-datanucleus-plugin</artifactId>
<version>3.0.0-release</version>
<configuration>
<log4jConfiguration>${basedir}/src/main/resources/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
<props>${basedir}/src/main/resources/datanucleus.properties</props>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>DataNucleus_Repos2</id>
<name>DataNucleus Repository</name>
<url>http://www.datanucleus.org/downloads/maven2</url>
</repository>
<repository> <!-- Required for transaction-api transitive dep -->
<id>Java_Net_LEGACY</id>
<name>Java.Net legacy</name>
<url>http://download.java.net/maven/1/</url>
<layout>legacy</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>DataNucleus_2</id>
<url>http://www.datanucleus.org/downloads/maven2/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<scope>runtime</scope>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
</dependency>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
</dependencies>
And given that I have the files log4j.properties and datanucleus.properties in their expected place, when I run
mvn compile
I get (taken from datanucleus.log file)
19:36:11,297 (main) ERROR [DataNucleus.Enhancer] - DataNucleus
Enhancer completed with an error. Please review the enhancer log for
full details. Some classes may have been enhanced but some caused
errors Error creating the MetaDataManager for API "JDO" :
org.datanucleus.exceptions.NucleusException: Error creating the
MetaDataManager for API "JDO" : at
org.datanucleus.NucleusContext.getMetaDataManager(NucleusContext.java:964)
at
org.datanucleus.enhancer.DataNucleusEnhancer.getMetaDataManager(DataNucleusEnhancer.java:261)
at
org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:716)
at
org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:590)
at
org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1390)
Caused by: java.lang.reflect.InvocationTargetException at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source) at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source) at java.lang.reflect.Constructor.newInstance(Unknown Source)
at
org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:681)
at
org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:314)
at
org.datanucleus.NucleusContext.getMetaDataManager(NucleusContext.java:958)
... 4 more
Caused by: java.lang.NoSuchFieldError: supportsORM at
org.datanucleus.api.jdo.metadata.JDOMetaDataManager.(JDOMetaDataManager.java:142)
... 11 more
I would like to enable logging to see what queries are being done by my application.
A thing to note is that the enhancement works fine when removing log4j dependency from the POM. Of course, the log file doesn't get updated anymore, but the classes are enhanced.
Any idea related to the above behaviour will be greatly appreciated.
The documentation give a different look of the configuration for the plugin in particular in the executions:
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
which might many problems. Furthermore you should remove the repository definitions from your pom, cause based on a short check all these dependencies are available via maven central. If you really need to configure the repositories you should use a repository manager instead.