简体   繁体   中英

Help building and running a Java project with Maven

I want to try out the example code from this article: Load Recovery.gov Grant Data into a CouchDB Database . I'm familiar with the Java language but I know nothing about the Maven build system.

I've managed to build the project by running 'mvn package', but I get the following when trying to run it:

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 else to set up my CLASSPATH properly?

Thanks!

You built your jar correctly but when you are running the code you need to add the classpath to the jar containing org.apache.httpcomponents . If you want to package it as one jar then use the maven assembly plugin jar-with-dependencies .

By the way in case you did not know this, maven by convention downloads the repository jar files to the local repository under your .m2\\repository folder. You should be able to locate org.apache.httpcomponents there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM