This is what I get:
[user#localhost KioskMenu]$ java -jar ./kioskmenu.jar
Exception in thread "main" java.lang.ClassFormatError: KioskMenu (unrecognized class file version)
at java.lang.VMClassLoader.defineClass(libgcj.so.7rh)
at java.lang.ClassLoader.defineClass(libgcj.so.7rh)
at java.security.SecureClassLoader.defineClass(libgcj.so.7rh)
at java.net.URLClassLoader.findClass(libgcj.so.7rh)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
[user#localhost KioskMenu]$
The only thing I noticed was that my RHEL is using a "free" version of Java. But this shouldn't matter should it?
You compiled the jar with a newer version of Java than the one on your Linux machine.
You should really be doing this:
java -jar ./kioskmenu.jar
Notice the -.
If you just give java jar ./kioskmenu.jar, the JVM is trying to find a class named jar and trying to pass ./kioskmenu.jar as an argument to it - which is clearly not what you want.
Related
I got an error when I run a file exe.
unable to find a java runtime, please download and install a java runtime from http://www.borland.com/jbuilder/resources/javaruntime.html
I use Java 1.8.0_151.
To fix it, I know I can run: javaw -jar exe_name class_name in cmd.
Ex: javaw -jar soflW.exe org.jgraph.JGraphad, but I don't know how to find the class name?
I have found a solution to my problem.
To find class name: I need zip .exe file and open it by winzip, then open file manifest.mf and you can see class name.
In my case, I need run with Java 7 because Java 8 hasn't this class and use java instead of javax as I said.
In other cases, I can run with Java 8 and use javax. I have not tried with java yet.
I'm trying to run a file.java and file.class for which I need to use a library of Cplex (optimization problem) using
$ javac -cp /home/apps/cplex/12.6.1/cplex/lib/cplex.jar file.java
$ java -cp /home/apps/cplex/12.6.1/cplex/lib/cplex.jar:. file
which was recommended when I asked in Compile Cplex in Java in linux . I finally ended the correction of my file (thing that worked in windows didn't in Linux) and the first line worked, but in the second one I got this error...
java.lang.UnsatisfiedLinkError: no cplex1261 in java.library.path
java.library.path must point to the directory containing the CPLEX shared library
try invoking java with java -Djava.library.path=...
Exception in thread "main" java.lang.UnsatisfiedLinkError: ilog.cplex.Cplex.CPXopenCPLEX([I)J
at ilog.cplex.Cplex.CPXopenCPLEX(Native Method)
at ilog.cplex.CplexI.init(CplexI.java:6608)
at ilog.cplex.CplexI.<init>(CplexI.java:629)
at ilog.cplex.IloCplex.<init>(IloCplex.java:10194)
at ilog.cplex.IloCplex.<init>(IloCplex.java:10209)
at memoria.bosques.problemafull(bosques.java:11395)
at memoria.bosques.main2(bosques.java:17829)
at memoria.bosques.main(bosques.java:18014)
I tried replacing java -Djava.library.path=/home/apps/cplex/12.6.1/cplex/lib/cplex.jar instead of -cp /home/apps/cplex/12.6.1/cplex/lib/cplex.jar but didn't work either.
The error occur in the fist time I define something of Cplex(before this was running fine)
IloCplex cplex = new IloCplex();
what can I do to solve my problem?
You need to do exactly what is suggested in the error message. And invoke java with -Djava.library.path pointing to the locations of the cplex shared module.
Something like this:
java -cp /home/apps/cplex/12.6.1/cplex/lib/cplex.jar:. -Djava.library.path=/path/to/libcplex121.so file
I've written a Java program that uses OpenCV library. So far, I executed the program with eclipse (and set the Jar location in eclipse properties).
This is a college final project. My instructor now wants to run the program in his computer. How can I generate a runnable jar(using Ant or using Java code) that will load the Java OpenCV jar from specific location (a directory that will be located in the executable Jar directory), that will work with Linux and Windows (I understood that linux uses a Jar file, and Windows uses a dll file)?
I've tried using:
String currentDir = System.getProperty("user.dir");
System.load(currentDir + "/path_to_jar/opencv-248.jar");
(let's ignore the fact that it will only work with linux) But when executing the jar, the following error occurs:
OpenJDK 64-Bit Server VM warning: You have loaded library /path_to_jar/opencv-248.jar which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c ', or link it with '-z noexecstack'.
Exception in thread "main" java.lang.UnsatisfiedLinkError: /path_to_jar/opencv-248.jar: /path_to_jar/opencv-248.jar: invalid ELF header (Possible cause: endianness mismatch)
Any help would be highly appreciated.
Use the classpath option for your java executable.
If you're running OpenJDK read the manpage at http://linux.die.net/man/1/java-java-1.6.0-openjdk
You should be able to use something along the lines of:
java -jar yourapp.jar -cp ./path_to_jar/
Another option is to build a JAR which includes its own dependencies. Here are some examples I found using the search terms "java create jar include dependencies":
Using Maven
Using Eclipse
I've read a number of answers on classpaths, and i can't understand why this isn't working; Notice the directory listing beforehand that shows jdbc.jar is clearly in the Drivers directory, and then the java command still fails. Also, on my windows machine I can run this exact program with the same setup if i put a ; at the end of the -cp ( "./Drivers/*; ). java -version is java version "1.6.0_37".
[~/test ] $ ls -1 ./Drivers/
dbdump-0.1.0-SNAPSHOT-standalone.jar
jt400.jar
jtds.jar
[~/test ] $ java -cp "./Drivers/*" dbdump.core input.config
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:jtds:sqlserver://SERVER;instance=MSSQLSERVER;database=dbone;
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at clojure.java.jdbc$get_connection.invoke(jdbc.clj:219)
at dbdump.core$_main.invoke(core.clj:60)
at clojure.lang.AFn.applyToHelper(AFn.java:161)
at clojure.lang.AFn.applyTo(AFn.java:151)
at dbdump.core.main(Unknown Source)
[~/test ] $
java handles path same whether be it on windows or linux.
So question is if ; is working on windows why it will not work on linux.
Secondly have you tried executing the same code or program on any other linux machine.
I am presuming may be the jar is corrupt. What about pin-pointedly mentioning the jar. not just * to pick up all jars
yep what nishant mentions is the correct usage of java call. along with loading the jar we also need to call the class
"lib/*" should be enough (reference):
java -cp "Drivers/*" com.example.Classname
Class path entries can contain the basename wildcard character *,
which is considered equivalent to specifying a list of all the files
in the directory with the extension .jar or .JAR. For example, the
class path entry foo/* specifies all JAR files in the directory named
foo.
For what it is worth, this is how things are handled on windows.
I am able to run a java program with some dependencies from cmd line on my mac, but when I try to run it on a linux SUSE 11 box I have it comes back with:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no myNativeLib in java.library.path
This is the cmd line I am running:
java -Djava.library.path=../lib -cp ../jar/a-jar.jar:. MyMainClass
Any help appreciated!
I would recommend to use absolute path for java.library.path. At least you eliminate possible problems with relative path resolution.
Also, just to confirm, you do have Linux library in the lib, right? Mac one will not work.
I'm going go out on a limb and assume(at the risk of a bunch of downvotes) that you are trying to use oracle's native database driver.
If it is indeed a database driver that you are using, you can bail on the native version and simply include the .jar thin client on your classpath by using the -cp extension. This may require some code changes such that you are not attempting to invoke the native driver.
If you are hell bent on using a native driver or you need to because the code relies on it. you need to make sure that the java.library.path variable is set to a directory containing the binary driver files(typically denoted with a .so extension).
Also make sure these driver files(since they are native binary) have been compiled for your distribution of linux and not just conveniently copied from the mac install.
If you are not doing any of these things feel free to ignore everything I've said.