Unable to run jetty start.jar - java

When I run start.jar I get the following error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/
jetty/start/Main : 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)
Could not find the main class: org.eclipse.jetty.start.Main. Program will exit.
According to the Jetty documentation (http://www.eclipse.org/jetty/documentation/current/quickstart-running-jetty.html), all I need to do is download the zip, extract, and run start.jar. Google doesn't seem to provide me with any people having similar issues.
Thanks,
Sam

Take a look on the following discussion and specifically on the most popular answer.
Shortly you have a problem of class version incompatibility. Your jetty is compiled with compiler of java 7 while you are trying to run it with JVM of previous version. The solution is: go forward to Java 7: upgrade your JDK and configure eclipse to use java 7 and start enjoying the new features.

This could happen when you have some code compiled using higher JDK, try to check the JDKs used to compile your code.
Besides according to the documetnation Jetty 9 needs JVM 1.7.
Further links:
What Version Do I Use? (Jetty Documentation)
https://code.google.com/p/googleappengine/issues/detail?id=6768
Unsupported major.minor version 51.0 but everything is set to JDK 1.6

The newest release of Jetty needs Version 1.7 of the JVM. Update your JVM or use an older version of Jetty (not recommended).
You can see the Jetty-versions here: http://www.eclipse.org/jetty/documentation/9.0.2.v20130417/what-jetty-version.html#d0e75

java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JRE during runtime.
So upgred your JRE to the version of compiled time version of JDK.

The Java compiler is an advanced version, and the virtual machine is not. Make it uniform either by upgrading your JVM or downgrading your compiler (JDK). I recommend the second option. Gook luck !!!!

This can also happend if you are configuring for example Jetty 8.1 server, but your Jetty installation directory is higher than that, for example 9.1.
So download proper Jetty installation, in Eclipse go to Windows -> Preferences -> Servers -> Jetty -> Edit -> browse to your newly downloaded installation directory.

Related

How to debug Java SE 6 using Eclipse 2022-12?

I cannot debug Java SE 6 using Eclipse 2022-12, It throws the following exception:
java.lang.UnsupportedClassVersionError: org/eclipse/jdt/launching/internal/javaagent/Premain : 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 sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source)
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"
However, I can run this project (Java SE 6) without any problem. I can also run and debug another Java SE 7 normally.
It's same as the problem posted here: https://www.eclipse.org/forums/index.php/mv/msg/1112218/1856754/
It's maybe happen since this change: https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/61
So. is there a way to debug Java SE 6 using eclipse 2022-12, thank you.
TL;DR
Downgrade your Eclipse (we are using 2022-03)
Double check Java version after that
Long story
A colleague had this problem today and after some tinkering we've got it to work. His Eclipse was also stopping at a ghost breakpoint. He had never ever worked on that project and we had cleaned up everything, but even then, it would stop at a breakpoint and break with the mentioned error.
After reading the links in this question, now I understand why this worked, but the second item was very unexpected:
I was on 2022-03 where it was working, so we downgraded his Eclipse to 2022-03 as well. As you pointed out, it seems they have made a change that created this bug during debug mode for Java 1.6.
After that, we double checked Java version everywhere and we found out that the Java 1.6 that was showing up on Eclipse was actually a Java 11 (it was written like "JavaSE-1.6 (jdk 11)"), so we forced it to use from a new Java 1.6 location. I assume Eclipse mixed up something, because I think it runs on Java 11.
After that, debug was working again.

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.

Eclipse on Windows: Exception in thread "main" java.lang.UnsupportedClassVersionError: MainMethod : Unsupported major.minor version 52.0

