How do I specify the Java virtual machine for Eclipse? - java

Millions of programmers have been able to do this; is there something so obvious as the nose on my face, which I'm missing here?
I've been using TextPad with Java for a dozen years. Everytime Windows changes versions, I have to reinstall them. Somehow, TextPad finds Java and I'm all set.
I don't know about PATH or environment variables (maybe this is the thing everyone else knows and I don't).
Anyway, I downloaded eclipse 1.7 and copied the files from the ZIP into C:\eclipse on my Windows 7 (64-bit version) machine. There are NO INSTALLATION INSTRUCTIONS in the download or at eclipse.org!
What am I supposed to put on a command line (for a batch file) on in the eclipse.ini file to allow Eclipse to find the Java virtual machine?
The location of javaw.exe
The path of jvm.ell
... or what?
=> Tell me how, and I'll make a web page dedicated to this!!!

How about http://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F ?

Normally with a properly installed JRE, Eclipse will just run because the javaw.exe and java.exe proxies are added to your windows folder which is always in the path. But alternatively you can make eclipse use any other JRE/JDK by editing the eclipse.ini file and adding the following lines at the top of the file:
-vm
<path to jdk or jre>

Windows > Preferences > Java > Installed JREs lets you configure any number of JREs.
The online doc (accessible from Help > Help contents or on the web) explains this and all other settings.
Hope that helps.

Related

Error occurred when running with Windows power shell. A JNI error has occurred, please check your installation and try again

I am getting "A JNI error has occurred, please check your installation and try again" error Whenever I'm running my java jar using "java -jar filename.jar" command with windows power shell. It works fine whenever I opens it with double click.
How Can I resolve this issue?
Thanks in advance.
You say it works when you double click the JAR file (in File Explorer) but not when you run it from the PowerShell window in this folder:
C:\incubating-netbeans-11.0-bin\netbeans\ani\Tank-IQ-Display-Configurator\Tank-IQ-Display-Configurator\dist
I'm guessing you have more than one JDK installed.
If you enter the following command in the PowerShell window, it will display the paths to all the java.exe files.
where.exe java
Windows associates file extensions with executables. Obviously, on your computer, the .jar extension is associated with java.exe. You can check this via Control Panel. Look for Default Apps. Hence when you double click the JAR in File Explorer the associated executable is launched.
I'm guessing that the default executable is that of JDK 11 and that either in the folder whose path I wrote above there is a java.exe that is compatible with JDK 8 or in your PATH environment variable, the path to the JDK 8 executable comes before the path to JDK 11 executable.
So check those things, i.e.
Default apps in Windows
PATH environment variable
Obviously there are many different ways to rectify the situation. I don't think any one is clearly superior and the most appropriate would depend on your environment and your needs which I am unaware of since you haven't provided those details, hence I won't suggest what actions you should take in order to resolve your issue.
What you do need to do is ensure that a JAR file containing java code that was compiled to JDK 11 is run with a java.exe from at least JDK 11.
Note that higher java versions can run classes compiled to lower versions. In other words, if your JAR was compiled to JDK 8, you could run it with JDK 11, but not the other way around (which is the cause of your error, as others have indicated).
As it says quite clearly in the error message, your JRE is too old. Install a newer JRE (and update your PATH and JAVA_HOME).
Also, please do not post error messages as screenshots when you could also paste them as text.

Executable jar not working on other computers

