0

I'm hitting this error when run my package jar:

java.lang.NoClassDefFoundError: com/google/common/base/Joiner

I simply call: java -jar xxx.jar

I already added the dependency in my pom.xml:

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>18.0</version>
  <scope>compile</scope>
</dependency>

I'm using IntelliJ editor. I have a unit test for the function which uses the Joiner class. It runs successfully from within IntelliJ.

I put my cursor on the Joiner and use "command + B" to search for the declaration of the Joiner class. It opens the Decompiled source code page, and on the heading it shows the path as: guava-18.0.jar/com/goog/common/base/Joiner So everything looks correct.

Can anyone help me figure out why do I hit this error?

  • I imagine that Guava isn't being included when you export the .jar – Jacob G. Dec 13 '17 at 01:55
  • using maven wont mean all the dependencies are in the jar file or otherwise locatable. see: https://stackoverflow.com/questions/15869784/how-to-run-a-maven-created-jar-file-using-just-the-command-line – slipperyseal Dec 13 '17 at 02:00
  • I used "mvn clean package" to build the package. I also tried "java -cp xxx.jar xxx.Main" to run the package. But always got the error. – Qing 'Matt' Zhang Dec 13 '17 at 03:04

1 Answers1

0

You could shade guava into your jar but it would result in a bigger jar file. But that way it would be included in your programm 100%. Read more about shading maven depencies into your jar file in the official maven-documentation: http://maven.apache.org/plugins/maven-shade-plugin/

Fabian Schmidt
  • 334
  • 1
  • 13