JAR file does not load class files from ext - java

I installed JDK 1.6 on my Linux system, the $JAVA _HOME directory is /usr/java/jdk1.6.0_07.
I built the path on Eclipse to $JAVA_HOME. It runs smoothly through Eclipse and loads all third party JAR files from /usr/java/jdk1.6.0_07/jre/lib/ext/, but when I export the JAR file and run it, it throws ClassNotFoundExecption.
Why?

Did you install Java properly? Here are some instruction for installing Java 7 or Java 6
Are you sure that the version of Java you are using is correct one since there can be several versions of java on linux? Try java -version on terminal where you run it to check.
Do you use any third party library? If so, did you specify the class path when you run the jar file or bundle them inside your jar file?

What does java -version return? Are you using the same JRE for execution?

Related

Java ClassVersionError although version seems to be okay

I'm getting the following error in my java web app (The application launches okay but when I click a button following error occurs). I'm using Tomcat (7.0.109) to run this application.
java.lang.UnsupportedClassVersionError: FileDetailsServlet has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [FileDetailsServlet])
Previously I used Java 15 (class version 59.0). But then I switched to JDK and JRE 1.8.0_311 (class version upto 52.0)because of other 3rd party apps.
Here are some things that I did
I've checked class version of FileDetailsServlet class using this
javap -verbose FileDetailsServlet| findstr "major"
command. And it shows that version is 51.0 (Java 7).
I've set JDK compliance to 1.8 in eclipse. (Project specific settings)
After changing JDK I recompiled all the files using JDK 1.8.0_311
I've checked environment variables. JAVA_HOME is "C:\Program Files\Java\jdk1.8.0_311"
JRE_HOME is "C:\Program Files\Java\jre1.8.0_311" and Path is "C:\Program
Files\Java\jdk1.8.0_311\bin"
Am I missing anything? I can not go back to Java 15. So is there any way around?
Check your class path for any "leftovers" from the old system. It looks like you are not inspecting the correct files. Maybe you have the FileDetailsServlet in a wrong version as depencency somewhere, or just in a "standalone" JAR- or WAR-file.
It is also important that Eclipse settings alone will maybe not cover, how the used container serves the servlet, so which technology do you use to run the FileDetailsServlet? That's the crucial point: this thing that you use to run (Tomcat, Jetty, other container, maybe included in a fat WAR or fat JAR file from Sprint Boot or another similar technology) has to use the correct .class file.
As you are using Tomcat as container:
You should check the class files inside the folder webapps/appname folder below your tomcat folder (replace appname with the deployment context name) Take care: when you run tomcat from Eclipse this could be somewhere completely different than the installation folder on disk, but I don't have an Eclipse installation ready to check that.

Create standalone executable from Java code for Windows, OSX and Linux all at once

i'm coding a project in Java and building it with gradle.
I need to keep it simple and compile it into standalone binaries for Windows, Mac and Linux.
Is there anything which can build all of this binaries or must i use a separate lib (like Launch4j for Windows executables) for every single binary?
I'd like to call a single "build-all-binarys"-like task in gradle and get a .exe, .app and .bin file out of it.
It would be nice to have the possibility to bundle a JRE into the binary as well.
Use the javapackager, added since Java 8 in the JDK.
It nicely creates a self contained executable - that's it bundles the JVM with every copy - of all standard operating systems with one call.
The javapackager is located in JAVA_HOME/bin/ directory.

Open jar file using JRE on Mac

I have a jar file that is meant to be ran through the command line.
I am not planning to do any java development on the machines where the application will run and my thought process is that therefore I should only need the JRE and not the JDK. In addition, the JDK is like 4x as big as the JRE and I would like to not have to download it.
When installing the JRE on a Mac, it does not set the path for the java command and if I try to run it, osx prompts me to install the JDK.
I wonder if anyone could provide some insight as to how to use the java command in a mac without having the download the bigger sized JDK?
Thanks a lot.
Have you tried running this in terminal?
java -jar MyJarName.jar
However, you can also try and make a runnable application of the jar file. Take a look at Packaging a Java App for Distribution on a Mac
EDIT:
You can also try running your starter class from the terminal. cd to the bin folder of your project, then java packageName.className. For example, java my.package.Starter.

AppBundler doesn't include binaries from JRE in OS X Java App

I'm trying to to package my java app into an OS X App Bundle and I want to include the JRE, so it can run without a installed JRE.
I'm following http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
The AppBundler Ant Task will generate a .app with the JRE included but it is missing all the binaries.
The App will run but i'm not sure it's not using my installed JRE instead as it's missing the binaries. Or does the included JavaAppLauncher replaces the normal java binary?
The bin/ folder is not included when bundling the JRE in an app. The only native binaries it uses are in MyApp/Contents/MacOS and MyApp/Contents/Plugins/MyJRE/Contents/MacOS.
Or does the included JavaAppLauncher replaces the normal java binary?
The app bundle does not call a 'java' command. Some combination of JavaAppLauncher and libjli.dylib invokes Java dynamically.
If you are unsure if it is using the bundled version of Java, output this when your app runs. It will tell you from what location Java is being called:
System.getProperty("java.home", "")

Run a jar file without JDK installed

is there any way to run a jar file without JDK installed ?
for example convert jar file to exe or put the jdk or jre into the jar file or something like this...
JRE is a must. JDK is not a necessity.

Categories