4

i am using webmaster tool Java api V3 to query data , my code work fine in eclipse but when i export it to a Jar i get the error below

Exception in thread "main" java.lang.NoClassDefFoundError: com.google.api.client.http.HttpTransport
    at java.lang.J9VMInternals.prepareClassImpl(Native Method)
    at java.lang.J9VMInternals.prepare(J9VMInternals.java:430)
    at java.lang.Class.getMethod(Class.java:1061)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:506)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:498)
Caused by: java.lang.ClassNotFoundException: com.google.api.client.http.HttpTransport
        at java.net.URLClassLoader.findClass(URLClassLoader.java:665)
        at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:942)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:851)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:82

my dependecies are as follow

enter image description here

enter image description here

i am compiling and exporting the jar in Java6 and executing it using Java7.

i assume it's a dependency issue but i don't know how to resolve it ?? espically it's working in eclipse but when i export the jar from eclipse keeping the default config and selecting the main class i get NoClassDefFoundError , any ideas thank you in advance.

2 Answers 2

3

You'll get this error when class com.google.api.client.http.HttpTransport IS available during compilation but is NOT available at runtime.

Eclipse automatically adds the jar files on the build classpath to your runtime configuration's classpath. Therefore you won't get the Exception when you're running from Eclipse.

I'm assuming you are running form the command line like this: java -cp myjarfile.jar com.my.Main

If this is the case, the classpath is missing the dependencies as configured in Eclipse. To solve this, append each of them as follows: java -cp myjarfile.jar;commons-logging-1.1.1.jar;etc... com.my.Main

Note that the semi-colon ; in the classpath is for Windows. Use a colon : on Linux.

Update When using a runnable jar file, make sure your class path is correctly set in the manifest file.

https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

Sign up to request clarification or add additional context in comments.

4 Comments

but i added all the jars to the class path
Please show how. Copy/paste the command line you are using to start the application e.g. java -cp ... so we can give better feedback
it's resolved i just exported a runnable jar from eclipse then executed it using java -jar majar.jar
Great! Glad you solved it. I've updated my answer with the -jar strategy.
0

i resolved the problem by exporting runnable Jar from eclipse instead of Jar.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.