Was trying to implement Google Calendar Code taken from https://developers.google.com/google-apps/calendar/quickstart/java but got an error as follows:
Exception in thread "main" java.lang.NoClassDefFoundError: org/mortbay/jetty/Handler
at CalendarQuickstart.authorize(CalendarQuickstart.java:76)
at CalendarQuickstart.getCalendarService(CalendarQuickstart.java:89)
at CalendarQuickstart.main(CalendarQuickstart.java:101)
Caused by: java.lang.ClassNotFoundException: org.mortbay.jetty.Handler
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
And the line was
Credential credential = new AuthorizationCodeInstalledApp(
flow, new LocalServerReceiver()).authorize("user");
Before this i just copied code from https://developers.google.com/google-apps/calendar/quickstart/java and created a Java Project and this two Jar file was missing
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
After importing these jar file got that error. Please help
The Google Calendar API Java Quickstart works fine. Based on the error message you received, it looks like you're missing one of the jetty dependencies. If you're using Gradle build (as suggested in here, check under your "Gradle Depenencies" for this jar file -jetty-6.1.26.jar.
If you're missing the jetty dependencies, Open your build.gradle and check to make sure you have included all the dependencies listed below.
dependencies {
compile 'com.google.api-client:google-api-client:1.20.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.20.0'
compile 'com.google.apis:google-api-services-calendar:v3-rev125-1.20.0'
}
Finally, Build and run the Gradle file to download the missing dependencies. You should now be up and running ! :)
Good luck!
Related
I have been reading through SO and several pages of google links, tried all of the approaches there but I cannot get my project running any more.
I am developing a small app and i decided to persist some data in JSON. I downloaded javax.json-api-1.1.jar and javax.json-api-1.1-sources.jar. Eclipse finds the jar file, I can import it, intellisense works, etc. Sadly, when running or debugging I get the following error as soon as the first JSON related line is executed:
Caused by: javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found
at javax.json.spi.JsonProvider.provider(JsonProvider.java:99)
at javax.json.Json.createObjectBuilder(Json.java:299)
at tabumaker.view.ChordManagementViewController.handleAddChordSaveBtnOnAction(ChordManagementViewController.java:214)
... 62 more
Caused by: java.lang.ClassNotFoundException: org.glassfish.json.JsonProviderImpl
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javax.json.spi.JsonProvider.provider(JsonProvider.java:96)
... 64 more
I put both jar files within my workspace and linked them in my eclipse project the following way:
Source attached to jar file:
Source-Lookup-Path set in project:
Source-Lookup-Path:
I really have no idea why it doesn't work. Eclipse has all information to find the API and the corresponding sources within those two jar files.
I'm trying to use the apache http library in my project. I imported the libreries in my project http://imgur.com/WvwqcDS
When I run my program, I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpEntity
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
The ClassLoader can't find org.apache.http.HttpEntity, which should be inside "httpcore-4.3.jar". Open the jar as an archive and verify that it contains org/apache/http/HttpEntity.class. If it does, the issue is in your launch configuration. In Eclipse, go to Run > Run Configurations... and find the Java Application profile for your main class (which should be the class containing the main method in "Launcher" project, based on the screenshot). Under the Classpath tab, you should see your library jars listed.
If not, go back to your "Launcher" project in the Navigation pane, right-click and select Properties, go to "Build Path", remove your jars, press OK, then go back in and add them again (to guarantee the eclipse meta-data is fresh). Also, under the "Order and Export" tab, it's a good idea to check off all jars so that if you include Launcher as a dependency for another project, the jars are transitively included.
your Eclipse is having trouble locating the external jars, try importing them into your workspace or referencing them outside by using "add external jar's"
In my case Maven was not updating dependencies properly. I use mvn clean and then re-updated dependencies then it got fixed.
I have been searching the web for a while now and no solutions found have been working out for me. So, I turn to you.
I get a java.lang.NoClassDefFoundError when I try to integrate the API of BIRT (an eclipse plugin for reports and documents). I copy paste their code, include ALL of the jar file in the lib folder (birt-runtime-4_2_2\ReportEngine\lib) and still I get the NoClassDefFoundError. What am I doing wrong? I cant find any useful information on their page. Furthermore, I have tried out a couple of other source codes, yet I still get the same problem. So i would argue that the imports of the jar-files might be faulty. But I cannot for the love of God find the fault is.
The code I have copy pasted (just to try out) is found here:
http://wiki.eclipse.org/Java_-_Simple_Design_Engine_API_%28BIRT%29
The complete error message is this:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/Platform
at org.eclipse.birt.core.framework.jar.ServicePlatform.getExtensionRegistry(ServicePlatform.java:72)
at org.eclipse.birt.core.framework.jar.ServicePlatform.createFactoryObject(ServicePlatform.java:98)
at org.eclipse.birt.core.framework.Platform$1.run(Platform.java:297)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.birt.core.framework.Platform.createFactoryObject(Platform.java:293)
at org.eclipse.birt.report.model.api.DesignEngine.<init>(DesignEngine.java:90)
at org.eclipse.birt.report.model.api.DesignEngine.newSession(DesignEngine.java:142)
at standard.Main.main(Main.java:36)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.Platform
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 8 more
Except from Birt's jar files you will also have to copy some extra jars from Birt Runtime to Tomcat's WEB-INF folder.
Download Birt Runtime from the following link: http://download.eclipse.org/birt/downloads/
In Birt Runtime you will find a folder called ReportEngine. In this folder there is a lib folder. Just copy it to your WEB-INF folder.
I had a similar problem and it worked for me. Take a look at my problem: NoClassDefFoundError for Birt Class EngineException
I created a webservice using servlet and Tomcat 6.0.
I created a java project in eclipse to call that webservice using HTTP.
I added the following jar files
1. httpcore-4.0
2. httpclient-4.0
but while running the project im getting the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.<init>(ThreadSafeClientConnManager.java:75)
at WSCall.HttpUtilities.GetServerResponse(HttpUtilities.java:52)
at WSCall.ServiceCall.main(ServiceCall.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
Please help me to find the solution.
You still have to add common-logging dependency under your classpath. However, you may continue encounter other simaliar Exceptions due to lack other dependency. I suggest you use maven to manage the dependency so that you don't have to mannualy add dependencies to your classpath.
It seems your project doesn't contain the Apache Commons Logging library. Adding it to your classpath should do the trick.
This is caused by the missing of commons-logging.jar.To fix it, download the commons logging library and add it to your project.
I am using the Apache Commons CLI 1.2 to parse command line arguments in Java. I had run into the NoClassDefFoundError when trying to run my java class but solved it by fixing the class-paths.
Now I have the same exception but in regards to the actual commons-cli classes as is shown below:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cl i/CommandLineParser Caused by:
java.lang.ClassNotFoundException: org.apache.commons.cli.CommandLineP arser
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: com.amirsys.score.api.script.CMDContentPusher.
The only thing I could think of is to set the class path to the commons-cli jar but that did not work. I haven't been able to find a solution to fixing the NoClassDefFoundError for imported classes. I thought these were compiled into the .class files?
Commons CLI is not in the classpath at runtime. If you struggle to get the classpath right you can try to package your application as a single big jar file containing all its dependencies, including Commons CLI. There are many tools to achieve that (jarjar, onejar, Maven shade plugin...)