I am trying to write a little test-programm with different Databases. MongoDB is one of them and it worked perfectly fine until last Friday, even though I didn't change anything in the java code of my MongoDB class.
System: I use an ubuntu 14.04 VM with the package mongo-org. The version of mongo is 3.0.5.
I also run MariaDB, PostgreSQL and Cassandra on the VM.
As a Client, I have windows 7 and Eclipse.
The connection and the test work perfectly fine with the other 3 databases.
And I can run the "mongo" client on ubuntu as well.
But when I try out the Java Test of MongoDB, I keep getting this error:
Exception in thread "main" java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at com.mongodb.MongoClientOptions$Builder.<init>(MongoClientOptions.java:52)
at com.mongodb.MongoClient.<init>(MongoClient.java:126)
at com.mongodb.MongoClient.<init>(MongoClient.java:115)
at de.motza.database.impl.DatabaseImplMongoDB.connect(DatabaseImplMongoDB.java:197)
at de.motza.database.impl.DatabaseImplMongoDB.instantiate(DatabaseImplMongoDB.java:207)
at de.motza.test.History_Log.testNewDatabase(History_Log.java:86)
at de.motza.test.History_Log.main(History_Log.java:66)
The part of the java Class, where the Exception occurs:
private static String dbHost = "10.158.251.251";
private static int dbPort = 27017;
private static String dbName = "history_log";
private static MongoClient mongoClient = null;
[...]
#Override
public void connect() {
try {
mongoClient = new MongoClient(dbHost, dbPort);
db = mongoClient.getDB(dbName);
} catch (Exception e) {
log.error(e);
}
}
I read about the disk-space, but I habe 12 GB free in my VM, so I do not think that this is the problem. I ran apt-get upgrade, but it didn't change anything either. I also reinstalled mongoDb, but nothing changed.
I also tried to recompile, but nothing changed there either.
Does anybody have any advice?
ADDITION:
Here you find the library tab of my project. I use multiple databases, so I marked the ones important for MongoDB
One possible reason for a IncompatibleClassChangeError you get is that a Mongo library binary has changed (for whatever reason) and now your earlier compiled test code isn't any more compatible with the library. I would suggest to recompile your test code and try again.
Related
I'm using APSTEX IFC Framework to creat a IFC 3D Viewer in my Java program.
My code is as follow.
import com.apstex.ifcjava3dviewer.IfcJava3DViewer;
public class JavaViewer2 {
public static void main(String[] args) {
IfcJava3DViewer ifcViewer = new IfcJava3DViewer();
}
}
The error is as followed:
java.lang.NoClassDefFoundError: com/jogamp/opengl/GLCapabilitiesImmutable
at com.apstex.javax.media.j3d.Pipeline$PipelineCreator.run(SourceFile:74)
at com.apstex.javax.media.j3d.Pipeline$PipelineCreator.run(SourceFile:1)
at java.security.AccessController.doPrivileged(Native Method)
at com.apstex.javax.media.j3d.Pipeline.b(SourceFile:91)
at com.apstex.javax.media.j3d.MasterControl.c(SourceFile:858)
at com.apstex.javax.media.j3d.VirtualUniverse.<clinit>(SourceFile:267)
at com.apstex.gui.core.controller.ApplicationController.<init>(SourceFile:1097)
at com.apstex.gui.core.kernel.Kernel.getApplicationController(SourceFile:59)
at com.apstex.ifcjava3dviewer.IfcJava3DPanel.<init>(SourceFile:71)
at com.apstex.ifcjava3dviewer.IfcJava3DViewer.<init>(SourceFile:38)
at test.main.JavaViewer2.main(JavaViewer2.java:7)
Caused by: java.lang.ClassNotFoundException: com.jogamp.opengl.GLCapabilitiesImmutable
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)
... 11 more
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.apstex.javax.media.j3d.VirtualUniverse
at com.apstex.javax.media.j3d.Canvas3D.<clinit>(SourceFile:3821)
at com.apstex.gui.ifc.views.view3d.j3d.ModelViewer.<init>(SourceFile:93)
at com.apstex.gui.ifc.views.view3d.j3d.ModelViewer.<init>(SourceFile:79)
at com.apstex.ifcjava3dviewer.IfcJava3DPanel.<init>(SourceFile:1079)
at com.apstex.ifcjava3dviewer.IfcJava3DViewer.<init>(SourceFile:38)
at test.main.JavaViewer2.main(JavaViewer2.java:7)
How can I correct the error?
Thanks for the two commends above to help me solve the problem. By installing a library of JOGL the program works.
#PrepareForTest({ A.class, B.class, SomeJavaClass.class, D.class})
class ReportActionTest
{
// JUnit class having around 10,000 lines of code
}
class SomeJavaClass
{
//Java class having around 10,500 lines of code
}
All JUnits of ReportActionTest were executing properly until I added few new methods in SomeJavaClass.
After Adding new methods, I tried to run JUnits of ReportActionTest.
But ReportActionTest couldn't load.
Following is the error log :
java.lang.ClassFormatError: Invalid this class index 11012 in constant pool in class file com/app/reports/web/action/SomeJavaClass
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:210)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:145)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:65)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at junit.framework.TestSuite.getTestConstructor(TestSuite.java:83)
at org.powermock.modules.junit3.internal.impl.PowerMockJUnit3RunnerDelegateImpl.<init>(PowerMockJUnit3RunnerDelegateImpl.java:54)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.powermock.modules.junit3.internal.impl.JUnit3TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit3TestSuiteChunkerImpl.java:75)
at org.powermock.modules.junit3.internal.impl.JUnit3TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit3TestSuiteChunkerImpl.java:37)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:217)
at org.powermock.modules.junit3.internal.impl.JUnit3TestSuiteChunkerImpl.<init>(JUnit3TestSuiteChunkerImpl.java:46)
... 20 more
Then I Removed some of the old methods(not newly added ones) of SomeJavaClass.class(Just to reduce it's size).
Then I tried to run JUnits of ReportActionTest and ReportActionTest loaded properly.
So, I wanted to know, is there any limitation on size of the classes added in #PrepareForTest ?
I want to understand this behaviour, if anyone can explain.
I'm trying to write a simple Jena Fuseki client in Java to send a SELECT SPARQL query and get the result.
I've found the following code written by someone else. It keeps crashing at runtime.
I'm using jena-arq-3.1.0.jar
javac -cp .;jena-arq-3.1.0.jar Main.java print no errors
java -cp .;jena-arq-3.1.0.jar Main crash!
Error log
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/jena/atlas/io/Printable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at org.apache.jena.query.QueryFactory.create(QueryFactory.java:78)
at org.apache.jena.query.QueryFactory.create(QueryFactory.java:52)
at org.apache.jena.query.QueryFactory.create(QueryFactory.java:40)
at Main.main(Main.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.jena.atlas.io.Printable
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)
... 16 more
Main.java
import java.net.URL;
import java.util.List;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
class Main {
public static void main(final String[] args) throws Exception {
String queryString=
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+
"prefix owl: <http://www.w3.org/2002/07/owl#>"+
"SELECT ?subject ?predicate ?object"+
"WHERE {"+
" ?subject ?predicate ?object"+
" } LIMIT 25";
// now creating query object
Query query = QueryFactory.create(queryString);
// initializing queryExecution factory with remote service.
// **this actually was the main problem I couldn't figure out.**
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://localhost:3030/FirstEndpoint/sparql", query);
//after it goes standard query execution and result processing which can
// be found in almost any Jena/SPARQL tutorial.
try {
ResultSet results = qexec.execSelect();
for (; results.hasNext();) {
// Result processing is done here.
}
}
finally {
qexec.close();
}
}
}
You need all necessary libs in the classpath, not only jena-arq.
javac works because you're using only classes from the jena-arq JAR.
java doesn't work because at runtime the classes of ARQ refer to other classes contain e.g. in jena-core, jena-iri, etc.
The easiest way would to add all libs from the Jena distribution resp. the lib folder itself to the classpath.
I have read the questions on using Sqoop from within a Java program here, here and here.
I came up with the following, but I am stumped by a ClassNotFoundException:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import com.cloudera.sqoop.SqoopOptions;
import com.cloudera.sqoop.SqoopOptions.FileLayout;
import com.mysql.jdbc.*;
public class SqoopExample {
public static void main(String[] args) throws Exception {
String driver = "com.mysql.jdbc.driver";
Class.forName(driver);
Configuration config = new Configuration();
// note that this is HDFS path, rather than core path
config.addResource(new Path("./config/core-site.xml"));
config.addResource(new Path("./config/hdfs-site.xml"));
FileSystem dfs = FileSystem.get(config);
SqoopOptions options = new SqoopOptions();
options.setDriverClassName(driver);
options.setConnectString("jdbc:mysql://localhost:3306/dbname");
options.setTableName("v_webstats");
options.setUsername("root");
options.setNumMappers(1);
options.setTargetDir(dfs.getWorkingDirectory()+"/TestDirectory");
options.setFileLayout(FileLayout.TextFile);
new com.cloudera.sqoop.tool.ImportTool().run(options);
}
}
I am sure that all the jars are correctly included and I have tested the connection to my database server and that works as well.
The exact error is:
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.driver
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at SqoopExample.main(SqoopExample.java:14)
not sure what I am doing wrong.
I believe that proper name of the MySQL JDBC driver class is:
com.mysql.jdbc.Driver
(notice the capital "D" in the "Driver)
We are developing java applet and embedding it in our web pages. When the applet is loaded via HTML APPLET tags, the browser/JVM prompts the user to allow it to run. When we hit cancel, the java console indicates the following exception:
java.lang.RuntimeException: java.lang.ExceptionInInitializerError
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission getenv.TEMP)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.System.getenv(Unknown Source)
at downLoadApp.<clinit>(downLoadApp.java:15)
... 21 more
Exception: java.lang.RuntimeException: java.lang.ExceptionInInitializerError
Now, I realize it's most likely because the class java tried to load was prevented from loading, and therefore the exception is thrown, but how do we gracefully handle this situation in the browser? I'd like to detect that the applet was denied and post a reasonable response to the condition, but I'm unaware of how to catch this exception since it appears to have been thrown by the JVM in reaction to not getting the jar file to load rather than code written in it...
Ideas?
Thanks!
You can catch the access control exception by putting the call to System.getenv in downLoadApp.java line 15 in a try-catch statement. That is, instead of this:
static String tmp = System.getenv("TEMP");
you should have:
static String tmp;
static {
try {
tmp = System.getenv("TEMP");
} catch (java.security.AccessControlException ace) {
// tmp is not set, maybe use some default value?
}
}
Do you call System.getenv("TEMP") somewhere in the static context of the downLoadApp class? Most probably this is in the initializer of a static field, but it could be in a static code block.
This is the place where it fails (a java.security.AccessControlException is thrown). The rest of the stack trace are errors following from that. You need to catch this exception to detect that you don't have the appropriate permissions.
As you can't catch exceptions of static field initializers, you need to move the call to getenv into a method or a static code block.
I don't think that you can catch this exception as this is thrown by JVM while loading applet.