I've created a program using Eclipse and exported as an executable jar (I've tried all 3 library handling options). It runs perfectly on the computer it was written and exported on, but when I try and run it on other machines it does nothing at all. It brings up no errors, nothing at all. I've got several people to try it for my with no luck, and I've tried running it on my laptop (ensuring that Java is the latest version, the same as the machine that it was written on). The MANIFEST file points to the Main class correctly.
Does anyone know how I can solve this issue?
It's incredibly frustrating!
If any more info is needed, I can supply it.
That happened to me a lot of times when I started writing java distributed applications.
Check your project build path (since you're using eclipse, right-button click on your project's folder, then Build Path > Configure Build Path). If any of the paths that are specified there are custom *ie C:\User\daMachineMaster\Java\jre\bin or whatever, it won't work on any other machine because the application will always look for that path, which won't exist in no other machine than daMachineMaster's computer. You could use a wrapper to fix this issue, since it encapsulates all needed information in a .exe, for example.
If that still isn't your issue, search your code for any links to your local directories. For example,
String style = main.screens.ScreenFramework.class.getResource("C:\Users\Dwayne\Music\cool\DarkTheme.css");
After you've located these kinds of hard links, the solution is changing them to be relative links. Check How to define a relative path in java
In the above case, it would mean changing to something like:
String style = main.screens.ScreenFramework.class.getResource("DarkTheme.css").toExternalForm();
Also, as mentioned in other answers, check if the other computers hava java installed. I don't think that they need any environment variables defined to run a runnable jar but if you want to run your app in the cmdline with something like java -jar yourapp.jarthen you need to go to the windows explorer (assuming you're using windows), right-click Computer, then click Advanced System Settings > Environment Variables > New... > Variable Name = JAVA_HOME; Variable Value = directory where java is installed > OK > Click on PATH > Edit... > add JAVA_HOME\bin to PATH > OK
When the Java Runtime Environment (JRE) is not installed, the JAR won't be open and won't show you any message. Try installing JRE into the other computer and try again.
You need to install a Java Runtime Environment (JRE) first, then you can directly run the .jar files on your computer. The Java Development Kit (JDK) download package contains it's corresponding JRE, so that's fine to install too.
Sorry for the late reply. Thanks for all your answers, but it turned out there was an error in my code that simply stopped it running without showing any errors.
I got this problem several times. The issue was the jar file runs on the computer where I have packaged. But in another computer it is not running, some time it shows running if I check the javaw.exe process in cmd but nothing is served.
The solution here is to make sure the following are set correctly.
Make sure the version of java in another computer match the jar file. In some case if you defined java16 in the pom file, make sure the computer has java16 or higher installed and the JAVA_HOME environment is set correct to point to this version.
Make sure the dependent variables are set correctly. For example if the package depends on database driver or database connection consider installing and creating database
For me it worked after changing the java version in the pom file to the oddest ie.the second computer use java 16 then packaged jar file to use java 11.

How to open/run .jar file (double-click not working)?

