2

I am new to java and maven. I am trying to run a project that I deployed on EC2 but I get the following error.

Exception in thread "main" java.lang.NoClassDefFoundError:     org/apache/http/HttpException
    at TripBuddy.DataCollectorDaemon.App.main(App.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

I have the following dependencies:

<dependency>
       <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpclient</artifactId>
       <version>4.0-alpha4</version>
</dependency>
<dependency>
       <groupId>commons-httpclient</groupId>
       <artifactId>commons-httpclient</artifactId>
       <version>3.1</version>
</dependency>

I changed the version of the first dependency to a later one(4.0 , 4.1.1, 4.3) and then the code doesnt build. I get error: exception URISyntaxException is never thrown in body of corresponding try statement

Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
student101
  • 21
  • 2
  • It's nearly always a bad idea to mix major versions like that. Why are you trying to include both of them? – chrylis -cautiouslyoptimistic- Mar 29 '15 at 08:36
  • As you also pointed out, there is already a 4.4 release so I recommend upgrading your version to that one. If your code doesn't compile, please post it so we can help you to fix that. – Ria Mar 29 '15 at 09:00
  • 1
    The `exception URISyntaxException is never thrown in body of corresponding try statement` means that you can just scrap that exception from the catch block (and maybe the complete `try`/`catch` block). – Clemens Klein-Robbenhaar Mar 29 '15 at 13:33
  • I tried to use the latest version of HttpComponents, and got the build error, so took out the try catch block and the build was successful but on running it I still get the "Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient"" – student101 Mar 29 '15 at 17:05
  • maybe you need to bundle the dependencies like HttpComponents in your jar, as explained here: http://stackoverflow.com/questions/16222748/how-to-build-fat-jar-with-maven – Clemens Klein-Robbenhaar Apr 28 '15 at 19:43
  • Using the shade plugin worked!! Thank you – student101 Apr 29 '15 at 23:31

0 Answers0