java.lang.NoClassDefFoundError on mac 10.5 - java

My problem started the other day when I tried to run a jar file that was compiled in java 1.6 from a friend. I then got:
java.lang.NoClassDefFoundError
Since I was only using java 1.5 obviously. So I updated using the system update. This did not help and when I ran:
java -version
in the terminal it still said I had java 1.5. I then saw on the internet that there was an "java SE update 4" on apples download page available. I downloaded and installed this file but it still wouldn't work. I gave up and decided to go back to my programming in eclipse. When I tried to compile and run my application in eclipse I now recieved the same error java.lang.NoClassDefFoundError and it wouldnt let me proceed. I tried right clicking the project and viewing the properties but it wouldnt let me, just gave me another error. I figured I might messed something up when I installed the new java version so I tried reinstalling eclipse but it still gave me the same error. I tried creating a new workspace but that wouldnt help either. I then figured I would try to compile throught the terminal using:
javac main.java
java main
But I still get the same error. I went in under systems settings and diabled "java 1.6" and i tried creating new projects with both javaSE-5 and javaSE-6 but it just wont work. My thoughts now is if it has something to do with eclipse not being able to access the bin & src directories in the project directory but that should work if i reinstalled it? I also saw someone mention setting the classpath in os x but I don't know. I would really need some help solving this issue since a lot of my work rely on eclipse working. I would rather not have to reinstall the whole OS just because of this but if I can't get it to work I guess there is no other alternative.
Best Regards
Jonas Kristensson

"Reinstall the whole OS"? Good lord, no.
Your problems have nothing to do with the version of Java. You don't understand how CLASSPATH works.
The class you were trying to run wasn't on the CLASSPATH. If your friend gave you a JAR, you need to add it to your CLASSPATH and use the fully-resolved class name to run it.
A word of advice for your future mental health: When you have problems, don't assume the worst and jump to extreme measures. Try the simple solutions first.

I tried to run a jar file that was compiled in java 1.6 from a friend. ... Since I was only using java 1.5 obviously
Note that if this was really the case you'd get a java.lang.UnsupportedClassVersionError, since Java 5 can't run classes compiled for Java 6 (it might be able to do so, but the class files say "I'm Java 6+" (class version 50) and thus Java 5 would just refuse to run it (max class version in Java 5 would be 49).

Try to compile with
javac -source 1.5 target 1.5 .....

Related

Bluej not running in Ubuntu machine

I recently installed bluej from ducke university's website which was written to to teach java programming in coursera courses.
It successfully installed but when i tried to run it was repeatedly giving error and I searched in internet but there were no exact solution given. The error it given was included in this question.
I even included the code snippet of bluej as well directories inside jvm.
unset JAVAPATH
FOUND="false"
for VMNAME in java-8-oracle jdk-8-oracle java-8-openjdk ; do
for JDKCANDIDATE in /usr/lib/jvm/"$VMNAME"* ; do
The directories inside jvm :
I am complete new to java so please help me to run successfully bluj.
Try downloading blueJ from the official website and reinstalling only one java JDK.
It might be a problem as u have 2 different versions of Java installed and running on one system
Moreover, if you have bluej the try running it in the blueJ application itself it is much easier
Even though Duke/Coursera say that you need the 4.11/Older Specific version of BlueJ, it's not actually right. You can install the latest version of BlueJ and use the packages provided by Duke University to run it exactly as they show you.
I was struggling with the same and made a video about it right now.
How to run BlueJ Duke/Coursera Specific Version 4.11 on Ubutnu or Linux with latest BlueJ

Running newer code in Java 8 -OR- Updating Java for Eclipse in Mac OS 10.12.6?

I am currently taking a class that requires me to use code created by the professor, but I've run into an issue. Whenever I try to run code that uses the professor's code, i get the following message:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: cs/comsc331/ppm/PPM has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0
I know what's causing this, as it tells me - my Java needs to be updated. However, when I go to do so, both Eclipse and the Java Control Panel tell me that I'm all set with the most recent version. I went looking, and on java.com it told me to download Version 8 Update 241, which I did, but nothing changed. When I started looking online for solutions, I came across a post that briefly mentioned that Eclipse would not run with a more recent Java on my system then Java 8.
It seems that I'm at an impasse - I either need a way to update Java without breaking my setup (I tried downloading a more recent version than Java 8 and Eclipse wouldn't start), or I need a way to run newer code on my older system, potentially by recompiling it myself (I tried doing this once and I couldn't figure it out so I could use some advice if this is the best way forward). If I have to recompile the code myself that's okay as there aren't a huge amount of files, but the more efficient the method, the better.
Updating to a newer OS is not an option (if that would even help) because when I've tried to do so in the past, my laptop had to be completely reset (something about it being to hold to handle the new way that files were being done? the explanation I received was unclear).
In the super short term, I've just been straight up copying the code into new files and compiling it on my own, but my professor wants us to work within the existing packages, so that is a bandaid more than anything else. Long term, I need a new laptop that can be fully updated (I got my current one in 2015) but I would assume that there's a more reasonable solution out there.
Thanks!

Java Compilation Errors: Unsupported Class Version

I recently finished a project in Eclipse and it ran without a problem. Then recently I imported a new assignment to work on for class, but when I did my old project all of a sudden had a x on its icon. I looked through the code, nothing had been changed, but it threw this error in the console:
java.lang.UnsupportedClassVersionError
at java.lang.ClassLoader.defineClass1(Native Method)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:685)
And others. Is this possibly due to the version of java being used or something else?
An UnsupportedClassVersionError is thrown when you use a higher JDK version to compile than when you try to run the program. For example, you compile Program.java using JDK1.7 but then attempt to run using JDK1.6. I am guessing that upon importing the new assignment for your class, you unknowingly adopted to use the JDK that the imported project was compiled in.
I suggest going to Eclipse Preferences and taking a look at your installed JRE's to make sure everything is okay and also to look at the projects Properties and looking at its Build Path. In general, make you you are using a version to run in that is at LEAST what you used to compile it. If you chose a higher version everything will still be okay.
EDIT:
Here is a link for more information on the matter and where I had originally read about this. I knew I had saved the link somewhere.
http://javarevisited.blogspot.com/2011/07/javalangunsupportedclassversionerror.html

