Running a jar file on other Windows versions - java

I've written a code that is supposed to be exporting a set of windows registry keys. I've successfully written the code and was able to also send the results of executing the code as a jar file to my email. However, while testing the jar file ( I've included the piece of code in the build.xml from the java website that will allow me to run the jar file out of the dist folder) I was able to get the desired results on my machine because I wrote the code on a windows 8.1 machine. While testing it on another machine ( with Windows 8 and Windows 7 professional ) I was not able to execute the code and the error I was getting was as follows :
"Java Virtual Machine Launcher, A Java Exception has occurred."
I used to get that error message when I did not include the code in the build.xml page to allow the jar file to run out of the dist folder, but now I'm getting it when I'm executing the jar file on different machines other than my own
Running it from the command prompt this is what i got:
Exception in thread "main" java.lang.UnsupportedClassVersionError: smc_1/SMC_1
W1 : Unsupported major.minor version 52.0
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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

#Sara, that error is a JVM mismatch error. I think you're trying to run a jar compiled for Java 8 on a system with Java 7 (or older) installed. Your options are (a) update the JVM to Java 8 or (b) recompile your application with the target set to 1.7 or whatever JVM you need to target, provided that your app doesn't include any Java 8-specific code. Oracle has some information on updating Java to the latest version here: http://www.java.com/en/download/help/java_update.xml

Related

How should I compile my java project targeting Java SE 8?

I have a Java Project (an application to play connect 4) and I want to turn it into an executable file. I created this project in VsCode, and I am using the Java Language Server (see details below). I extracted the .jar file, and used Launch4J to turn it into an executable, and when I run it, I get an error message (see below).
I researched the problem, and it seems that I need to compile my code targeting Java SE 8 rather than 17 (I have 17 currently installed). Could anyone explain to me how I should do this, or is there anything else I'm doing wrong?
The project has multiple files. I'm not sure if this is relevant, but the project has no external dependencies, although it does use javax.swing, javax.sound, and java.awt (as well as java.io.File, java.io.IOException, and java.util.Random, but I'm pretty sure those are irrelevant).
I have eclipse installed if it's necessary, but I only installed it today, and have no experience using it at all. The JDK I am using is (I believe) version 1.8.0_321. (At least this is what I get when I type in java -version.)
The Java compiler version is javac 17.0.2
When I try to run the executable generated by Launch4J, I this is the error I get:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Main has been compiled by a more recent version of the Java Runtime (class file version 61.65535), this version of the Java Runtime only recognizes class file versions up to 52.0
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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
And the popup error:
Java Virtual Machine Launcher
Error: A JNI error has occurred, please check your installation and try again.
Here are the Settings I used in Launch4J:
Output File: C:\Users\username\OneDrive\Coding\Java Connect 4 v.2\Connect 4.exe
Jar: C:\Users\username\OneDrive\Coding\Java\Java Connect 4 v.2\Java Connect 4 v.2.jar
Don't wrap the jar, launch only: NOT ticked
Wrapper Manifest: none
Change dir: .
Command Line args: none
Process priority: Normal
Both Options NOT ticked
Min JRE version: 1.2.0, Prefer public JRE, but use JDK runtime if newer
Max JRE version: none, First 64-bit, then 32-bit. (This was the default.)
All other settings are default.
Download the latest Java JDK version as .exe file (“x64 Installer”) and install by clicking on the .jar file.
Now the server should start again
#Holger has answered this question. The answer to the problem was to ship a custom JRE image with the application with the help of JLink. That way it can be used regardless of the local version of JRE.

Issue with running JAR in Windows, works fine in Ubuntu

I am stuck on the following error. I don't know what type of error it is. What should I do?
C:\Users\shehzad\Desktop\Software>java -jar Untitled.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: FrontEnd/MainWindow : Unsupported major.minor version 52.0
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 java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Scenario is: I developed software that works fine in Ubuntu 14.04 Lts. It's JAR also works in Ubuntu, but when I tried this JAR
in Windows 7 it shows the above error.
Ubuntu Java version: 1.8.0_101
Windows Java version: 1.7.0_79
class version 52.0 means it requires Java 8 to run. You should for security reasons update your Windows Java anyway, so its time to go to Java 8. If you need Java 7 for something you can keep it as a private installation, but make sure the "javapath" as configured by the registry points to Java 8.
You can also start in a command window or via explorer link the right Java.exe without installing it as public version like this:
"c:\Program Files\java\jdk_1.8.0_102\bin\javaw.exe" -jar app.jar
Your jar file is compiled using 8u101 (major.minor version 52.0) and your trying to run on 7u79. Hence you end up in Unsupported major.minor version 52.0.upgrade your java to 8u101.

