I'm trying to install the Deeplearning4j library ( https://deeplearning4j.org/index.html) but I don't understand how to use install the lib correctly with IntelliJ and Maven so that I can build a .jar file from it.
As long as I'm running the program from IntelliJ everything seems to work.
This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>DeepLearning</groupId>
<artifactId>deeplearning</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-core -->
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-native -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-api -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-api</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-native-platform -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.datavec/datavec-api -->
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>MLPClassifierLinear</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
I am not sure if everything is set up correctly because it's the first time I use maven.
When I run the maven install command and start the .jar file I get an error that says that a JNI error has occurred and a NoClassDefFoundError.
This is the exact error message:
Error: A JNI error has occurred, please check your installation and
try again
Exception in thread "main" java.lang.NoClassDefFoundError:
org/deeplearning4j/nn/conf/layers/Layer at java.lang.Class.getDeclaredMethods0(Native Method) at
java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at
java.lang.Class.privateGetMethodRecursive(Class.java:3048) at
java.lang.Class.getMethod0(Class.java:3018) at
java.lang.Class.getMethod(Class.java:1784) at
sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException:
org.deeplearning4j.nn.conf.layers.Layer at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 7 more
Can somebody explain me how to use maven correctly so I can build .jar files without getting errors?
Thank you :)
Simple recipe for getting most things done:
deeplearning4j-core, nd4j-native-platform, maven shade plugin
deeplearning4j-core gives you most dependencies people use on simple desktop.
nd4j-native-platform bundles all operating system native dependencies so you don't have to worry about multi OS deployments/binaries. This also makes sbt and gradle actually..usable since they can't handle classifiers.
maven shade plugin handles building the jar properly.
https://github.com/deeplearning4j/dl4j-examples/blob/94568e78e86c56807c03fe17d6a2f89f0b0df377/dl4j-spark-examples/dl4j-spark/pom.xml#L98
Also, please don't use the term "install". You aren't installing anything. You're setting up a set of libraries using a dependency manager. It's not installing in the sense of the OS like ruby and python tend to do.
Beyond that: Specific critiques about your pom. nd4j-native here is redundant. You don't need that. You only use nd4j-native if you are using snapshots or building from source.
Datavec-api isn't needed because it's already brought in by deeplearning4j-core. Please read up on maven transitive dependencies to understand how this works.
If you aren't sure on how any of these things get resolved, look at using
mvn dependency:tree
Related
I have a java azure function that was running package azure-functions-maven-plugin version 1.3, trying to upgrade the package to anything 1.4 or greater when I try to package the function I get the following error:
Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.12.0:package (package-functions) on project azure-functions-archetype: com.google.gson.stream.MalformedJsonException: Expected name at line 9 column 4 path $.extensions.http
My Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.microsoft.azure</groupId>
<artifactId>azure-functions-archetype</artifactId>
<version>1.38</version>
<packaging>jar</packaging>
<dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-documentdb</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
</dependency>
</dependency>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>1.12.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<configuration>
<resourceGroup>java-functions-group</resourceGroup>
<appName>${functionAppName}</appName>
<region>${functionAppRegion}</region>
<appSettings>
<property>
<name>FUNCTIONS_EXTENSION_VERSION</name>
<value>~3</value>
</property>
</appSettings>
</configuration>
<executions>
<execution>
<id>package-functions</id>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
```
I m unable to find a solution online on what is causing this error, hoping someone out there has an idea
Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.12.0:package (package-functions) on project azure-functions-archetype: com.google.gson.stream.MalformedJsonException:
It seems to be the issue in pom.xml code like either the tags are misspelled or the azure functions maven plugin code is missing or written wrong.
There is a similar issue here resolved by specifying the runtime and correcting the misspelt tags/code.
Also, Please make changes in your pom.xml file by comparing with my pom.xml as I see in the given pom.xml is missing the azure.functions.maven.plugin.version, runtime OS property etc. (https://i.imgur.com/uVkrUfU.png, https://i.imgur.com/ccu4BrW.png).
Reference: pom.xml code
I tried to run the Azure Functions Project (Java Stack) in VS Code and it come up with many issues regarding to loading the dependencies, Java Compiler Packages etc. and finally running the function successfully by following the below steps:
Maven version 3.8.4
Azure Functions Maven Plugin 1.15
Process 1:
Created the Azure Java Functions Project through VS Code and run the function successfully:
Process 2:
Created azure functions project using maven-archetype-quickstart template and is working good.
Run this command in your VS Code terminal:
mvn archetype:generate -DgroupId=com.microsoft.azure -DartifactId=azure-functions-archetype -DinteractiveMode=false
Since archetypes are templates and they intend to reflect current best practices, they can evolve in time, thus they have their own versions. Maven will ask you which version of the archetype you want to use. By default, maven chooses latest version for you. so if you agree to use the latest version of an archetype, just press Enter at this step;
Every maven project (and module) has its groupId, artifactId and version. Maven will then ask these to you in three steps. groupId: This is generally unique amongst an organization or a project. artifactId: The artifactId is generally the name that the project is known by. version: This is the last piece of the naming puzzle.(read more)
Finally, maven will ask you the package structure for your code. A best practice is to create your folder structure that reflects the groupId, thus Maven sets this as default but you are free to change this.
After entering these information, Maven will show you all the information you entered and ask you to verify project creation. If you press Y and then enter, voila your project is created with the artifact and settings you chose.
You can also read maven-archetype-plugin's usage site.
To Update the pom.xml versions, please run the commands (in your VS Code Project terminal) available in this Maven official site.
I used the following basic Maven command to generate a project:
mvn archetype:generate -DgroupId=it.maven.project -DartifactId=MavenExample -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
The project was correctly created and I could test the automatically generated App class without any problem with this instruction:
java -cp target/MavenExample-1.0-SNAPSHOT.jar:lib/* it.maven.project.App
Later on, I added some dependencies to the POM, obtaining the following file:
<?xml version="1.0" encoding="UTF-8"?>
<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>it.maven.project</groupId>
<artifactId>MavenExample</artifactId>
<version>1.0-SNAPSHOT</version>
<name>MavenExample</name>
<!-- FIXME change it to the project's website -->
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Finally, for testing sake, I modified the App class previously generated by Maven itself:
package it.maven.project;
import org.apache.commons.lang3.RandomStringUtils;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
System.out.println("Stringa generata casualmente: " + RandomStringUtils.random(16, true, true).toUpperCase());
}
}
A series of strange things happen:
even though more recent versions of dependencies are specified in POM, in .m2 folder the downloaded versions seem to be older (for instance I get 2.1 and 2.5 for commons-lang3)
the project is correctly compiled by instruction
mvn clean install -U
when I run again command to execute App, I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/RandomStringUtils
at it.maven.project.App.main(App.java:13)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.RandomStringUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Questions:
how is it possible that project compiles but then errors are returned at compiling time? Why the import in App is accepted but instruction:
System.out.println("Stringa generata casualmente: " + RandomStringUtils.random(16, true, true).toUpperCase());
generates an exception?
what should I correct/execute to allow my program to work and use correctly dependencies?
when you create a simple java project you define a set of dependencies in the pom but if you don't create a java archive file (ejb-jar or war) all the dependencies are not available at runtime if you run the jar compiled in the target directory.
There are two solutions:
Create a uber jar that include all your depenencies in your jar: use stackoverflow solution
when you run the jar from command line you have to add the dependencies to the classpath:
java -cp "/path/dependencies/dep1.jar;/path/dependencies/dep2.jar" -jar myApp.jar
Hello I'm having a weird problem about war creation.
I use maven-war-plugin (tried with 3.1.0, 3.2.0, and 2.6). When I run war:war (or mvn clean package, or similars) the war is created but I noticed that it is like it always packages all the files and dependencies it encountered in the history of the project. I noticed this because the war file is always getting bigger and by opening it I see there are a lot of dependencies that I declared on the pom but now they are removed, and most importantly there are classes I deleted from the project! I even tried to start a new project and the result does not change.
I guess I'm using this badly... Is there something I should do to let him "forget" about the history and force it to consider the project "as it is" when creating a war?
Thanks for the help!
PS:
I always clean and compile before running war:war;
I work with IntelliJ IDEA Community 2017.3
using jdk 1.7 because of technical constraints.
Just for completeness, there is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>sduca-consumer-listener</groupId>
<artifactId>sduca-consumer-listener</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<webappDirectory>/sduca</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Using Spring 4 because of jdk 1.7 -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.18.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</project>
EDIT1: I tried to change versions of maven-war-plugin, maven-compiler-plugin, and Maven itself, but nothing changes.
EDIT2: I tried changing the output directory, no changes. I tried to change version of the dependencies and as "expected" now the war includes both versions, becoming bigger and bigger...
EDIT3: I reinstalled IntelliJ IDEA, upgrading to the latest version. Nothing changes, it has only reset the content of the package, but it still "keep track" of the content and dependencies and still includes removed stuff on the package when creating a new one.
EDIT4: I've started using mvn clean compile war:war instead of mvn clean package and at first things started working, but then the problem of the existing old files returned. However, I find out that if I manually remove the exceding resources and *.class from the war it looks it works (at least it's deployed).
It's just a trick worked for me many times,
Backup your dependencies from pom.xml and delete it.
Do a clean build, it will show errors in all Java classes. Also delete the previous war.
Now, replace those backed up dependencies and clean build the webapp again. All errors will be disappeared and war file will be as expected.
I have a problem that I can't seem to resolve. I have no issues starting a Spring Boot application from Eclipse (Oxygen) with STS 3.9.2, from the Boot Dashboard:
However, when I try to run it from command line, I get an error that files are missing:
Exception in thread "main" java.lang.RuntimeException:
java.lang.reflect.InvocationTargetException at
org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:62)
at java.lang.Thread.run(Thread.java:748) Caused by:
java.lang.reflect.InvocationTargetException at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:54)
... 1 more Caused by: java.lang.ArrayStoreException:
sun.reflect.annotation.TypeNotPresentExceptionProxy at
sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
at
sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
at
sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
at
sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
at
sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
at
sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
at java.lang.Class.createAnnotationData(Class.java:3521) at
java.lang.Class.annotationData(Class.java:3510) at
java.lang.Class.getAnnotations(Class.java:3446) at
org.springframework.core.type.StandardAnnotationMetadata.(StandardAnnotationMetadata.java:68)
at
org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition.(AnnotatedGenericBeanDefinition.java:56)
at
org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:139)
at
org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:127)
at
org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:122)
at
org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:158)
at
org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:134)
at
org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:126)
at
org.springframework.boot.SpringApplication.load(SpringApplication.java:708)
at
org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:357)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
at se.itab.bos.admin.AdminServer.main(AdminServer.java:37) ... 6
more
I tried commenting out the following from my startup class:
#SpringBootApplication
#Import({
// AppConfig.class
// , ActiveMqServerConfig.class
// , MetricConfig.class
// , AdminConfig.class
// , SystemConfig.class
// , SystemMessageRouterConfig.class
// , CommandConfig.class
// , AdminMessageRouterConfig.class
})
public class AdminServer {
This solves the issue so that I can launch from command line, but I don't understand why. In my pom.xml I have every other module defined, in which these files are contained.
I am using Spring Boot Starter 1.3.5.RELEASE and Java 8.
Any help would be greatly appreciated.
UPDATED
This is my full pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>se.bos</groupId>
<artifactId>bos-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../bos-parent</relativePath>
</parent>
<artifactId>bos-admin</artifactId>
<packaging>jar</packaging>
<name>BOS Admin</name>
<properties>
<java.version>1.7</java.version>
<start-class>se.bos.admin.AdminServer</start-class>
</properties>
<dependencies>
<!-- operations: spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-remote-shell</artifactId>
</dependency>
<!-- operations: spring boot admin -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<!-- application: bos -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-site</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-server</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-core</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-client</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-model</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-system</artifactId>
</dependency>
<!-- application: spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- test -->
<!-- -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
To start the project from command line, I run:
mvn clean install
java -jar target/admin.jar
After commenting out each import one by one, I also found that the problem stems from imported modules, but have not yet found why.
Running java -version from command line:
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
This is the same as what is used in Eclipse and what is in JAVA_HOME
Using mvn clean install will not produce the executable jar file for you, as this will not package the executable spring boot libraries and pom dependencies. It will only produce a jar file containing only your code.
Using the spring-boot-maven-plugin you need to execute the spring-boot:repackage goal and phase in order for the executable jar file to be appropriately packaged with the spring boot/pom dependencies and ready to be executed on the command line. i.e. run mvn package spring-boot:repackage and then run your application on the command line.
Full details on this can be found in the Spring Boot Maven Plugin Documentation and the spring-boot:repackage goal.
Note: It works in Eclipse because Eclispe has setup your classpath appropriately to reference the dependencies in your pom at compile and runtime, whereas your compiled jar file does not.
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
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.
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>