Java NullPointerException on Minecraft MCP loadup - java

I have made my own Minecraft Client (which runs fine in Eclipse) however once I had exported it as a .jar file, and put it in Minecraft versions folder with a .json file, it returned an error when loaded.
UPDATE------------------------------------------
Exception in thread "main" java.lang.IncompatibleClassChangeError: Implementing class
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 net.minecraft.client.main.Main.main(SourceFile:41)
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
I did the instructions to successfully export it, however it returned this!

Yes, of course it runs fine in your IDE.
Have you noticed that it has 1.8.jar under Libraries tab? That means the "Client" in your Eclipse project is using some files(assets.*) inside 1.8.jar. The Client project in your Eclipse isn't the original Minecraft source code. It is modified a bit by MCP scripts to allow you to launch Minecraft client properly in your Eclipse. You have to copy a lot of stuffs from 1.8.jar and I am sure that Minecraft Launcher can't launch it unless you modify your exported Jar file and *.json.
If you really want to have your own Minecraft.jar, below are the correct steps.
After you've done your modifications to Minecraft, save all files then close your Eclipse. In the directory(folder) which contains eclipse directory, you should fine reobfuscate.bat or reobfuscate.sh. Use the .bat version if you are Windows user, and use .sh if you are MacOS or Linux user.
After you run the file, you should see some files in reobf directory. The files in the directory are obfuscated files and can be copied to Minecraft.jar directly. Now, use WinRar or other tools to open Minecraft.jar(1.8.jar). Copy all the files in reobf directory to Minecraft.jar(and replace if the file exists). After you finished these steps, you've got your own Minecraft.jar!
Now you should create your own version profile in Minecraft Launcher.(Reference: here)
In your .minecraft/versions directory, you should put your own Minecraft.jar. Predict you named it MyCustomMinecraft.jar, you have to create a new directory called MyCustomMinecraft in .minecraft/versions. Now, copy MyCustomMinecraft.jar and paste it in MyCustomMinecraft directory. Then, copy 1.8.json in versions/1.8 directory and paste it in MyCustomMinecraft. Rename 1.8.json to MyCustomMinecraft.json. Open MyCustomMinecraft.json with any text editor, in line 2, you should see "id": "1.8",. change it to MyCustomMinecraft. Your line 2 should look like "id": "MyCustomMinecraft", now.
Open Minecraft Launcher. Edit Profile button > Use version: > you should see release MyCustomMinecraft in the list!

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.

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.

Running a jar file on other Windows versions

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

Lauch Eclipse SWT window application from command line error

First off. I am a newbie and green with respect to Java programming.
I created a Java Eclipse "SWT" "Application Window" on a Eclipse Kepler 4.3.1 (32-bit) running WindowBuilder and SWT (swt.jar). The design view is a composite.
The java application runs fine from Eclipse. I simply press the play button and presto.
Problem:
Issuing
java -cp . PkgNetAccelerator32.netAcceleratorApp
yields the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composite
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.eclipse.swt.widgets.Composite
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
I was doing some research and several posts on other issues suggested that the cure is to create a manifest. I saw an article that said something like:
Select the src folder, right click and select export, then Java, then JAR file, specify Manifest.jar and a path on the folder, make sure the "Generate the manifest file" is selected, and press finish.
I created the manifest file and tried launching it with the following command line:
java -jar ../Manifest.jar -cp . PkgNetAccelerator32.netAcceleratorApp
That yielded the same error message above.
I saw another article that said that one should add in the swt.jar file, but that is taken care of by the manifest. No? Specifying "swt.jar" instead of the manifest that I created resulted in an error message:
no main manifest attribute, in ../swt.jar
That error message makes sense.
I am at a loss. How do I run the java application?
I am testing on my Windows 7 Professional 64-bit desktop, but I need to run on CENTOS too. That should be no problem, as I assume whatever the fix on Windows is, will work on CENTOS.
UPDATE:
I placed the two lib files in a /lib folder to match the answer given. I then issued the following command line and got the following error message.
C:\SoftDev\Projects\NetAccelerator\JavaWorkspace\NetAccelerator32>java -cp "bin/*;lib/*" PkgNetAccelerator32.netAcceleratorApp
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at PkgNetAccelerator32.netAcceleratorApp.open(netAcceleratorApp.java:43)
at PkgNetAccelerator32.netAcceleratorApp.main(netAcceleratorApp.java:33)
I found the following article, which produces a command line that works, just that is not reasonable for sending. I much rather use the answer.
Lets assume you have a eclipse project structure similar to this:
Workspace
-> Project
-> src (source code directory)
-> bin (compiled byte code directory as JAR)
-> lib (jar directory)
-> .classpath (eclipse file)
-> .project (eclipse file)
I am assuming that you are exporting the JAR as an executable JAR.
So in order to run a class in that exported JAR with another JAR from the lib directory (swt.jar) while your working directory is the Project directory you will need to execute:
java -cp "bin/*:lib/*" PkgNetAccelerator32.netAcceleratorApp
Using wildcards requires Java 6 or later
Please note: CENTOS requires : as a path separator. Windows uses a semi-colon.
This will add your classes and the swt classes onto the classpath and run your main class PkgNetAccelerator32.netAcceleratorApp
SWT 32bit vs 64bit
You will either need to use a 32bit JVM locally or continue to use a 64bit JVM and use the 64bit version of swt; see swt on windows 64 bit. I would suggest you match your version of your local JVM (32bit or 64bit) with the version that you will be running on the CENTOS machine. You will however need a different swt jar for CENTOS.

NoClassDefFoundError org/eclipse/swt/SWTError

I m trying to compile an open source software . The build works fine and results into a jar file "five-server.jar". When I try to run this file from cmd , I get these errors.
C:\Users\vickey\code\five-server\dist\main>java -jar five-server.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/SWTError
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.SWTError
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.devtcg.five.Main. Program will exit.
any suggestion what is wrong?
The SWT Jar files are platform dependent.
See http://www.jarfinder.com/index.php/java/info/org.eclipse.swt.SWTError
e.g. on Windows a suitable jar would be:
org.eclipse.swt.win32.win32.x86_3.1.0.jar
or on Mac OS X:
swt-macosx-3.0m7.jar
and so on.
You might run into call kinds of followup problems if you add this dependency e.g. whether you are
using 32bit or 64bit libraries.
It is too bad that these kind of dependency problems show up more often than not these days :-(
You have to set the classpath so that it includes at least the class org.eclipse.swt.SWTError
or the jar containing it:
java -classpath path/to/jar/containing/org.eclipse.swt.SWTError -jar five-server.jar
You should also set the Main-class attribute in the manifest file in the five-server.jar
Following the #Wolfgang Fahl answer, you might download the references here:
Standard Widget Toolkit » 4.3 x86
Maven reference:
https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86.4.3.swt/org.eclipse.swt.win32.win32.x86/4.3
Jar file:
http://central.maven.org/maven2/org/eclipse/swt/org/eclipse/swt/win32/win32/x86_64/4/3/swt/org.eclipse.swt.win32.win32.x86_64/4.3/org.eclipse.swt.win32.win32.x86_64-4.3.jar
Standard Widget Toolkit » 4.3 x64
Maven reference: https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86_64.4.3.swt/org.eclipse.swt.win32.win32.x86_64/4.3
Jar file:
http://central.maven.org/maven2/org/eclipse/swt/org/eclipse/swt/win32/win32/x86_64/4/3/swt/org.eclipse.swt.win32.win32.x86_64/4.3/org.eclipse.swt.win32.win32.x86_64-4.3.jar

Categories

Resources