Jar before jre - java classpath - java

is there a way to run java and tell it to use a certain jar higher in the classpath than the jre?
I know it is possible in eclipse run configuration, but I want it to work using java from command line.
The reason is that there is a class that is loaded from the jre and I wanted a different version that should have been loaded from an external jar. I saw this was the case using -verbose.
Thank you

try this Java arg
-Xbootclasspath/p:my.jar

Related

Cannot add java 11 jre in STS version 4.5.0

I am trying to migrate my Springboot projects from Java 8 to Java 11 although I'm having issues first on updating the installed jre of my STS. Since java 11 doesn't have any separate jre, unlike the previous versions, I was trying to include the jdk 11. Although as you can see on the bottom photo, it does not seem to locate the jrt-fs.jar file.
I've also tried to configure the SpringToolSuite4.ini file by including these lines:
-vm
C:\Program Files\Java\jdk-11.0.7\bin\javaw.exe
This is how my .ini file looks like:
Although nothing still happens. Anyone who has other pieces of advice on where I should check? Thank you in advance!
In the preference for configuring the JREs you should select the JDK folder itself, not the lib nor the bin folder. Eclipse will find all the necessary files and libraries that are included in that JDK and can deal with JDKs >= 11.
Please note that this preference is different from the VM that you specify in your ini file. The VM in the ini file is used to run the IDE itself, not to compile your projects against or run them. It is a totally separate thing, which allows you to run your IDE on JDK11 (for example), whereas at the same time you can implement and run projects on JDK8 or JDK14 (or whatever).
You are adding the lib/ dir instead of bin/.
Don't forget to add bin/ to the %Path% environment variable.
Make sure you don't have duplicates from earlier versions of the jdk/jre.
Sorry, you are adding the jdk instead of the jre that is expected:
https://www.java.com/de/download/help/download_options.xml

JAR file does not load class files from ext

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?

Missing libraries with oracle-java7-jdk in eclipse on ubuntu 12.04

I recently installed the ubuntu 12.04 final beta
After installing the oracle jdk from the webupd8 ppa, launching eclipse failed complaining about a missing shared library.
Can't load library: /home/bob/.swt/lib/linux/x86_64/libswt-gtk-3740.so
I searched around, and found this quesion: Eclipse cannot load SWT libraries
As the OP recommended, I tried switching to open-jdk, and that worked wonderfully. The problem, however, is that I am working on a project that doesn't support openjdk.
I tried the second solution as well (the one by scott, which was just creating symbolic links to /usr/lib/jni/... in ~/.swt/lib/linux/x86_64/). Eclipse launches and everything is fine, but it still misses some libraries; this is what I get when i try to run my project:
Caused by: java.lang.UnsatisfiedLinkError: /tmp/libgdx/1352105074/libjogl_awt-linux64.so: libjawt.so: cannot open shared object file: No such file or directory
I know libjawt.so is somewhere on my computer:
$ locate libjawt.so
/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/amd64/libjawt.so
/usr/lib/jvm/java-7-oracle/jre/lib/amd64/libjawt.so
But eclipse or java seems to think that libraries should be placed in ~/.swt/lib/linux/x86_64, isn't that weird?
Eclipse when launched defaults to its own internal JRE, as I understand. I recommend the following:
Modify your CLASSPATH variable to include the path to the desired libraries;
Set your JAVA_HOME to match the actual JAVA_HOME;
Setup Eclipse to launch from the desired JVM by customizing the eclipse.ini using this information: http://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F#eclipse.ini
Also, can you specify the -classpath option when Eclipse is launched?
Try downloading the latest version of Eclipse and running it. For some reason it works fine. I just ditched my older version of Eclipse. I hope this works for others!
Please note that there are two Java runtimes in play here. The one used to run Eclipse itself, and the one you want to run your code. They do not have to be the same!
I would suggest
Run Eclipse with a JDK that works
Download Oracle JDK manually and unzip it to a folder in your home directory
Tell Eclipse about this additional runtime (http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-add_new_jre.htm)
Configure your project to use that JVM instead. (http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-assign_default_jre.htm)
Now your own code is compiled against, and runs with Oracle Java.

Do I need to install Java SDK if I have eclipse

I have been using Eclipse for 2 weeks and all programs are working fine.
But I have realized that I have not specifically installed Java SDK.
Is it normal or does Eclipse have its own compiler?
I need to test the JDBC MySQL connector and now I don't know where to copy that file because in my:
C:/programfiles/java
I have only one directory that is JRE 6.
Yes you're right. Eclipse has its own compiler so you don't need JDK if you are working with Eclipse.
There is some cases/plugins that are only working with JDK such as Maven. So if you are planning to use Maven (either from Console or from Eclipse) you will need to download JDK.
For your mysql connector, a common practice is to copy the jar to your project directory (or maybe under lib directory) and add it to the build path. Once the jar is in the location, you can refresh the workspace, right click, and select Build Path, add to Build Path.
You can download Eclipse with a bundled JRE, which is probably what you've done. But since it has its own compiler etc, it doesn't need the full JDK.
You don't need the JDK to use the mysql driver, though, you just need to add it to your project classpath in Eclipse. Some documentation suggests putting JAR files in the JRE/JDK's extensions directory, but this is a profoundly bad and outdated idea - don't do that. Use the classpath, via Eclipse's environment.
Eclipse has its own compiler and can run on a non-JDK JRE.
The usual approach to use a library jar, is to copy it into your Eclipse project inside Eclipse, and right-click-add it to the Build Path. The classes are then accessible to your own code.

JRE version enough to run a jar

What is the smallest version of JRE to run a simple jar that calls other jars while running ?
That depends completely on what parts of the Standard API and what class file version the classes in that JAR (and the ones it calls) are using.

Categories