lwjgl UnsatisfiedLink error - java

I know this may seem like a duplicate but throughout the examples I have seem I must be doing something wrong still.
I am using Netbeans 8.0.
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.opengl.Display.<clinit>(Display.java:132)
at org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.AppGameContainer.<clinit>(AppGameContainer.java:36)
at Engine.main(Engine.java:33)
Is my error which i know from research is just the path isn't set. I went into Properties > Libraries and i have a Library LWJGL which has multiple .jar's in it, including lwjgl.jar. I also have gone to Properties > Run which is where i believe my problem is. I have made a folder in C:\LWJGL\ that contains the lwjgl.jar aswell. My VM Options are -Djava.library.path=C:\LWJGL\.
I know i must be missing something here in regards to where is it looking for the native files or something? After reading through other posts i think my problem is the location of the native files.

java.library.path takes the path to the natives (extensions .dll, .so, .dylib), not the jar file. You have to point it directly to the folder where you have stored these files; it won't work when they are in a subfolder. The LWJGL zip file you downloaded will most likely contain a native folder that contains these files.

Related

Properly create Java JAR

I am using IntelliJ to create a variant of the Java WorldWind application. When I build the JAR artifact in IntelliJ I can see my DLLs and SOs in the top-level directory of the JAR. However, when I try to execute it, it complains it can't see these libraries that are inside the JAR (tried both Windows and Linux, thus being why I include SOs and DLLs).
What do I need to do to get it to see these libraries?
This is my first time creating an executable JAR, so sorry for the vagueness, I'm not quite sure what information is important. Please ask me any questions necessary to better understand this problem, and I will answer them.
Edit:
Catched FileNotFoundException: D:\code\Animator\animator\out\artifacts\Animator_jar\Animator-natives-windows-i586.jar (The system cannot find the file specified),
while addNativeJarLibsImpl(
classFromJavaJar class com.jogamp.common.os.Platform,
classJarURI jar:file:/D:/code/Animator/animator/out/artifacts/Animator_jar/Animator.jar!/com/jogamp/common/os/Platform.class,
nativeJarBaseName Animator-natives-windows-i586.jar):
[ file:/D:/code/Animator/animator/out/artifacts/Animator_jar/Animator.jar ->
file:/D:/code/Animator/animator/out/artifacts/Animator_jar/ ] +
Animator-natives-windows-i586.jar ->
slim: jar:file:/D:/code/Animator/animator/out/artifacts/Animator_jar/Animator-natives-windows-i586.jar!/
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: D:\code\Animator\animator\out\artifacts\Animator_jar\gluegen-rt.dll
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:551)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:64)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:96)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:414)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:388)
at com.jogamp.common.os.Platform$1.run(Platform.java:209)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:179)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:82)
at au.gov.ga.worldwind.animator.application.AnimatorConfiguration.<clinit>(AnimatorConfiguration.java:46)
at au.gov.ga.worldwind.animator.application.Animator.<clinit>(Animator.java:205)
As far as the structure of the JAR, I don't know how to show other than a screenshot of the JAR in 7-Zip:
In the image we can see that the name of the jar is: Animator.jar, but intelliJ is searching for: Animator-natives-windows-i586.jar. You must go to Module Settings - Artifacts and change the OutputDirectory to: D:\code\Animator\animator\out\artifacts\Animator_jar
Then check the name of the artifact to match the path and the name of the file.
The image added by me is an example.

Getting NoClassDefFoundError from Groovy sql.eachRow function

