question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Java] NoClassDefFoundError

See original GitHub issue

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

I am wondering why it is so hard to make a Maven projects work fine with external JAR libraries. I’ve added the needed information to pom.xml. The project will download all of the required dependencies and also IDE doesn’t mark the imported packages or syntax markups as invalid.

    <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>20160810</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>
    </dependencies>

I am trying to use org.json and org.json.simple, but it doesn’t matter how ever I am trying to import it. I’ve read around the internet about this error, but it doesn’t make any sense for me. I was so excited about it that I don’t need to configure something “hard” what I don’t understand, but now I have to. Normally I use Eclipse on PC, but when I’m not at home it would be awesome to code something at somewhere without installing the stuff on the PC I’m using.

In Codenvy, build and run processes take place on different nodes and different environments. This project produces /repo with quite a few jars and a startup script that is impossible to inject into a Docker container (Codenvy runners are Docker based). Thus, I recommend performing build and run in the same environment, i.e. in the runtime. What you need to do is create a new runner (the button is on the runner panel), install Maven there, perform build and execute startup script. You will also have to unbind the service from localhost -kalrsson from StackOverflow

So basically what can I do? I really would like to use Codenvy of course.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
ddementievacommented, Sep 8, 2016

@MPNull It seems you need to add Maven dependency plugin to copy your dependencies as jars to the lib folder, specified in your manifest.

Simply add the following to the pom.xml, build and run your project:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>install</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                    <overWriteReleases>false</overWriteReleases>
                    <overWriteSnapshots>false</overWriteSnapshots>
                    <overWriteIfNewer>true</overWriteIfNewer>
                </configuration>
            </execution>
        </executions>
    </plugin> 
1reaction
MPNullcommented, Sep 8, 2016

@ddementieva awesome, awesome, awesome! It was the solution! Luv U ❤️

That’s one of the reasons why I didn’t never treat a Codenvy about the problem. I were pretty sure that there’s something I’ve fuck’d up myself. Thank you a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I getting a NoClassDefFoundError in Java?
java.lang.NoClassDefFoundError This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and ...
Read more >
How to Resolve the NoClassDefFoundError in Java
The NoClassDefFoundError is a runtime error in Java that occurs if the Java Virtual Machine (JVM) or a ClassLoader instance attempts to load ......
Read more >
NoClassDefFoundError (Java Platform SE 7 )
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a...
Read more >
3 ways to solve java.lang.NoClassDefFoundError in Java ...
NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available at compile...
Read more >
java.lang.NoClassDefFoundError
java.lang.NoClassDefFoundError is runtime error thrown when a required class is not found in the classpath and hence JVM is unable to load ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found