I asked a question earlier here: NoClassDefFoundError with bluecove's javax.microedition
but got no responses.
I am trying to run some java code (Server.java) that requires bluetooth, so I installed the bluecove-2.1.0.jar file in C:\Program Files\Java.
I compile my code with javac -cp "C:\Program Files\Java\bluecove-2.1.0.jar";. Server.java and run it with java Server -cp "C:\Program Files\Java\bluecove-2.1.0.jar"
It compiles successfully, but when I run it, I get the error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: javax/microedition/io/Connection
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.microedition.io.Connection
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)
... 7 more
Any ideas where i've gone wrong?
EDIT: Following Minus' answer, to fix the error that followed, I also needed to use a different .jar file which I downloaded from http://snapshot.bluecove.org/distribution/download/2.1.1-SNAPSHOT/2.1.1-SNAPSHOT.63/
The problem is that the .dll is not loaded correctly.
The library should contain a .dll that will be saved on disk and loaded, maybe the program cannot save the .dll to disk or cannot read it.
Extract the .dll and follow bluecove installation instructions on Native Library location.
For example:
Create a directory c:\blue, and a directory blue\lib.
Put the files like this:
C:\blue\Sever.java
C:\blue\Sever.class
C:\blue\[bluecove_native_library].dll
C:\blue\lib\bluecove-2.1.0.jar
Open a cmd (Command Prompt) on c:\blue
Try to run the app like this:
java -cp .;lib\bluecove-2.1.0.jar -Dbluecove.native.resource=false Server
This way you will have both Server.class and bluecove-2.1.0.jar in classpath and the DLL in path (since on Windows the current dir is in path).
Add a current folder to a classpath (.;) and make sure that your code is in a package-name folder.
So if your server has a package name :
mypackage
make sure that your class code is in a /mypackage directory
than go to a parent folder to /mypackage and call:
java -cp ".;C:\Program Files\Java\bluecove-2.1.0.jar" mypackage.Server
Related
i've got a big problem exporting my project as a jar file (inside my project i use weka). I'm using Eclipse.
I've added in Java Build Path weka.jar and i've attached to it weka-src.jar, testing my classifier under eclipse everything works, so i've decided to create a jar (because i need that another program use it).
First of all i've created the manifest file:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ weka.jar weka-src.jar
Class-Path: .
Rsrc-Main-Class: start.Home
Main-Class: start.Home
The main class of the program is Home (inside the package start), while weka.jar and weka-src.jar are inside the /src/ directory of the eclipse program.
When i try to execute the jar created i receive this output:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifiers/Classifier
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: weka.classifiers.Classifier
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)
... 7 more
I think that the problem is the CLASSPATH so i've tried to solve it in this way:
I've created the Environment Variable CLASSPATH with this values:
C:\Users\tomma\Desktop\workspace Eclipse\AndroidPermissionsClassifier\src\weka.jar
C:\Users\tomma\Desktop\workspace Eclipse\AndroidPermissionsClassifier\src\weka-src.jar
but nothing changed, can someone help me please?
You are right: the classpath is the problem. Did you remove the items from the manifest classpath when you added them to the environment CLASSPATH? (Side note: place the source jar in the -sourcepath, not the classpath.)
Am trying to compile MATLAB code that employs Bloomberg's APIv3 via the Datafeed toolbox. The code runs fine within MATLAB. The compiler works fine on code without Java. The javaclasspath references the API via:
DYNAMIC JAVA PATH
C:\blpv3\API\APIv3\JavaAPI\v3.7.1.1\lib\blpapi3.jar
I get several compilation errors relating to Java (stacktrace below) on compilation with :
mcc -m -R -startmsg -R -completemsg -v my_prog.m
I suppose I need to tell mcc to link to blpapi3.jar more explicitly, but how? Do I need to set up a static Java path?
Any help would be much appreciated!
Warning: A Java exception occurred getting the method description for the
java.util.Locale class:
Java exception occurred:
java.lang.NoClassDefFoundError: com/bloomberglp/blpapi/Session
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetPublicMethods(Unknown Source)
at java.lang.Class.getMethods(Unknown Source)
at com.mathworks.jmi.OpaqueJavaInterface.doesMethodExist(OpaqueJavaInterface.java:407)
Caused by: java.lang.ClassNotFoundException: com.bloomberglp.blpapi.Session
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.loadClassInternal(Unknown Source)
... 5 more
After some more browsing and lots of trials, I have resolved the issue. The answers are in several posts on this site already. Anyway, there are several issues...
1
It appears that
Java exception occurred: java.lang.NoClassDefFoundError
is a runtime error, not a compile error. To fix this I updated the classpath.txt in both the COMPILER AND THE MCR, located at,
$matlabroot\toolbox\local\classpath.txt
to something like this
javaclasspath
STATIC JAVA PATH
C:\Program Files\MATLAB\R2012a\java\patch
C:\blpv3\API\APIv3\JavaAPI\v3.7.1.1\lib\blpapi3.jar
Alternatively, the blpapi3.jar can be copied into
$matlabroot/java/jarext
alongside the other JAR files.
Also, I removed the dynamic java path, which only works for the Matlab IDE.
2
I have disabled the ADDPATH in startup.m with a clause such as
if ~isdeployed && ~ismcc
addpath D:\Matlab
...
end
3
Arguments to mcc must include the directories in which the source files are located, i.e.
mcc -m -I 'source_file_dir' -v top_level_function.m
4
When handling files within the code, reference relative to the $matlabroot, e.g.
if isdeployed
sFile_Path = fullfile(matlabroot,'..','Input',sFile_Name);
else
sFile_Path = which(sFile_Name);
end
5
Notice that the $matlabroot of the MCR is different from the $matlabroot of the Matlab IDE.
I have three source files in a folder. I simply want to compile them using commandline and then execute them. However, I'm having the following issue. I am on a windows box:
Code compiles fine:
C:\mycode\src\code>javac Source1.java Source2.java Source3.java
Does not run from the folder where class files are:
C:\mycode\src\deckofcards>java Source1
Exception in thread "main" java.lang.NoClassDefFoundError: Source1 (wrong name: code/Source1)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
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$000(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)
Could not find the main class: Source1. Program will exit.
However, it does run when moving to parent folder:
C:\mycode\src\code>cd ..
C:\mycode\src>java code/Source1
Hello1
Hello2
Hello3...
......
....
I want to distribute this source to someone and I'm not sure whether they will be on windows or unix box.
Eventually I want to create an executable jar file but that also was giving me an error like this.
Problem here is not with running Java files, it runs fine. So you wanted to understand the following:
In order to run a Java program you need to do the following steps:
Create Java source files (*.java files)
Compile using javac to binary class files (*.class files)
Run the class files using java executable
We use package structure to keep organize the java files. In your case it is a simple application (and you use the package named "code"), but in a large production application we need to organize our code into many packages.
While running the class file, we need to give the class file path (which includes the package path). So in your case you need to execute java code/Source1 to run your class.
You can learn more from this link: http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html
For creating a JAR file you can refer the link: http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
For making a JAR file executable ensure you add manifest file with main-class attribute.
I'm trying to start my java game but I have some troubles with the java command line:
Here is what I type:
C:\>java -Djava.library.path=%cd%\lib -jar game.jar
And here is what I got:
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
at com.game.Main.main(Main.java:7)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
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)
... 1 more
I can start my game with Eclipse (With Run as Java Application) but after the menu I got the following error:
Exception in thread "Thread-5" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:65)
at org.lwjgl.Sys.loadLibrary(Sys.java:81)
at org.lwjgl.Sys.<clinit>(Sys.java:98)
at org.lwjgl.opengl.Display.<clinit>(Display.java:129)
at com.game.displaygui.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
lwjgl.jar has been put into the folder \lib.
Could you explain me with I got that?
Thanks.
This because lwjgl library is made by two components:
the .jar file which contains Java code
and the native binary library (which can be .so or .dll or .dylib according to your OS)
The first error you are getting is because you are setting the library path, that should contain the native library, but it does contain the .jar. So you get a java.lang.NoClassDefFoundError because you should set either the library path to the folder that contains native library, either the classpath to contain the real lwjgl.jar file.
The second error that you get with Eclipse is a successive step: your classpath contains the jar library but it is not able to find the native library attached to it, you can fix it in the following way:
You should specify explicitly which lib files to include (seperated by ;) :
-cp %cd%\lib\lwjdl.jar;%cd%\lib\<another-lib>.jar
Don't be tempted to use the wildcard * as it will cause more harm than good (from previous experience :))
You use the java.library.path option to specify the location of native libraries to load. In the location pointed to by that option you would place all dll or .so files required by LWJGL. On the other hand, you need to make sure that all required JAR files are on your classpath, via the -classpath option. Currently, you have your JAR files in the wrong directory.
In Eclipse, if you using maven.
Add the following to the project "Run" : "VM options" .
-Djava.library.path=yourpath/youproject/java/target/natives
I am trying to generate wrapper for com4j using tlbimp-20110320.jar. I also tried a 2008 version with the same errors. I get the same errors even when I try running against the example in the tut.
C:\Users\matthew\Documents\NetBeansProjects\test>"C:\Program Files (x86)\Java\jr
e7\bin\java.exe" -jar tlbimp-20110320.jar -o excel -p excel "C:\Program Files (x
86)\Microsoft Office\Office14\EXCEL.EXE"
Exception in thread "main" java.lang.NoClassDefFoundError: org/kohsuke/args4j/Cm
dLineException
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.kohsuke.args4j.CmdLineException
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
After Iceman provided a link to a required library I was able to get it to run a little. However I had to copy the arg4j contents into the tlbimp jar, and the com4j contents into the tlbimp jar as well. Now I get
C:\Users\matthew\Documents\NetBeansProjects\test>"C:\Program Files (x86)\Java\jr
e7\bin\java.exe" -jar tlbimp-20110320.jar -o excel -p excel "C:\Program Files (x
86)\Microsoft Office\Office14\EXCEL.EXE"
Generating definitions from Excel
A referenced type library "Office" is generated into the same package "excel"
Unable to handle the type SAVEARRAY(Variant)*
method ConnectData
interface IRtdServer
A referenced type library "VBIDE" is generated into the same package "excel"
Exception in thread "main" java.lang.NullPointerException
at com4j.tlbimp.driver.Driver$1.resolve(Driver.java:64)
at com4j.tlbimp.Generator$LibBinder.<init>(Generator.java:382)
at com4j.tlbimp.Generator.getTypeLibInfo(Generator.java:686)
at com4j.tlbimp.Generator.getTypeName(Generator.java:663)
at com4j.tlbimp.TypeBinding.bind(TypeBinding.java:173)
at com4j.tlbimp.MethodBinder.declareReturnType(MethodBinder.java:542)
at com4j.tlbimp.MethodBinder.declareWithDefaults(MethodBinder.java:399)
at com4j.tlbimp.MethodBinder.declare(MethodBinder.java:118)
at com4j.tlbimp.InvocableInterfaceGenerator.generateMethod(InvocableInte
rfaceGenerator.java:39)
at com4j.tlbimp.InterfaceGenerator.generate(InterfaceGenerator.java:94)
at com4j.tlbimp.Generator$LibBinder.generate(Generator.java:491)
at com4j.tlbimp.Generator.generate(Generator.java:112)
at com4j.tlbimp.driver.Driver.run(Driver.java:107)
at com4j.tlbimp.driver.Main.doMain(Main.java:132)
at com4j.tlbimp.driver.Main.main(Main.java:56)
tlbimp-20110320.jar is required args4j-2.0.1.jar and com4j-20110320.jar
Note: com4j-20110320.jar, it is necessary to change the name to com4j.jar
Additional Info
The tlbimp of the latest version (tlbimp-2.1.jar), requires args4j-2.0.8.jar and com4j-2.1.jar.
In this version, file name change is not required.
From the stack trace, it looks like you are missing dependent jars from the java class path. The program seems to be looking for Koshuke's args4j library - http://args4j.kohsuke.org/.
Unjar tlbimp.jar and check out its manifest. It has a classpath where args4j and com4j must be in the same directory as tlbimp.jar and require specific names. The specifics of the name depend on the build and may or may not include version number. Name your com4j and arg4j as indicated and you're good to go.