I have been trying to fix this problem for several hours now, and I am totally at my wits end.
My old computer crashed, but luckily I was able to recover most of my files. I installed eclipse on my desktop, and attempted to import a few projects into eclipse. Every one of them had problems, and not a single one will run. I am running Windows 7 on a homebuild PC- I am 99% sure this is not a hardware problem, I don't think you need specs.
First, every time I import I have followed this thread because it is the first of my problems: every time I import a project, eclipse will not recognize anything from java and I apparently need to manually tell it what to use (which is annoying, and if anyone has a fix for this it would be great to know how to stop it).
But the big problem comes after I fix that. Whenever I try to run the project, no matter which project it is I get the error I copied in the description:
Exception in thread "main" java.lang.UnsupportedClassVersionError: MainMethod : 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 tried just about everything, and am getting pretty close to just breaking the whole thing. I have followed all of the following guides: this one, this one and this one. All of them say to do the same thing: change the project preferences and check the compiler settings. The settings should match.
I am running JDK7 and JRE7. JRE8/JDK8 is not installed anywhere on my desktop- I am not sure why eclipse seems to think it is. My question is this: how do I fix this problem? Do I need to do a clean install and follow a specific set of steps to stop this from happening? Do I need to put JDK8 on my computer? Do I need ro re-import the projects into the workspace in a specific way? Am I just stuck?
If you have followed the steps of configuring JDK, the project might be referring to previously generated classes. You may try Project on menu > Clean, select all projects and then try to run the application.
Moreover, go to Project Properties, Java Build Path, Libraries and confirm that you are referring to the correct Java Runtime version.
Your project was created with a version of Java JDK, but your eclipse has a older version of JDK.
Verify if the version of your project's JDK is the same of the eclipse's JDK.

why is my jar file not being executable after clean and build project from Netbeans?

I followed some online tutorial and build a little GUI. I tried to make a jar file by clean and build project in the Netbeans, but the jar file doesn't let me open for some reason. Am i missing other stuff?
okay here is what happens after i type in java -jar GUI2.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: gui2/GUI2 : U nsupported 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) Could not find the main class: gui2.GUI2. Program will exit
If you want to execute a JAR file, you can run from command line "java -jar yourJarFilePathHere".
Also, take a look at this SO post...
https://stackoverflow.com/a/5258323/1246574
Unsupported major.minor version 51.0
This tells that runtime environment doesn't support the format of class compiled
Either upgrade JRE to supported version or compile your source with runtime environment compatibility by adding -source switch
For netbeans: right click on project > properties > source select the source version compatible with your runtime version (java -version from terminal where you are running it) and rebuild the jar
The problem is that when you compile a java file it targets a certain version of Java (1.6, 1.7, etc). So if you compile your project for version 1.7, but on your computer you only have installed 1.6, it will give you this Unsupported major.minor version error when you try to run it. That just means there's a mismatch between the target version and the installed version.
The solution: check the Java version currently installed on your computer with java -version from the command line. I would just go ahead and update to be safe. Then check the target in your Netbeans settings (right click your project name -> Properties -> Sources -> Source/Binary format)

Unsupported major.minor version java as windows service with procrun

I am trying to run my java application as a windows service.
I did as said here: http://web.archive.org/web/20090228071059/http://blog.platinumsolutions.com/node/234
and http://commons.apache.org/daemon/procrun.html
And I get this exception:
2013-02-04 14:52:25 Commons Daemon procrun stderr initialized
java.lang.UnsupportedClassVersionError: serviceWrapper : 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)
Exception in thread "main"
It seems that your default JRE, installed on your Windows is 1.6 or less, while classes, which you are trying to run, are compiled under Java 7.
java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.
The version number shown describes the version of the JRE that the class file is compatible with.
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
Your application is a Java 7 application, but it looks like you have Java 6 (or less). You can install Java 7 on the Java website.
This exception says that the JRE you are running on is Java 6.0 or an earlier version, but the classes you are trying to run (or at least some of them) have been compiled using a Java 7.0 compiler.
There are two approaches to solving this:
Upgrade your execution platform to Java 7.0, and your code should run as-is.
Recompile your code for the Java 6.0 (or earlier) platform:
Install a Java 6.0 (or older) JDK and recompile your code.
Compile your code using your existing Java 7.0 build environment, but using suitable "-target" and "-bootclasspath" options to get the compiler to generate Java 6.0 compatible code.
(I would recommend an upgrade ...)

Categories

Resources