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.
Related
Hi i am using the following code to call a cxf service and getting the error. how to resolve this?
WebClient client = WebClient.create("http://localhost:8080/weath/api/v1/cities/cities", "test", "murali", null);
The above code is giving this error:-
Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
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 org.ymd.CxfClient.main(CxfClient.java:29)
All the jars that i have in my classpath are:-
cxf-rt-rs-client-3.1.7.jar
cxf-rt-transports-http-hc-3.1.7.jar
cxf-bundle-jaxrs-2.1.2.jar
cxf-rt-frontend-jaxrs-3.1.7.jar
cxf-core-3.1.7.jar
cxf-rt-transports-http-3.1.7.jar
javax.persistence-2.1.1.jar
-cxf-api-2.7.18.jar
javax.ws.rs-api-2.0.jar
I resolved my problem. it is because of version conflict. When i use maven for getting dependencies everything got resolved.
This question already has answers here:
How can I solve "java.lang.NoClassDefFoundError"?
(34 answers)
How do I resolve ClassNotFoundException?
(28 answers)
Closed 6 years ago.
i want to connect to hive database on server using java program. below is code of java :
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveQueryJava {
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
// Register driver and create driver instance
Class.forName(driverName);
// get connection
Connection con = DriverManager.getConnection("jdbc:hive -hiveconf mapred.job.queue.name=queuename://ip:port/dbname", "uname", "");
// create statement
Statement stmt = con.createStatement();
// execute statement
Resultset res = stmt.executeQuery("SELECT pincode FROM pincode_city_map LIMIT 5;");
System.out.println("Result:");
while (res.next()) {
System.out.println(res.getString(1));
}
con.close();
}
}
i added 3 jar files for 4 NoClassFoundExceptions. jar files are :
hive-service-0.11.0.jar
libthrift-0.8.0.jar
hive-jdbc-0.10.0.jar
hive-metastore-0.10.0
now getting new NoClassFoundException as below :
Exception in thread "main" java.lang.NoClassDefFoundError: com/facebook/fb303/FacebookService$Iface
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
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)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
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)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
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)
at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at HiveQueryJava.main(HiveQueryJava.java:21)
Caused by: java.lang.ClassNotFoundException: com.facebook.fb303.FacebookService$Iface
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)
... 40 more
every time this exception comes, i have to search for this class and download a jar file. is there any master jar file which contains all jars for connecting to hive database ?
at the end i want to connect to hive by java program. can anyone provide a different code or suggest other way round to this problem ?
The libfb*-*.jar is missing in your CLASSPATH. Please make sure the necessary jars included in the CLASSPATH with correct version and without any duplication.
The following pages might be of help,
http://docs.aws.amazon.com/ElasticMapReduce/latest/DeveloperGuide/HiveJDBCDriver.html
https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-JDBCClientSampleCode
If you are using hortonworks , they have bundled all the jars..and you can connect by using below two jars:-
http://repo.hortonworks.com/content/repositories/releases/org/apache/hadoop/hadoop-common/2.7.1.2.3.2.0-2950/hadoop-common-2.7.1.2.3.2.0-2950.jar
http://repo.hortonworks.com/content/repositories/releases/org/apache/hive/hive-jdbc/1.2.1.2.3.2.0-2950/hive-jdbc-1.2.1.2.3.2.0-2950-standalone.jar
Also you can only connect only hive server 2 , so you connection string should be like the below one, use hive2 instead of hive.
Connection con = DriverManager.getConnection("jdbc:hive2://hadoopip:10000/database","username", "password");
I want to build a simple system notification in my Java desktop application. So, after some search on web, I have find JCarrierPigeon library to do this.
So after insert the two library I have this code:
package prove;
import javax.swing.JFrame;
import net.sf.jcarrierpigeon.Notification;
import net.sf.jcarrierpigeon.NotificationQueue;
import net.sf.jcarrierpigeon.WindowPosition;
public class NOtification {
public static void main(String[] args){
NotificationQueue queue = new NotificationQueue();
JFrame window1 = new JFrame();
Notification note1 = new Notification(window1, WindowPosition.BOTTOMRIGHT, 25, 25, 1000);
queue.add(note1);
}
}
But if I try to run it, I have this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jdesktop/animation/timing/TimingTarget
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at prove.NOtification.main(NOtification.java:18)
Caused by: java.lang.ClassNotFoundException: org.jdesktop.animation.timing.TimingTarget
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 13 more
How can I fixed it?
The Homepage of JCarrierPidgeon states:
"First of all, be sure to include the Timing Framework library in your classpath."
And the errormessage looks like you did not do this.
The Homepage also provides a link to that library. I won't do it here, because it is likely to become out of date.
I'm a student, and I'm trying to write an RMI application.
I have 3 separate projects:
One is Server Side
One is Common (include Interface and Entities to reflect with Database Structure)
One is Client
and I write it on Netbeans IDE.
When I start server I receive a printstack error like this:
Exception in thread "main" java.lang.NoClassDefFoundError: rmi/cosmetic/Interfaces/ICategories
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at Server.ServerSide.main(ServerSide.java:22)
Caused by: java.lang.ClassNotFoundException: rmi.cosmetic.Interfaces.ICategories
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 13 more
Java Result: 1
rmi/cosmetic/Interfaces/ICategories
is the path of file Interface Categories, it has been contained in Common Project for both of 2 sides client and server
I have no idea about this issue. I try to set classpath on my windows but it didn't work.
Can someone please help me?
Some images, to make it clear
http://upanh.7nghiep.com/vgo-images/vgo.vn-qIntT.jpg
http://upanh.7nghiep.com/vgo-images/vgo.vn-jaJw0.jpg
upanh.7nghiep.com/vgo-images/vgo.vn-RvxIo.jpg
upanh.7nghiep.com/vgo-images/vgo.vn-DvuMt.jpg
upanh.7nghiep.com/vgo-images/vgo.vn-OI9rL.jpg
Caused by: java.lang.ClassNotFoundException:
rmi.cosmetic.Interfaces.ICategories
There's your problem right there. Your Registry or your client can't find that class. It needs to be on their CLASSPATH.
Gwt -> RPC -> MongoDB (Morphia)
Caused by: java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
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
com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload$WebAppClassLoaderExtension.findClass(JettyLauncher.java:372)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:366)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
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
com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload$WebAppClassLoaderExtension.findClass(JettyLauncher.java:372)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:366)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337)
at com.mongodb.MongoOptions.reset(MongoOptions.java:47)
at com.mongodb.MongoOptions.<init>(MongoOptions.java:29)
at com.mongodb.Mongo.<init>(Mongo.java:148)
at com.mongodb.Mongo.<init>(Mongo.java:113)
at
myapp.database.MyCodeImpl.getDataSource(MyCodeImpl.java:42)
at
MyCodeImpl.getDataSource():
public Datastore getDataSource() {
try {
Morphia morphia = new Morphia();
Mongo db = new Mongo("localhost");
return morphia.createDatastore(db, getDatabaseName());
} catch (UnknownHostException e) {
e.printStackTrace();
throw new DatabaseException();
}
}
line 42: Mongo db = new Mongo("localhost");
Without GWT works fine. Why doesn't work with GWT?
Looks like problem with com.mongodb.DbDecoder... Any suggestions?
From the stacktrace, it looks like it's a GWT problem. Make sure you don't deploy gwt-user.jar or gwt-dev.jar to your Jetty. Also make sure that you have only one version of GWT in your class path.