I am debugging a Java application that runs Groovy program for a certain database transaction call. When the pointer passes the following line of the Groovy program
sql.eachRow("select.....from...where...",[value0, value1])
It prints the following exception
- Servlet.service() for servlet Groovy threw exception
java.lang.NoClassDefFoundError: org/apache/commons/collections/CursorableLinkedList
at org.apache.commons.pool.impl.GenericObjectPool.<init>(GenericObjectPool.java:392)
at org.apache.commons.pool.impl.GenericObjectPool.<init>(GenericObjectPool.java:258)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:795)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at groovy.sql.Sql$36.run(Sql.java:1192)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.sql.Sql.createConnection(Sql.java:1190)
at groovy.sql.Sql.eachRow(Sql.java:466)
at gjdk.groovy.sql.Sql_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:115)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:119)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:187)
at sce_expiry$_run_closure1_closure4_closure5.doCall(sce_expiry.groovy:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:69)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:97)
at sce_expiry$_run_closure1_closure4_closure5.doCall(sce_expiry.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
sce_expiry.groovy is the groovy file name.
The solutions other people got recommended are like making sure the common-collections.jar and groovy-all.jar are in the classpath. I have verified. Both jar files are located in the lib folder of the webapp's directory inside my Tomcat. And the class can be found inside common-collections.jar with the same package name.
I actually have almost 0 experience with Groovy. So I'm really not sure whether some additional configuration is needed.
Does anyone have any idea?
--------------------------Solution found and question might change--------------
Alright, so I found out two ways to make this work. And they are related.
First of all, I am using Tomcat 5 here. In the Tomcat folder, there is a common/lib directory for users to place jar files shared by applications.
There are already some Apache commons-xxx.jar files in place but not commons-collection.jar. If I put a copy of commons-collection.jar together with the existing jar file, it will work! Alternatively, remove one jar file (commons-dbcp.jar), it will work as well. Both commons-collection.jar and commons-dbcp.jar are available in the application's own lib folder.
Yet, I need to do more research on this, but I suspect that commons-dbcp.jar need to work together with commons-collection.jar for the function I call, and that common/lib folder takes a higher priority to be read in. Therefore, once commons-dbcp.jar is read in, Tomcat will ingore the same in the app's lib folder and will only work with the one in the common lib folder. While commons-collection was not available in the common lib folder, it complained when commons-dbcp.jar was looking for it.
Please correct me if I'm wrong. I don't know perfectly how Tomcat works..
So this question is no longer tagged with Groovy and Grails, but Java and Tomcat 5.

java.lang.NoClassDefFoundError occures using tess4j without Eclipse

I use tess4j library for my java app. I followed instructions and copied liblept168.dll and libtesseract302.dll into my project root folder. When I run my app with Eclipse, it works normally. But when I export it as runnable jar file, it gives me java.lang.NoClassDefFoundError - UnsatisfiedLinkError: The specified module could not be found. But I am sure, that program see this files, because earlier before I added this files it gave me other error, that files can't be found. I also used to copy this dlls to my jar archive, but it didn't help. I am absolutely sure, that I use right jre too. I just can't understand what can be wrong...
Tesseract1 api = new Tesseract1();
api.setTessVariable("tessedit_char_whitelist", "(),-+0123456789");
//part of code of getting image
String result = api.doOCR(image);
Any ideas?
UPD:
I edited my manifest file as you said and it is:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ jsoup-1.7.3.jar json_simple-1.1.jar Filters.jar ja
i_core.jar jna-4.1.0.jar tess4j.jar jai_codec.jar jxl.jar myjsocksj.j
ar jai_imageio.jar
Class-Path: jai_imageio.jar tess4j.jar
Rsrc-Main-Class: com.slando.MainWindow
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Then there were errors about missing dll files and I copied them into jar. And then the same error began to occure.
Stacktrace:
java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.tess4j.Tesseract1
at com.slando.parser.ImageParser.getNumberFromImage(ImageParser.java:109)
at com.slando.parser.ImageParser.loadNumberFromImage(ImageParser.java:138)
at com.slando.parser.ImageParser.loadNumberFromImage(ImageParser.java:144)
at com.slando.parser.PageParser.loadPhone(PageParser.java:202)
at com.slando.parser.PageParser.loadFullInfo(PageParser.java:319)
at com.slando.HttpThread.run(HttpThread.java:58)
at java.lang.Thread.run(Unknown Source)
One more:
java.lang.UnsatisfiedLinkError: The specified module could not be found.
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.Native.open(Native.java:1759)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Native.register(Native.java:1396)
at com.sun.jna.Native.register(Native.java:1156)
at net.sourceforge.tess4j.TessAPI1.<clinit>(Unknown Source)
at com.slando.parser.ImageParser.getNumberFromImage(ImageParser.java:109)
at com.slando.parser.ImageParser.loadNumberFromImage(ImageParser.java:138)
at com.slando.parser.ImageParser.loadNumberFromImage(ImageParser.java:144)
at com.slando.parser.PageParser.loadPhone(PageParser.java:202)
at com.slando.parser.PageParser.loadFullInfo(PageParser.java:319)
at com.slando.HttpThread.run(HttpThread.java:58)
at java.lang.Thread.run(Unknown Source)
Eclipse has the tess4j jar in its classpath, but your system does not. To distribute this project, the tess4j jar needs to be in the classpath in your jar manifest. You can also add the path to this jar to the classpath environment variable in your system settings.
Someone else had the same problem

JAR file behaving differently in a different place in file system

I have project called test in Eclipse which I want to export into Runnable JAR file. During the process of exporting the project, when I choose as a location of JAR file the subfolder of test folder in file system, such as C:/.../test/App.jar, it will work. However, when I want to put it for example on my desktop, it will run but in a very limited look (some GUI components missing) and it throws a lot of exceptions saying something like that:
at java.awt.EventDispatchThread.run(Unknown Source) xception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Could not initialize class com.sun.opengl.impl.windows.WindowsGLDrawableFactory
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javax.media.opengl.GLDrawableFactory.getFactory(GLDrawableFactory.java}
What can be the problem? I assume it is not good that I have to specify my JAR file concretely into one folder in file system, it would become unuseful for any other potentional user.
Looks like the jar needs other jars to execute. In this case you would have to set the classpath before you execute the jar
This might help you with your problem.

Java Eclipse Error 'Source not found.'

I'm new to the programming world, and I am trying to do a simple program where I read and output a single number from a file. I believe I set everything up right in the code, do I need to do anything special with the location of the .txt file to make the program read the file?
package pack;
import java.util.*;
import java.io.*;
public class Ch2_PrExercise17 {
public static void main(String[] args)
throws FileNotFoundException{
Scanner inFile = new Scanner(new FileReader("inData.txt"));
int num1;
num1 = inFile.nextInt();
System.out.println(num1);
}
}
The exception I get is as follows;
Exception in thread "main" java.io.FileNotFoundException: inData.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at pack.Ch2_PrExercise17.main(Ch2_PrExercise17.java:8)
If Eclipse is really saying "source not found" then it is talking (at that point) about the source code of something.
If you are managing to run the class from Eclipse, then Eclipse has been able to compile it, so it knows where the source code is. So it must be the source code of something else. My best guess is that it can't find the source code for the standard Java class library, and that probably means that Eclipse is running on a JRE installation not a JDK installation.
(If my theory is correct, then the "source not found" text is embedded in the exception stacktrace ...)
It might also be a build problem but I doubt it, because if the class wasn't building you'd see error markers when you view the source file in eclipse, and Eclipse would complain when you tried to run it. Eclipse would also complain if the source file was in the wrong directory.
The second part of the problem is getting your application to find the "inData.txt" file. That should be simple. When you try to open a file with a relative pathname, the Java libraries will try to resolve the pathname relative to the application's "current directory". By default, when you run the application from Eclipse, this will be the directory your shell was in when you launched Eclipse; e.g.
$ cd /home/josh/somedir
$ eclipse &
... and the default current directory should be "/home/josh/somedir".
If the default current directory is not right, you have a number of options, including:
Change directory to the right one before launching Eclipse.
Use Eclipse's "Run Configurations" panel to select your application's launch configuration, and change the launcher's current directory setting.
Change the relative pathname in the source code to the correct absolute pathname for the file.
FOLLOW-UP
Exception in thread "main" java.io.FileNotFoundException: inData.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at pack.Ch2_PrExercise17.main(Ch2_PrExercise17.java:8)
The "Unknown Source" messages mean that the JVM (not Eclipse) cannot find the information it needs to produce a full stacktrace. You appear to be executing using an "rt.jar" file that has debug information stripped. You can ignore this issue, but to fix it you would need to look into what JVM is being uses, and why the "rt.jar" has no debug info.
The real problem is the FileNotFoundException exception, and my diagnosis of that (as above) stands. The "current directory" is not what it needs to be for that relative pathname to resolve. See above for possible solutions.

Categories

Resources