0

I've been googling a lot for this and it seems easy, but it just doesn't work for me. I want to include Twitter4j in my JAR in IntelliJ IDEA. I have put the twitter4j JAR into my /lib folder , specified it in Libraries, specified it to compile in dependencies: Dependencies and specified to include it in artifacts.

In the final JAR, both twitter4j-stream and twitter4j-core are included: Final JAR

Still, Java throws a NoClassDefFoundError when run.

(This is not Maven.)

user11153
  • 8,536
  • 5
  • 47
  • 50
user3760874
  • 75
  • 1
  • 5
  • Possible duplicate of [Why am I getting a NoClassDefFoundError in Java?](http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java) – Harmelodic Mar 21 '16 at 13:41
  • @Harmelodic Definitely not a duplicate of that. :D – user3760874 Mar 21 '16 at 13:49
  • You simply need to check that the class exists in the final output jar and the resource (if it is embedded) is on the runtime classpath, specified in the manifest. You could also look at SBT-Assembly (https://github.com/sbt/sbt-assembly, http://stackoverflow.com/questions/23070469/how-do-i-publish-a-fat-jar-jar-with-dependencies-using-sbt-and-sbt-release). – ManoDestra Mar 21 '16 at 13:52
  • @ManoDestra The JARs are in my JAR file and I have just manually specified them in the manifest but it still throws that error whenever it tries to access a class from twitter4j. – user3760874 Mar 21 '16 at 14:13
  • If you've solved the issue please add it as an answer. Don't put your answer in the question since that makes it harder to find the actual answer. – Makoto Mar 21 '16 at 14:27
  • Could you possibly post up the structure of your final jar, and the structure of the embedded jar that you're referencing within it? And the attempted path that you're using to get to the class in question that's causing the issue for you? – ManoDestra Mar 21 '16 at 14:51

2 Answers2

0

I had similar error and the problem was that I did not write correctly the title in the command line: java title. Be sure that your title is equal to the program name written inside your program before it has been packed.

In public class title the title must be equal to the program name as well as to the name of jar archive.

(Obviously you can not use data files inserted in the JAR file with the CLASS file until the JAR file is unpacked...)

0

Answer given by author of the question:

In the Artifacts, you have to choose "Extracted *.jar" instead of the library.

user11153
  • 8,536
  • 5
  • 47
  • 50