How to set Eclipse Java version in OS X - java

When I download and expand Eclipse EE version a file of type Application is created :
I'm new to using to Eclipse on MAC. I want to set the java version to
export JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"
But no eclipse.ini file is created. How to set and or install Eclipse on MAC and set the java version ?

This solution allows you to specify the JVM for a given eclipse installation, without changing any system properties. Make sure you have a valid JVM (usually JDK 8 for eclipse) installed.
Here are the steps:
open finder and navigate to the location of Eclipse (i.e. Applications)
right-click on the eclipse application
select "show package contents"
navigate to /content/Eclipse/eclipse.ini
open the .ini with a text-editor
at the top of the file, add the following lines (or replace the existing -vm line)
-vm
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin
You need to replace adoptopenjdk-8.jdk with the name of your JVM.

File type "Application" is actually a directory. Right-click it (or control click) and select "Show Package Contents". You should find eclipse.ini at Contents/MacOS/eclipse.ini inside the Eclipse application directory.

You need to install the full JDK rather than the JRE before you can use it with Eclipse. The full JDK should set itself as the current Java. The JDK installs in something like /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home
As mentioned in the other answer the Eclipse application is actually a directory (called Eclipse.app) using 'Show Package Contents' in Finder will show you the contents.

Related

Getting "Error: JAVA_HOME not found in your environment" when attempting to create a new Maven project in VSCode

I'm attempting to generate a Maven project via VSCode's Maven for Java extension.
Here's my issue: After I click "Create new Maven Project" in the Explorer, choose the quickstart option, and choose the folder I want to work in, I am given an error in terminal which reads as follows:
Error: JAVA_HOME not found in your environment.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Currently, my JAVA_HOME system variable is set as C:\Progra~1\Java\jdk1.8.0_271.
Any suggestions for how to make this error go away? I'm not sure if it matters, but my JDK is installed on my C drive and I am attempting to create a project on my M drive.
Thanks!
1.Add java to PATH:
Control Panel-> System-> Advanced system settings-> Environment
Variables:
Under User variables, Choose Path, click New:
Copy the path of the JDK bin directory.
Open Command Prompt, and run java --version. If there's no error
shown and you get the right jdk information, turn to the next step;
2.Install Java Extension Pack in VS Code;
3.Press Ctrl+Shift+P to open Command Platte and choose Java: Configure Java Runtime:
Turn to Java Tooling Runtime and select your installed jdk, JDK
for Language Server is equivalent to java.home:
Then reload VS Code to make change effective.
The solution to this problem was setting both a user Path variable and a new system variable "JAVA_HOME" specifically to the address of the bin folder of my Java 11 installation.
In my case the path looked like this:
C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot\bin
I have a hunch that my issue may have related to the fact that I have two JDKs installed- one for Java 8 and one for Java 11- but I'm not sure.
Thank you to those who helped!
I have manage to configure this entirely through Visual Studio Code. Using the reference for the Maven extension: https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven
I set my Java home path in Visual Studio Code, like this (inside of settings.json):
"java.home": "C:\\Program Files\\Java\\jdk-9.0.4"
And then you can enable Maven to use the same path with the settings below:
"maven.terminal.useJavaHome": true

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.

Eclipse package explorer error in a web application project

I am following a tutorial by Google on "google app engine using java" and trying to make a simple web application. But I am having problem to make a JSP file in the war directory. This is the tutorial page: https://developers.google.com/appengine/docs/java/gettingstarted/usingjsps
I am using eclipse. When I create a new JSP file in the war directory, it causes an error in the package explorar. The error is:"Your project must be configured to use a JDK in order to use JSPs"
How can I get rid from this error?
In Window - Preferences - Java - Installed JREs, make sure you have a JDK installed, and select it as the default.
First thing, go into Window>Preferences>Installed JREs and sellect a JDK's JRE.
Them add this line to eclipse.ini:
-vm C:\Program Files\Java\jdk1.7.0_45\bin\javaw.exe
That line must be in the beginning of the file, before any -vmargs argument, or else Eclipse will crash on start.
Last go into your System's environment variables and add "C:\Program Files\Java\jdk1.7.0_45\bin" to the PATH variable, before the "%SystemRoot%\system32" entry.
Those three entries must all point to the same JDK and, of course, must be changed to whatever your JDK's path actually is.
Restart your Eclipse and you should be good to go.

Eclipse not detecting the installed java

I had installed Eclipse Galileo first and after that installed Java.
But it is not detecting my java.
What configuration changes can I make so that Eclipse can run my java programs?
========================== Edited ================================
You can specify the exact jvm you want to use through:
a -vm argument
directly within the eclipse.ini
Once started, you can reference as many JVM you need in the Installed JRE preference panel
alt text http://img168.imageshack.us/img168/3307/eclipseinstalledjre2.png
Finally, you need to reference the JVM you need in the Libraries tab, in your Java Build Path properties of your Java project (as mentioned by Steve in his answer):
alt text http://img52.imageshack.us/img52/5947/eclipseinstalledjre3.png
It seems, that your project doesn't have the JVM in it's Build Path.
Right-Click on your project. Choose Build Path --> Add Libraries.... Take JRE System Library and choose a JVM for your project.

How to change JAVA.HOME for Eclipse/ANT

