Create and run a Java project with Maven

I want to try the sample code from this article: Download Recovery.gov Grant Data to the CouchDB database . I am familiar with the Java language, but I know nothing about the Maven build system.

I managed to create the project by running the "mvn package", but when I try to start it, I get the following:

djm@surfer:~/source/sample-parse$ java -cp target/sample-parse-1.0-SNAPSHOT.jar com.discursive.sample.parse.LoadingGrants
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpEntity
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

Do I need to do something to properly configure my CLASSPATH?

Thank!

+3
source share
1 answer

You created your jar correctly, but when you use the code, you need to add the path to the jar containing org.apache.httpcomponents. If you want to pack it as one jar, use the maven build plugin jar-with-dependencies .

, , maven jar .m2\repository. org.apache.httpcomponents.

+5

Source: https://habr.com/ru/post/1790206/


All Articles