2

I am using Maven for the first time.
I want to use org.json and I have added the dependency to my pom.xml:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.json/json -->
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20180130</version>
    </dependency>
</dependencies>

Running mvn package works fine.
When trying to execute, I get the following error message:

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject

I have tried to change the scope and double check API-documentation/xml-tags.

Any help is greatly appreciated.

EDIT: This answer solved it for me :-)

olaven
  • 186
  • 1
  • 3
  • 14
  • How do you package your application? As JAR/WAR/EAR? How are you running your code? – Vasan Mar 13 '18 at 23:23
  • I package it as .jar. I am running in terminal using java -cp to/jar package.mainClass. Solved by this answer: https://stackoverflow.com/a/10569417/8543529 – olaven Mar 13 '18 at 23:27

1 Answers1

2

Try last version:

<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20090211</version>
</dependency>

Import Changes.

And do:

mvn clean && mvn install
Jackkobec
  • 5,889
  • 34
  • 34