0

I have an issue, which relates to starting a jar file.

I have my code in java, and i have to export it to get a jar file. I do that, and i get a jar file, however, now i want to call my jar file from the command line. I set my main class in my jar file, so that i have an entry point. My java code depends on another jar file, and i am not sure, if it has anything to do with my problem.

Then i call the file from command line, after i have positioned myself in the right folder. I use the command : java -jar Likvidator2.jar

And what i get is this :

Error Message

I have tried checking my java version, and updating it, but at this point i really am not sure what to do and where to go anymore. Is it possible that i am building my project wrong, or something ?

Sachin
  • 901
  • 2
  • 10
  • 23
Marin
  • 11
  • 7
  • 1
    A jar file does not contain dependencies... – khmarbaise Mar 16 '16 at 12:48
  • 2
    You have to either add the dependencies to the classpath, or repackage all dependencies into your jar. Since you appear to use maven, take a look at the maven shade plugin: https://maven.apache.org/plugins/maven-shade-plugin/ – Jan Dörrenhaus Mar 16 '16 at 12:52
  • i have just checked my pom.xml file, and there is a dependency to a jar that i use, im confused – Marin Mar 16 '16 at 13:00
  • Possible duplicate of https://stackoverflow.com/questions/15930782/call-java-jar-myfile-jar-with-additional-classpath-option – Sachin Mar 16 '16 at 13:06

3 Answers3

0

You need to add the classpath to the command.

java -classpath <pathtodependency.jar;pathtootherdep.jar> your.MainClass
Christian
  • 3,503
  • 1
  • 26
  • 47
0

You should use the Maven Shade Plugin to create an executable JAR, as @Jan Doerrenhaus already commented.

Community
  • 1
  • 1
Moritz Petersen
  • 12,902
  • 3
  • 38
  • 45
0

[SOLVED]

I just had to build the jar file as runnable jar file, and everything worked fine.

Marin
  • 11
  • 7