I can't open or run my .jar file.
I just installed java, but I tried to open the .jar with other programs first, so the double-click defaults to something else and I can't change it back.
java -jar myfile.jar`
Above command returns:
'java' is not recognized as an internal or external command, operable program or batch file.
Is there a way I can still open/run this?
e: OS is Windows 8.
Also, I downloaded the .jar file; didn't create it myself (if that's relevant)
Not sure if it contains an executable (but I think it does).
you can use the command prompt:
javaw.exe -jar yourfile.jar
Hope it works for you.
There are two different types of Java to download: The JDK, which is used to write Java programs, and the RE (runtime environment), which is used to actually run Java programs. Are you sure that you installed the RE instead of the SDK?
Use cmd prompt and type
java -jar exapmple.jar
To run your jar file.
for more information refer to this link it describes how to properly open the jar file.
https://superuser.com/questions/745112/how-do-i-run-a-jar-file-without-installing-java
You may have several JDKs installed in your PC. Some older JDK installers also copy some java files such as java.exe, javaw.exe into C:\Windows\System32 folder.
I had a similar issue, and searched the internet for a solution and none of the suggestions didn’t open by double clicking the .jar file.
In my case the reason is I have multiple JDK & JRE versions installed on my computer. Since I am a software developer working with several different versions for different clients I need to use multiple JDKs in my PC (Windows 10 Pro). So I do not want to change the system variables (i.e. JAVA_HOME, JRE_HOME or PATH), instead I use command prompt to run java in user process whenever I wanted to use a different version.
When installing JDK it registers the .jar file association with latest version we installed in the PC. If you right click on the .jar icon and select properties, it will show that file opens with “Java(TM) Platform SE Binary”. If we look at the registry key: HKEY_CLASSES_ROOT\jarfile\shell\open\command, it will point to latest JDK version.
It is not a good idea (sometimes annoying) to change the registry key every time I want to run an app build from a different version.
So in my situation it is impossible to just double click the .jar file to execute it. But instead I found a work around solution myself.
Scenario:
Multiple JDKs (1.7, 1.8, 9.0, 10.0, 11.0, and 12.0)are installed in the PC, so the latest installed was 12.0.
Problem
Want to double click an executable .jar developed using JDK 1.8 and didn’t work
This is my work around solution:
Create a shortcut for the .jar file that you want to open.
Right click the shortcut icon and select properties -> Shortcut tab
Change the text in the target (for example "D:\Dev\JavaApp1.8.jar")
To
"C:\Program Files\Java\jdk1.8.0\bin\javaw.exe" -jar
"D:\Dev\JavaApp1.8.jar"
Then click ok Double click the shortcut.
It should now open the app.
I was having this same issue for both Windows 8 and Windows Server 2012 configurations.
I had installed the latest version of JDK Java 7 and had set my **JAVA_HOME**system env variable to the jre folder: *C:\Program Files (x86)\Java\jre7*
I also added the bin folder to my **Path** system env variable: *%JAVA_HOME%\bin*
But I was still having problems with double clicking the executable jar files. I found another system env variable OPENDS_JAVA_ARGS that can be used to set the optional properties for javaw.exe. So I added this variable and set it to: -jar
Now I am able to run the executable jar files when double clicking them.
In cmd you can use the following:
c:\your directory\your folder\build>java -jar yourFile.jar
However, you need to create you .jar file on your project if you use Netbeans. How just go to Run ->Clean and Build Project(your project name)
Also make sure you project properties Build->Packing has a yourFile.jar
and check Build JAR after Compiling
check Copy Depentent Libraries
Warning: Make sure your Environmental variables for Java are properly set.
Old way to compile and run a Java File from the command prompt (cmd)
Compiling: c:\>javac Myclass.java
Running: c:\>java com.myPackage.Myclass
I hope this info help.
Go to your java directory,
Copy this path
C:\Program Files\Java\jdk1.8.0_40\bin
Right click on my computer , click properties, then go to "Advanced system settings"
click , Environment variables.
go to "System variables" table, find an entry named "path".
Double click it and go to the end, put a semicolon and paste your path, apply and ok.
It should run now.
first of all, we have to make sure that you have downloaded and installed the JDK.
In order to download it click on the following link
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
(Do not forget to check "Accept License Agreement", before you choose the version you want to download)
For Windows OS 32-Bit (x86) choose "jdk-8u77-windows-i586.exe"
For Windows OS 64-Bit (x64) choose "jdk-8u77-windows-x64.exe"
Install the file that is going to be downloaded. During the installation, pay attention, because you have to keep the installation path.
When you have done so, the last thing to do, is to define two "Environment Variables".
The first "Environmental Variable" name should be:
JAVA_HOME
and its value should be the installation path
(for example: C:\Program Files\Java\jdk1.8.0_77)
The second "Environmental Variable" name should be:
JRE_HOME and its value should be the installation path
(for example C:\Program Files\Java\jre8)
As soon as you have defined the Environment Variables, you can go to command prompt (cdm) and run from every path your preferred "java.exe" commands. Your command line can now recognize your "java.exe" commands.
:)
P.S.: In order to define "Environment Variable", make a right click on "This PC" and select "properties" from the menu. Then the "System" window will appear and you have to click on "Advanced system settings". As a consequence "System properties" window shows. Select the "Advanced" tab and click on "Environment Variables" button. You can now define the aforementioned variables and you're done
You must create a manifest file and specify your class that has the main method. you can build your jar file with manifest file as a parameter.
jar cfm MyJar.jar Manifest.txt MyPackage/*.class
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Cakes
Build-Jdk: 1.6.0_04
Main-Class: com.foo.App
An easy way to execute .jar files is to create a batch file.
Let's say you placed your jar file on your Desktop;
#echo OFF
java -jar C:\Users\YourName\Desktop\myjar.jar
Copy this code to a .txt file, modify "YourName" and save as "myjar.bat". Then whenever you double click, the jar file will be executed.
Hope this helps.
Short trick: after I only REMOVED SPACES from names of the folders, where the .jar file was, double-clicked worked and the file executed.
In Netbeans please delete current you create the jar file and on the project explore of Netbeans please clean and build 2 or 3 times and right the project folder in project explore and build the jar file.
I had this problem a while back and the solution was really easy.
Just uninstall the current version of Java, download an older one, then uninstall the older and install the latest again.
For example: Java 8 Update 73 current install Java 7 Update 95.
How it works: Java's registry keys were messed up, and when you install the older version they get fixed.
If the intention of the question is to view the contents of the JAR file, then the following java command would help.. (provided, JDK location is added to the environment variables.)
Windows Command prompt> jar tvf yourJarFile.jar
Example:
jar tvf log4j-extras-1.2.17.jar
Reference: http://docs.oracle.com/javase/tutorial/deployment/jar/view.html
I downloaded the latest JDK 7u10. Once you do that, try running your jar, It should execute.

java name of folder in which java is installed

Hi is there a chance to find where is java installed on windows ?? Becouse my application use JCE but not all algoritms are installed and I have to download some files
like its writen here.
Edit:
Another question, how to check if JCE is istall and contains such algotitm (DES) ??
It is typically installed under c:\Program Files\Java\{JRE Release)
Otherwise you can find the JDK home if it is installed by the JAVA_HOME environment variable.
Somewhere around C:\Program Files\Java\jre6.
Depending on your system privileges, you may be able to look at your environment variables. From what I understand, the bin folder of your JRE installation should be included in your PATH variable.
You can print this out by typing path into a command line ,
or you can find it by right clicking on my computer, and going to properties. Under the Advanced tab, you should see an environment variables button, and your PATH will be in the bottom list.

JSmooth question on bundling a JRE

I'm trying to bundle a JRE with my jar file so that I can run my application on any windows computer, regardless of if it has Java or not. The jsmooth manual says:
For the option to work correctly, you have to put a JRE in a directory near the EXE (generally in a subdirectory called "jre" or whatever). Once the exe is generated, it will FIRST try to locate the JRE at the location mentioned. If it can't be found there, then it will fallback in the normal jre look-up mode (search for a jre or a jdk in the Windows registry or in commonly-used environment variables). There is no JVM-version check when using a bundled JRE, as the packager is supposed to bundle a suitable JVM for the application.
Does this mean that the jre subfolder should be included in the jar, be its own separate jar, or put in the folder that comes along with the exe? If it is supposed to be in a folder with the exe, how can I specify the relative path to the jre subfolder?
My directories are as follows:
setup/
-jre/
-myprogram.exe
I tried using ..\jre, .\jre, ..\setup\jre in the GUI screen, but none of them worked.
Any ideas or leads would be greatly appreciated. Thanks so much!
EDIT: when I tried jre (and ..\jre I think), I got the following error message from windows when I tried running it "MyProgram.exe has stopped running." When I look at the problem details, it says APPCRASH and the fault module name is jvm.dll
just put the "jre" folder next to the exe, and write "jre" (without quotes) in the GUI of jsmooth
As an alternative, I would suggest using the mature open source project, NSIS. You could write an installer that would download and install the JRE, and then create shortcuts to run your program.
Here are some useful links:
http://nsis.sourceforge.net/Simple_Java_Runtime_Download_Script
http://nsis.sourceforge.net/Java_Launcher
Have you tried Launch4J (http://launch4j.sourceforge.net/), we switched from JSmooth to this a while ago, as it was more up to date and had more features.
But, put the jre folder in the same folder as the .exe, then use jre\ as the path to it. You'll need to make sure the working folder of the .exe is the installation folder though. And make sure you have a full JRE in the jre folder.

Categories