I am stuck at the beginning of the development. I have a simple test program listed below. I followed http://code.google.com/apis/gdata/articles/eclipse.html to setup Eclipse.
import com.google.gdata.client.*;
import com.google.gdata.client.youtube.*;
import com.google.gdata.data.*;
import com.google.gdata.data.geo.impl.*;
import com.google.gdata.data.media.*;
import com.google.gdata.data.media.mediarss.*;
import com.google.gdata.data.youtube.*;
import com.google.gdata.data.extensions.*;
import com.google.gdata.util.*;
import java.io.IOException;
import java.io.File;
import java.net.URL;
public class Test {
public static void main(String[] args) {
YouTubeService service = new YouTubeService(
"xxx.apps.googleusercontent.com",
"AAA");
}
}
}
When I run java Test in console, I got exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gdata/client/youtube/YouTubeService
at Test.main(Test.java:18)
Caused by: java.lang.ClassNotFoundException: com.google.gdata.client.youtube.YouTubeService
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 1 more
When I run in Eclipse, I got the exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
at com.google.gdata.client.Service.<clinit>(Service.java:555)
at Test.main(Test.java:18)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Maps
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 4 more
What's wrong here? How to fix this?
You seem to be missing google-collections API which has been deprecated and is now replaced by guava for your second error (running in eclipse). For the first error you have forgotten to add the required jars to you class path (gdata-youtube-2.0.jar). use
java -cp ...gdata-youtube-2.0.jar... your.java.Program
where ... symbolizes other required libraries.
Related
I've been experiencing problems with the following source code:
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.net.URL;
/**
* Created by Boris on 14-1-2.
*/
public class Parser {
public static void main(String[] args) throws Exception {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
WebRequest request = new WebRequest(new URL("http://oddsportal.com"));
HtmlPage page = webClient.getPage(request);
int i = webClient.waitForBackgroundJavaScript(1000);
while (i > 0)
{
i = webClient.waitForBackgroundJavaScript(1000);
if (i == 0)
{
break;
}
synchronized (page)
{
System.out.println("wait");
page.wait(500);
}
}
webClient.getAjaxController().processSynchron(page, request, false);
System.out.println(page.asXml());
}
}
This is the error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/pool/ConnPoolControl
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:557)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClient(HttpWebConnection.java:518)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:155)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1486)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1403)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:305)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:390)
at DIIParser.Parser.main(Parser.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: org.apache.http.pool.ConnPoolControl
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 25 more
I read a lot about the topic, included browser version to WebClient, switched to the old version 4.2 of org.apache.httpcomponents, tried casting HtmlPage as stated in another topic here but nothing helps. All I want is to load a particular page and wait until the javascript is executed, after that parse it with jsoup. Thank you in advance for your help!
Regards,
Boris
Although you haven't explained what you have done so far to get that error I guess you haven't imported the appropriate libraries. Make sure you import all the libraries that come in the HTMLUnit distribution.
You can take a look at how to do this in Eclipse in the following question, maybe it can help:
How to setup HtmlUnit in an Eclipse project?
By the way, there is no need to switch to any old version. Just import the libraries and you're done.
This Question should not be closed as suggested answer does not answer question in this case.
The below code causes this error :
Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at scala.java.mixed.test.Driver.main(Driver.java:17)
Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 13 more
The code :
package parallel
import com.recommendations.EucleudianProperties
class TestData(var distanceMap : java.util.Map[java.lang.String , java.lang.String]) {
object ProcessData{
def apply {
println("in apply method "+distanceMap.size)
}
}
}
package scala.java.mixed.test;
import java.util.HashMap;
import java.util.Map;
import parallel.TestData;
public class Driver {
public static void main(String args[]){
Map<String , String> distanceMap = new HashMap<String , String>();
new TestData(distanceMap);
}
}
What is causing this error ? Am I calling the Scala class TestData from java class Driver correctly ?
EDIT : here is the build path
The issue for me is that the scala-library.jar is not configued on classpath within
Eclipse run configuration , once I added this it behaves as expected. Here is my updated classpath :
The issue is that when I run it via Eclipse Juno by clicking on it and "Run as Java Application" it works,
but it needs to be to run in a Linux shell script or at least from the Linux shell.
I need it to append all the jar files from $CATALINA_HOME/webapps/myapp/WEB-INF/lib to my classpath.
Here's my code:
package com.myapp.client;
public class ClientApp {
public static void main(String args[]) {
System.out.println("Hi Client");
}
}
When I cd into $CATALINA_HOME/webapps/myapp/WEB-INF/classes/com/myapp/client issue the following command:
java -classpath "/home/devuser/DevTools/apache-tomcat-7.0.32/webapps/myapp/WEB-INF/lib/*:." ClientApp
I receive this exception:
Exception in thread "main" java.lang.NoClassDefFoundError: ClientApp (wrong name: com/myapp/client/ClientApp)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: ClientApp. Program will exit
When I go to my home dir (/home/devuser) and type this in, it still doesn't work:
java -classpath "/home/devuser/DevTools/apache-tomcat-7.0.32/webapps/myapp/WEB-INF/lib/*:." $CATALINA_HOME/webapps/myapp/WEB-INF/classes/com.myapp.ClientApp
Exception in thread "main" java.lang.NoClassDefFoundError: /home/devuser/DevTools/apache-tomcat-7/0/32/webapps/myapp/WEB-INF/classes/com/myapp/ClientApp
Caused by: java.lang.ClassNotFoundException: .home.devuser.DevTools.apache-tomcat-7.0.32.webapps.myapp.WEB-INF.classes.com.myapp.ClientApp
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: /home/devuser/DevTools/apache-tomcat-7.0.32/webapps/myapp/WEB-INF/classes/com.myapp.ClientApp. Program will exit.
Thank you for taking the time to read this... Would appreciate it if someone could assist me.
All of your libraries and classes need to be in your classpath, then the next argument is the path to your class.
java -cp '.:/path/to/libdir/*:/path/to/myapp.war' com.myapp.client.ClientApp
I am getting a NoClassDefFoundError error when I run my program. Here is the stack trace:
Exception in thread "main" java.lang.NoClassDefFoundError: ex7/Ex7
Caused by: java.lang.ClassNotFoundException: ex7.Ex7
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Java Result: 1
How do I fix this? I'm on a Mac and running NetBeans.
It seems class Ex7class from package ex7 isn't in classpath. recheck the class try clean build
I put the xmlbeans-2.3.0.jar into path and it says another exception while reading .xslx file using apache poi.
Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:149)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:136)
at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:98)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:199)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:178)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:53)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:176)
at setTargetPlan.setTask(setTargetPlan.java:152)
at userVerification.main(userVerification.java:204)
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
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)
... 10 more
Same as your earlier problem.
For each ClassNotFound exception, search for the jar on the site below which contains this class and put the jar in your classpath
http://www.jarfinder.com/index.php/java/info/org.dom4j.DocumentException shows you need dom4j.jar