Running java file in cmd - error given

I recently moved a project from one machine to another but I am now given an error when attempting to run java files on the new machine. I'm trying to run a java file from part of an Android project in command prompt but I am given an error. The file compiles okay but fails to run. Here is the error I am given;
Exception in thread "main" java.lang.NoClassDefFoundError: ChatServer (
e: edu/UTEP/android/ChatServer)
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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Any ideas why I am receiving this error?
Your ChatServer is having a package declaration of edu.UTEP.android in the top. So either you need to remove that package declaration recompile your java file again and run it
(or)
you need to create folder structure like this
CurrentDir/edu/UTEP/android/
Keep your java file in android folder and invoke java ChatServer from CurrentDir. Any of these two will solve the issue :-)
For more info on packages, you can refer to my previous answer on a similar issue here
Make sure that the .jar that provides ChatServer is in your runtime Classpath.
This issue rise when jvm don't file class path.
check where u have placed your jar file or lib folder.
Move to that directory then run javac and then java .
Issue will be resolved.

Exception when running a Jar on another computer (other Java version)

Playing with a little network program, created a Jar with netbeans. Runs just fine on my computer java 1.7.0.60, but when I take it to another computer that has a newer version of java 1.7.0_65 it will not run, I get this error:
C:\Program Files (x86)\Java\jre7\bin>java -jar ReverseEchoServer.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: reverseechose
rver/SocketClient : Unsupported major.minor version 52.0
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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
I have read several posts on here that talk about PATH, have looked at that but no luck. I belive its the version differance. Any advice would be most appreciated, Thanks!
Java class files compiled for Java 7 have Major/Minor versions 51/0. If you have a JVM implementation that wasn't prepared for Java 7, it would give you this error indicating "I don't know how to interpret and run this class file."
Try either compiling for an older JVM version, or upgrade your JVM.
Use the Target and specify the version in which it needs to be executed using target switch followed by version number.
javac -target 1.7 yourJarName.jar

Using jasperstarter to compile and run iReport "java.lang.UnsupportedClassVersionError"

Basically what I want to do is create a PDF from a iReport jrxml or jasper file.
The idea is to use this for reports over the net and the best solution I managed to find was to use a program like jasperstarter and then run the report with a connection to MSSQL database.
To get the connection going I had to download the latest net.sourceforge.jtds.jdbc.Driver.
The report works fine using iReport 5.1 but when I do follow the instructions from jasperstarter I get an "java.lang.UnsupportedClassVersionError" response.
jasperstarter command
jasperstarter pr -t generic -f pdf -i test_report.jasper -o test -u username -p password --db-driver net.sourceforge.jtds.jdbc.Driver --db-url jdbc:jtds:sqlserver://LOCAL-PC/Demo_DB
output
Exception in thread "main" java.lang.UnsupportedClassVersionError: net/sourcefor
ge/jtds/jdbc/Driver : Unsupported major.minor version 51.0
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at de.cenote.jasperstarter.Db.getConnection(Db.java:69)
at de.cenote.jasperstarter.Report.fill(Report.java:220)
at de.cenote.jasperstarter.App.processReport(App.java:222)
at de.cenote.jasperstarter.App.main(App.java:107)
Please advice.
Basically, you are trying to run code that was compiled on / for Java 7 on an older JVM.
That doesn't work.
Either:
run your application on a Java 7 JVM (or later1); i.e. upgrade your Java version,
find a build of the JDTS driver that is suitable for your execution platform, or
find the source for the JDTS driver and build it for your platform.
For more detailed information on this exception and its causes, read:
http://stackoverflow.com/questions/10382929.
1 - Note that even Java 7 is end-of-life now. If you are still running that version of Java you should upgrade.
Make sure you have same JRE and JDK.
If not sure un-install download the latest JDK and try again.
Note that the JDK does install the JRE automatically.

Categories

Resources