Running Multiple Java Versions

Hopefully someone can help me because I am apparently brain dead. I have searched and read through a lot of this forum as well as others for help in resolving my problem and I am just not getting it.
I have 2 Java WebApps that I need to run for Johnson Control HVAC units. The one unit is old and strictly requires Java 1.6.0_21. There are no upgrade options available for this unit. Just hundreds of thousands of dollars to replace the whole system. But the system works just fine so I am not interested in replacing it.
Now I have another unit which my company just took over at another location that uses a similar control unit but runs on Java 1.7.0_49 or 69 I can't remember. I have both versions installed on my computer but only the newer unit with Java 1.7 works. My older one now comes up with Unable to Launch Application Error. I have tried all these things and either I am just plain doing it wrong or something else that I am not catching is up.
I tried going into the Java Control Panel and unchecking Enable 1.7. That had no affect, even after rebooting.
I went into the Environmental Variables and under Path I have no Path to Java. So I added the path to the Java 1.6 version which also had no affect.
I have a batch file on my desktop to run the older app because it's web URL is a mile long. In this batch file I tried to add set JAVA_HOME variable and a set PATH variable for Java 1.6 which also had no affect.
I tried just doing java -version:1.6 from the cmd prompt which also did not allow the program to start.
I got it so when I did java -version from the cmd prompt it would tell me 1.6.0_21 for the version but I still can't get the program to load.
So I uninstalled 1.7 from the computer and tried it again. Still would not load the program. I had to reinstall the 1.6 before the older program worked. But once I reinstalled 1.7 I was back in the same boat.
I tried re-installing both programs using the STATIC=1 command through cmd prompt and still only version 1.7 runs and the older 1.6 does not.
I do get a message when I try to load the 1.6 that says, the program has requested an older outdated version of the program. Open with new version recommended or open in the older requested version 1.6.0_21. I select open in the older version but still get the Can Not Launch Application Error.
I have also tried going into the advanced settings and unchecking Internet Explorer for the Browser in the 1.7 control panel and going into the 1.6 control panel and checking Internet Explorer.
What am I doing wrong here or what am I missing? Any help would be appreciated.
This is a Windows XP 32 bit computer. Nothing special, just a word processor mostly.
You are swimming upstream, but it isn't a very large or strong stream, and this can be done.
The upstream part is that most instructions for doing this assume you are going to run only one version of the JVM on a given machine.
The good news is that Java doesn't require this, and is not set up so that it is difficult to run two at the same time. You just have to be rigorous about where each of them get their information.
I would recommend not "installing" EITHER of them. Do not put the executables' or the libraries' directories on your path variable, and do not define a CLASSPATH variable on the machine globally. You will need to unpack a runtime environment for each JVM, each in their own directory tree.
Make one batch file to run each version. It will define its own path variable, and its own classpath (either with SET CLASSPATH= or using the classpath JVM argument).
Good luck.

Java 7 vs Java6 bug

I am having a problem where if a computer is using anything lower than the latest java7 runtime environment, when they click on the jar file, it says, "Cannot find the main class: xxx. Program will exit'.
I don't understand why it does this on java6 Runtime. Any ideas? Thanks guys.
Something is wrong at the OS level rather than in Java. For instance, the accepted answer to Executing a Jar on Vista with a double click explains that you need to have the file associations set up correctly on a Windows OS for double-click to work on a JAR file.

Categories

Resources