Why do i need to use batch files to run java programs? - java

I have bothe that java 1.7 JDK installed and the Java 1.7 JRE installed and for some reason, i can use the JDK in eclipse but if i am going to run any java program then i am forced to use a batch file. My path is: "C:\Program Files\Java\jdk1.7.0_51\bin\javaw.exe\" but for some reason the jre inside is not registering

Related

How to run (exe) java-8 application in java-11

I have made a java application using jdk 8 and then made an executable file from the jar.
Then I updated my system to java 11, and deleted all older java versions from my system, and when I run this app from exe file it can't run and takes me to web browser and asks me to download java 8. But if I run the jar using java -jar app.jar it runs normally on java 11.
I've used launch4j to make an exe out of jar, and there is no possibility to pick java 11 as the newest version.
So how can I make this exe run on java 11?
Unless you have compiled EXE with latest launch4j 3.12 you are most likely stuck on Java 8. Support for newer JDK was added in ticket #177 Launch4J doesn't accept Java 9 JDK.
The solution would be to recompile EXE with latest launch4j and hope it works with Java 11. Alternatively you could create a BAT file running java -jar app.jar but that goes against the whole point of launch4j.

How do I check that my Java application will run on a machine with JRE 1.6/1.7?

I have a few applications that I am giving to my colleagues on customer support. I made all of these applications using JRE 1.8, and most of the machines that are being used are using a JRE of 1.6 or 1.7. I have refactored the code so that it will work with these versions of Java.
However, how am I supposed to test that these applications will in fact run on a machine with these versions of Java installed? Do I have to use another computer? Is there any way of testing this from my own PC?
I'm using launch4j to create an .exe file that will run the application (they're just tools to help some troubleshooting processes)
Just to try be more clear, I have the latest version of Java installed on my PC, and I want to test that PCs with Java 1.6/1.7 will still run the .exe file generated from launch4j; so how do I do this on my own PC?
In your IDE (for example eclipse) you can change the project properties
for the java compiler "Compiler compliance level" from 1.8 to 1.6. Then
build the new code.
(By the way, if you like to support Java 1.6 you should only compile with
this compliance level)
If you have still installed old Java-JRE-Versions on your
PC you can set JAVA_HOME environment to the JRE 1.6 folder
(Checks %PATH% too and rename your java 8 JDE and java 8 JRE folder
temporaerly for safety).

Get JRE version from System Property

It's not a duplicate. I would like to get current JRE version while program is executing.
To test result I've installed JDK 8.91 (without JRE 8.91 installation) and JRE 8.77. Also I've created JRE_HOME, JAVA_HOME variables, excluded Path variable with JDK folder.
My Tomcat uses JRE so I would like to get current JRE version before I will launch it. I found solution like:
System.getProperty("java.version")
After executing
System.out.println(System.getProperty("java.version"))
I get result 1.8.0_91 Instead of 1.8.0_77, which I wanted to get.
However, Oracle documentation gives the definition that this is JRE version.
Link:http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/System.html#getProperty%28java.lang.String%29
How can I fix it?
When you run a Java program, it always runs on a JRE (Java Runtime Environment). You cannot run a program on the JDK directly.
When you install Oracle's JDK, a JRE is included, you can find it in the jre directory in the JDK installation directory.
When you install Oracle's JDK, you get an option to install a "public JRE". This is a JRE that is installed separately from the JDK itself, and is used by browser plug-ins. You need this only if you want to be able to run Java applets in your browser.

How to force a jar to run in java 7?

I made a Runnable Jar that will run as service in windows, but the final pc that will execute him, has 3 versions of java installed, 1.3, 1.6 and 1.7, and my jar needs to be executed with 1.7, because him uses classes that are present only in 1.7+ version, o don't know how are configured the environiment variables, my question is:
Is possible to force my code to run in java 1.7?
You can also do this without persistently resetting your path environments. Just use the absolute path to your jre/jdk instead of typing "java": e.g.: "C:\Program Files\Java\jre7\bin"\java -jar foo.jar, same goes for MacOS and Linux.
Set your JAVA_HOME and PATH environment variable to point to the Java 7 directory.
See https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them to know how to do it.
Rather than setting path/classpath at top level, you should create a
batch file and set path/classpath there.
Then command to run your jar.

Change the Java version Eclipse is running under

I want to run my Eclipse in a newer Java version (jdk 1.7) because of compatibility problems with the Window Builder Plugin
"Eclipse is running under 1.6, but this Java project has a 1.7 Java compliance level, so will not be able to load classes from this project. Use a lower level of Java for the project, or run Eclipse using a newer Java version."
So I suppose, I've to change the vm of Eclipse in the configurations.
-vm
C:\Program Files (x86)\Java\jre6\bin\client\jvm.dll
eclipse.home.location=file:/C:/Program Files (x86)/Eclipse IDE for Java EE Developers/
eclipse.launcher=C:\Program Files (x86)\Eclipse IDE for Java EE Developers\eclipse.exe
eclipse.launcher.name=Eclipse
eclipse.p2.data.area=#config.dir/../p2/
eclipse.p2.profile=epp.package.jee
eclipse.product=org.eclipse.epp.package.jee.product
eclipse.startTime=1351770082498
eclipse.vm=C:\Program Files (x86)\Java\jre6\bin\client\jvm.dll
eclipse.vmargs=-Dosgi.requiredJavaVersion=1.5
But I'm not realy familiar with all the statements, and my question is which ones do I've to change in order to run Eclipse with jdk 1.7?
Edit the eclipse.ini file to point -vm to JDK 7

Categories

Resources