Reputation: 3548
Hi I am using followng maven dependencies. When I run the application in Eclipse, it is working fine. but when i deploy the application as jar file, it is throwing following error.
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
at java.net.URLClassLoader.findClass(Unknown Source)
Following is my maven dependency file.
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.client.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>${jersey.client.version}</version>
</dependency>
<!-- http://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<properties>
<jersey.client.version>2.21</jersey.client.version>
</properties>
<dependencies>
Any help on this.... I gone through following link, but it don't help me.
running standalone java executable in eclipse results in NoClassDefFound
Upvotes: 2
Views: 5497
Reputation: 2111
Maybe You are missing the Maven dependency below in your pom.xml
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.2.Final</version>
</dependency>
Upvotes: 0
Reputation: 27476
If you distribute only single jar (not fat-jar/uber-jar) you need to provide the classpath to it, that is all the library jars that are required to run it.
In your case it would be something along this lines:
java -jar my.jar -cp $HOME/.m2/repository/org/glassfish/jersey/core/jersey-client/2.21/jersey-client-2.21.jar
And after :
you need to add all other dependencies that you have.
Another option is to use e.g. assembly plugin to build uber jar (jar that will contain all other jars, libraries and your code): http://maven.apache.org/plugins/maven-assembly-plugin/usage.html:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
And then build the jar using: mvn clean package assembly:single
, and see that now you have two jars inside target
, the larger one is the uber jar that you can distribute.
Upvotes: 3