I finally managed to get LuaJava to build on OSX and now I am running into trouble using it in Eclipse. I put the jnilib in my system path and when I go to the directory where I built it I can run the Console like this:
$ java -cp "luajava-1.1.jar" org.keplerproject.luajava.Console
API Lua Java - console mode.
> print("Hello World!")
Hello World!
> exit
$
So I'm guessing that means that it is built and installed correctly. I added the jar to my project using the "Add External Jar" in the Java Build Path property window. But when I try to use it I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: ScriptEngineSample
Caused by: java.lang.ClassNotFoundException: ScriptEngineSample
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)
Here is all of my code:
LuaWarrior.java
public class LuaWarrior
{
public static void main(String[] args)
{
new Game().start();
}
}
Game.java
import org.keplerproject.luajava.LuaState;
import org.keplerproject.luajava.LuaStateFactory;
public class Game
{
private LuaState _lua;
public Game()
{
_lua = LuaStateFactory.newLuaState();
_lua.openLibs();
}
public void start()
{
_lua.LdoFile("scripts/hello.lua");
}
}
It turns out that it doesn't need to be in the system path, but is needs to be in the JVM Library folder.
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries/
Related
I have JDK 1.8 installed and below is the class I run in Eclipse:
import io.restassured.RestAssured;
import static org.hamcrest.Matchers.equalTo;
import static io.restassured.RestAssured.given;
public class test {
public static void main(String[] args) {
RestAssured.baseURI = "https://jsonplaceholder.typicode.com";
given()
.queryParam("posts", "1")
.body("")
.when()
.get()
.then()
.assertThat().statusCode(200)
.body("userId", equalTo(2));
}
}
I get the following error:
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
at org.codehaus.groovy.reflection.GroovyClassValueFactory.<clinit>(GroovyClassValueFactory.java:35)
at org.codehaus.groovy.reflection.ClassInfo.<clinit>(ClassInfo.java:107)
at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:95)
at org.codehaus.groovy.reflection.ReflectionCache.<clinit>(ReflectionCache.java:39)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:209)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:107)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:85)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36)
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:86)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.createMap(ScriptBytecodeAdapter.java:635)
at io.restassured.internal.ResponseParserRegistrar.<init>(ResponseParserRegistrar.groovy)
at io.restassured.RestAssured.<clinit>(RestAssured.java:346)
at test.main(test.java:12)
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
at org.codehaus.groovy.runtime.dgmimpl.NumberNumberMetaMethod.<clinit>(NumberNumberMetaMethod.java:33)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:350)
at java.base/java.lang.Class.newInstance(Class.java:645)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.createMetaMethodFromClass(MetaClassRegistryImpl.java:257)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:110)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:85)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36)
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:86)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.createMap(ScriptBytecodeAdapter.java:635)
at io.restassured.internal.ResponseParserRegistrar.<init>(ResponseParserRegistrar.groovy)
at io.restassured.RestAssured.<clinit>(RestAssured.java:346)
at test.main(test.java:12)
Run mvn dependency:tree to view the whole dependency tree. You check if you see a problem here.
And try upgrading the maven-plugin version.
class First {
public First() {
super()
// TODO Auto-generated constructor stub
}
static void main(String s)
{
print('Hii');
}
}
After running the code in eclipse using Groovy Console option the following exception is being shown.
java.lang.ClassNotFoundException: groovy.ui.Console
at org.codehaus.groovy.tools.RootLoader.findClass(RootLoader.java:179)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:151)
at java.lang.ClassLoader.loadClass(Unknown Source)
Nothing wrong with the code. Groovy Console dependencies are not included by default with Groovy 2.5+ You can use Groovy 2.4 which bundles groovy-all or run as Java Application since you have a class with a main method.
I have the following Java file in Eclipse.
package java_python_tutorial;
import org.python.core.PyInstance;
import org.python.util.PythonInterpreter;
public class MainJython {
public static void main(String[] args) {
PythonInterpreter python = new PythonInterpreter();
python.execfile("pytest/test_np.py");
// PyInstance test = (PyInstance) python.eval("Test()");
// test.invoke("printArr");
python.close();
}
}
If I include just the Jython JAR, running the file will result in an ImportError: no module named numpy from Python. I tried fixing this problem by also including the JyNI JAR in my project build path, but now running the file gives this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/python/modules/_weakref/ReferenceBackendFactory
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at org.python.core.PySystemState.initialize(PySystemState.java:1015)
at org.python.core.PySystemState.initialize(PySystemState.java:947)
at org.python.core.PySystemState.initialize(PySystemState.java:930)
at org.python.core.PySystemState.initialize(PySystemState.java:925)
at org.python.core.PySystemState.initialize(PySystemState.java:920)
at org.python.core.PySystemState.initialize(PySystemState.java:916)
at org.python.core.ThreadStateMapping.getThreadState(ThreadStateMapping.java:32)
at org.python.core.Py.getThreadState(Py.java:1440)
at org.python.core.Py.getThreadState(Py.java:1436)
at org.python.core.Py.getSystemState(Py.java:1456)
at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:105)
at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:94)
at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:71)
at java_python_tutorial.MainJython.main(MainJython.java:7)
Caused by: java.lang.ClassNotFoundException: org.python.modules._weakref.ReferenceBackendFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 18 more
For reference, the contents of the Python script I'm calling is:
import numpy as np
class TestNP(object):
def __init__(self):
self.arr = np.array([[1,2,3],[4,5,6]])
def printArr(self):
print(self.arr)
I have a folder full of classes from a class I took. With a fresh install of jGrasp old projects that used to run fine are now full of "symbol not found" errors.
I still have the libraries, but I don't know how to import them. The way our class was set up, you didn't need import statements for anything that was in the library.
/* Turtle Drawing Program Lab 6, Part B */
/* Started by Celine Latulipe , modified by Bruce Long*/
public class Lab6PartB {
public static void main(String [] args)
{
/* Create the world */
World w = new World();
/* Create the turtle, call him Tom */
Turtle tom = new Turtle(w);
/* test the getDistance2() method */
int dist = tom.getDistance2();
System.out.println("This should print out the value 400. Value is: " + dist);
tom.moveTo(500, 400);
dist = tom.getDistance2();
System.out.println("This should print out the value 640. Value is: " + dist);
// TODO: Add a third test case that you make up
}
}
Error:
----jGRASP exec: java Lab6PartB
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: ModelDisplay
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: ModelDisplay
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)
... 7 more
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
You can add the directory containing the class files to the classpath, either at the OS level, or using "Settings" > "PATH / CLASSPATH" > "Workspace" in jGRASP.
Also, you could copy all the class files/directories to the folder containing your new project classes.
I'm coding on Jitsi using Eclipse: I have to use JDBC to connect to MySQL database, so I've imported java.sql.* in my MainFrame class and I've included mysql-connector-java-5.1.18.jar into "Java Build Path" -> "Libraries".
When I run the project, I've this error:
IOException in readRegistry: java.io.EOFException
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found by [76]
at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)
at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at net.java.sip.communicator.impl.gui.main.MainFrame.init(MainFrame.java:301)
at net.java.sip.communicator.impl.gui.main.MainFrame.<init>(MainFrame.java:239)
at net.java.sip.communicator.impl.gui.UIServiceImpl.loadApplicationGui(UIServiceImpl.java:133)
at net.java.sip.communicator.impl.gui.GuiActivator.start(GuiActivator.java:129)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:629)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1827)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1744)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1148)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
at java.lang.Thread.run(Unknown Source)
I've created another project separated from Jitsi and I've tested my code following the same procedure (including java.sql.*; , adding the library), but the "new" project works fine and I can connect to my database, Jitsi doesn't.
Source:
import java.sql.*;
public class SQLFirstTime {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/cdcol";
Connection con = DriverManager.getConnection(url,"user", "pass");
// ...
con.close();
} catch(SQLException sqlEx) {
System.out.println("Errore SQL");
sqlEx.printStackTrace();
} catch(ClassNotFoundException cnfEx) {
System.out.println("Class NOT FOUND!");
cnfEx.printStackTrace();
}
}
}
Thanks,
also if i'm using Ant to build the project how can I include the JDBC library?