Asked By: Anonymous
After spending countless hours, googling similar threads and whatnot, i’m still stuck with this issue. I have simple Java app, that uses Guava. I’m using Intellij IDEA CE 2021. So, i have copied guava.jar in /lib, and included it in Project Structure > Modules > Dependencies:
I have also created .jar atrifact, and added guava dependency:
After building artifact and running it from console, i get Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/io/Files, no matter what i try. I don’t have any more ideas, any advice here?
Answered By: Anonymous
Some simple steps and you are done with this task:
- put the guava.jar file in a directory inside the project (e.g. lib)
- if you have just one dependency go in the project explorer and right-click on guava-30…jar and choose "Add as library"
- if you know there are more dependencies right-click on the "lib" folder and choose "Add as library…"
- File – Project Structure – Artifacts – press "+" – JAR – from Modules…
- choose the Main class of your project and "OK"
- generate the jar: Build – Build Artifacts – Build
- you now have a folder in your project "out" – artifacts with the generated project jar
Just a note (not valid for Guava): if you are using signed jars like Bouncy Castle you will notice that this doesn’t work like describes because the "including" of the external dependency file in the project jar will destroy the signature.