I\'ve followed the simplest maven example and made the following pom.xml
file:
As per exception ClassNotFoundException: org.json.simple.parser.JSONParser
the required jar
file is not present in classpath
.
In eclipse use below steps:
Right click on project --> properties --> deployment assembly --> add
--> (here select appropriate file system to add jar like)java build path entries
hope it help.
By default, jar doesn't include dependencies within it. You either need to add all dependencies in classpath at run time or you can build jar with dependencies. For building jar with dependencies see link: http://maven.apache.org/plugins/maven-assembly-plugin/
The problem is, you are setting the classpath to a single .jar file, thus java command can not find the dependency. (json-simple-1.1.1.jar in your case..)
You can tell maven to include the dependencies in target folder that you compiling your class to.
This is done by the following change in the pom.xml:
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Now try mvn package (or mvn clean install, I am not sure..) and you will see in /target/lib the dependencies are copied.
Run your application like this:
java -cp target/my-app-1.0-SNAPSHOT.jar:target/lib/json-simple-1.1.1.jar com.mycompany.app.App
{"hello":"world"}