I am trying to sign a jar file using an ANT script. I know this has to be pointed at the JDK directory for jarsigner.exe to run, but when I echo java.home it returns the JRE directory.
This isn't a problem for javac, because I can set the executable path. But, that does not exist for signjar.
How do I change the java.home path? When I right-click on MyComputer and go to:
Properties > Advanced > Environment Variables
The "PATH" variable is correctly pointed to the JDK (C:\program files\java\jdk\bin).
Update: The file now signs correctly after changing the PATH variable suggested below.
In Eclipse the Ant java.home variable is not based on the Windows JAVA_HOME environment variable. Instead it is set to the home directory of the project's JRE.
To change the default JRE (e.g. change it to a JDK) you can go to Windows->Preferences... and choose Java->Installed JREs.
To change just a single project's JRE you can go to Project->Properties and choose Java Build Path and choose the Libraries tab. Find the JRE System Library and click it, then choose Edit and choose the JRE (or JDK) that you want.
If that doesn't work then when running the build file you can choose Run as->Ant Build... and click the JRE tab, choose separate JRE and specify the JRE you want there.
For me, ant apparently refuses to listen to any configuration for eclipse default, project JDK, and the suggestion of "Ant Home Entries" just didn't have traction - there was nothing there referring to JDK.
However, this works:
Menu "Run" -> "External Tools" -> "External Tools Configuration".
Goto the node "Ant build", choose the ant buildfile in question.
Choose tab "JRE".
Select e.g. "Run in same JRE as workspace", or whatever you want.
Under Windows you need to follow:
Start -> Control Panel -> System -> Advanced -> Environment Variables.
... and you need to set JAVA_HOME (which is distinct from the PATH variable you mention) to reference the JDK home directory, not the bin sub-directory; e.g. "C:\program files\java\jdk".
Simply, to enforce JAVA version to Ant in Eclipse:
Use RunAs option on Ant file then select External Tool Configuration in JRE tab define your JDK/JRE version you want to use.
Also be sure to set your JAVA_HOME environment variable. In fact, I usually set the JAVA_HOME, then prepend the string "%JAVA_HOME%\bin" to the system's PATH environment variable so that if Java ever gets upgraded or changed, only the JAVA_HOME variable will need to be changed.
And make sure that you close any command prompt windows or open applications that may read your environment variables, as changes to environment variables are normally not noticed until an application is re-launched.
In addition to verifying that the executables are in your path, you should also make sure that Ant can find tools.jar in your JDK. The easiest way to fix this is to add the tools.jar to the Ant classpath:
If you are using Eclipse, try the following:
Right click on the ant build file, then choose "Properties".
Click on the "Run/Debug Settings", then click on the launch configuration file. You should be able to edit it then.
After you click "Edit", you should see a new window with a "Properties" tab which will show you a list of Ant build properties. There is a "java.home" property in the list. Make sure it refers to the correct path.
Spent a few hours facing this issue this morning. I am likely to be the least technical person on these forums. Like the requester, I endured every reminder to set %JAVA_HOME%, biting my tongue each time I saw this non luminary advice. Finally I pondered whether my laptop's JRE was versions ahead of my JDK (as JREs are regularly updated automatically) and I installed the latest JDK. The difference was minor, emanating from a matter of weeks of different versions. I started with this error on jdk v 1.0865. The JRE was 1.0866. After installation, I had jdk v1.0874 and the equivalent JRE. At that point, I directed the Eclipse JRE to focus on my JDK and all was well. My println of java.home even reflected the correct JRE.
So much feedback repeated the wrong responses. I would strongly request that people read the feedback from others to avoid useless redundancy. Take care all, SG
Go to Environment variable and add
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_37
till jdk path (exclude bin folder)
now set JAVA_HOME into path as PATH=%JAVA_HOME%\bin;
This will set java path to all the applications which are using java.
For ANT use,
ANT_HOME=C:\Program Files (x86)\apache-ant-1.8.2\bin;
and include ANT_HOME into PATH, so path will look like PATH=%JAVA_HOME%\bin;%ANT_HOME%;
Set environment variables
This is the part that I always forget. Because you’re installing Ant by hand, you also need to deal with setting environment variables by hand.
For Windows XP: To set environment variables on Windows XP, right click on My Computer and select Properties. Then go to the Advanced tab and click the Environment Variables button at the bottom.
For Windows 7: To set environment variables on Windows 7, right click on Computer and select Properties. Click on Advanced System Settings and click the Environment Variables button at the bottom.
The dialog for both Windows XP and Windows 7 is the same. Make sure you’re only working on system variables and not user variables.
The only environment variable that you absolutely need is JAVA_HOME, which tells Ant the location of your JRE. If you’ve installed the JDK, this is likely c:\Program Files\Java\jdk1.x.x\jre on Windows XP and c:\Program Files(x86)\Java\jdk1.x.x\jre on Windows 7. You’ll note that both have spaces in their paths, which causes a problem. You need to use the mangled name[3] instead of the complete name. So for Windows XP, use C:\Progra~1\Java\jdk1.x.x\jre and for Windows 7, use C:\Progra~2\Java\jdk1.6.0_26\jre if it’s installed in the Program Files(x86) folder (otherwise use the same as Windows XP).
That alone is enough to get Ant to work, but for convenience, it’s a good idea to add the Ant binary path to the PATH variable. This variable is a semicolon-delimited list of directories to search for executables. To be able to run ant in any directory, Windows needs to know both the location for the ant binary and for the java binary. You’ll need to add both of these to the end of the PATH variable. For Windows XP, you’ll likely add something like this:
;c:\java\ant\bin;C:\Progra~1\Java\jdk1.x.x\jre\bin
For Windows 7, it will look something like this:
;c:\java\ant\bin;C:\Progra~2\Java\jdk1.x.x\jre\bin
Done
Once you’ve done that and applied the changes, you’ll need to open a new command prompt to see if the variables are set properly. You should be able to simply run ant and see something like this:
Buildfile: build.xml does not exist!
Build failed

Categories