Starting eclipse with configured JVM from windows batch file - java

I have problems to start eclipse with a proper configured JVM from windows batch file.
I like to do it this way, because I have different workspaces, different eclipse versions, different java versions and different configurations.
I guess the problem is the way I pass the parameters. I have tried several combinations of setting '"', but none worked. Below is just one example.
Anyway, can someone help?
Thanks :-)
Afterwards added:
Sorry, I forgot - the problem is the parameters for the JVM are neglected
#echo off
ver
echo.
set thePathToJDK=C:\Program Files\AdoptOpenJDK\jdk-11.0.10x9-hotspot
rem to be checked - is JAVA_HOME needed by anyone ?
rem eclipse states that is neglecting JAVA_HOME
set JAVA_HOME=%thePathToJDK%
rem set path to vm ( shall be in harmony with path to JDK )
set thePathToJVM=%thePathToJDK%\bin\javaw
set thePathToEclipse=C:\eclipse\ ...
set thePathToEclipseWorkSpace=C:\ ...
rem set minimal path (for ECLIPSE/JAVA)
set theNewPath=%SystemRoot%\system32
set theNewPath=%theNewPath%;%SystemRoot%
set theNewPath=%theNewPath%;%SystemRoot%\System32\Wbem
set theNewPath=%theNewPath%;%SystemRoot%\System32\WindowsPowerShell\v1.0\
set path=%thePathToJDK%\bin;%theNewPath%
echo.
echo path used for ECLIPSE
echo %path%
set theCommand=%thePathToEclipse%\eclipse.exe -data "%thePathToEclipseWorkSpace%" -vm "%thePathToJVM%" -vmargs -ea -Xmx4096m -Xss256m
echo.
echo %theCommand%
rem start eclipse with preconfigured Java
cmd /c %theCommand%
pause

On Windows, you need to include the .exe part of the VM's file name when you're using -vm with a file rather than a folder.

As #greg-449 pointed out, "the parameters" only change the Java that Eclipse itself uses.
What I wanted cannot be done the way I wanted it to be done
:-(

Related

Cannot find java.exe

I am trying to launch a .bat file but I get the error
System cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe
I understand that this is probably a path variable, but I have not been able to understand how to fix it, if that is the problem.
Thanks in advance.
First of all, the path that you provided i.e. C:\ProgramData\Oracle\Java\javapath\java.exe doesn't appear to be correct. It should point to either JRE or JDK folder that you (probably) have in here:
C:\Program Files (x86)\Java\jdk1.8.0_25\bin
In there you should at least see the following files (and hence, the addition of this bin directory to your PATH variable in the env vars):
java.exe
javac.exe
javaw.exe
javap.exe
java.h.exe
java-rmi.exe
javadoc.exe
jarsigner.exe
jar.exe
If you don't see the files above, something is definitely wrong! Also, even if you were using JRE (not JDK), you should still have this bin folder present, where java.exe resides.
I had the same problem. Here's what worked for me:
Go into your path variable and delete: C:\ProgramData\Oracle\Java\javapath\.
Then add a new one called: %JAVA_HOME\bin
This post helped: java-path-is-not-pointing-to-sdk-path-in-windows
Edit: Sorry, I just noticed that this question was 3 years old.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#ECHO OFF
:: Export java settings from registry to a temporary file
START /W REGEDIT /E %Temp%\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft"
if not exist "%Temp%\java.reg" (
START /W REGEDIT /E %Temp%\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft"
)
if not exist "%Temp%\java.reg" (
echo java not installed
exit /b 1
)
:: Find java location
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%\java.reg ^| FIND "INSTALLDIR"') DO SET "JAVA_HOME=%%B"
SET "JAVA_HOME=%JAVA_HOME:"=%"
SET "JAVA_HOME=%JAVA_HOME:\\=\%"
::SET JAVA_HOME
set "java=%java_home%\bin\java.exe"
"%java%" -version
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Try this to see if you can automatically can detect the java location.And if it's work you can put this at the beginning of your script and use %java% in your script (though it will decrease the performance).

'"java.exe"' is not recognized as an internal or external command,

I have downloaded both Java jdk1.7.0_06 and Java jre7. and i added the following system variable JAVA_HOME C:\Program Files\Java\jdk1.7.0_06\bin to my windows 7. But when I type the following in the CMD command line on my windows 7 C:\activiti-5.10\activiti-5.10\setup>ant demo.start to run a demo application I got the following error in the command line '
"java.exe"' is not recognized as an internal or external command, operable program or batch file
So does anyone know how i can solve this problem ?
BR
If you look at the "ant.bat" file, you will see that it looks for the "java" command in the following way:
If the %JAVACMD% environment variable is set, then it uses that.
Otherwise, if the %JAVA_HOME% environment variable is set, it tries to use %JAVA_HOME%\bin\java.exe
Otherwise, it tries to use java.exe; i.e. it will look on your %PATH%.
In your case, you have %JAVA_HOME% set ... but set to the Java installation's "bin" directory, not to the root of the installation. So the Ant.bat script looks in the wrong place for java.exe.
Just set %JAVA_HOME% correctly, and it should work.
JAVA_HOME C:\Program Files\Java\jdk1.7.0_06
As you can see from the above, you do not need to have the Java "bin" directory on your %PATH% for Ant to work, but it is a good idea to set it anyway. That way you can run the Java commands simply from the command line.
The setting of %CLASSPATH% is not relevant to this problem. Indeed, unless the build.xml file is broken, Ant will ignore your %CLASSPATH% environment variable.
You need to put the file java.exe in your PATH variable but the JRE in JAVA_HOME
JAVA_HOME is the path of JDK root folder.eg: C:\Program Files\Java\jdk1.7.0_06 but path define C:\Program Files\Java\jdk1.7.0_06\bin
JAVA_HOME C:\Program Files\Java\jdk1.7.0_06
JRE_HOME C:\Program Files\Java\jre1.7.0_06
path = C:\Program Files\Java\jdk1.7.0_06\bin;C:\Program Files\Java\jre1.7.0_06\bin
Typically JAVA_HOME should be the parent directory of the "bin" folder.(jre or jdk)
In this case ant expects the java to be from the JDK.
try following in a cmd window
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_06
set path="%JAVA_HOME%/bin;%path%;
ant
(side note: adding java.exe to path is not a requirement for ant; it is a convenience thing for the user)
Just delete the following set of files from your %windir/System32 folder. Actually deleting java.exe is enough but for consistency sake just delete all the java related binaries.
java.exe
javaw.exe
javaws.exe
Actually oracle windows installer places a copy of these files into %windir/System32 folder (which I don't understand why) but looks like they are not needed (as they are available anyway under JDK folder where you install them).
I have tried all the various solutions posted in the SO and other forums as well but none of them worked for me. I have also set all the relevant environment variables (JAVA_PATH, CLASS_PATH etc) correctly as well. Finally this is the only solution that has worked for me.
Go to the \squirrel-sql-3.9.0>squirrel-sql.bat .open that squirrel-sql.bat in Notepad and comment out the existing logic which is
=======================================
if exist "%IZPACK_JAVA%\bin\javaw.exe" (
set LOCAL_JAVA=%IZPACK_JAVA%\bin\javaw.exe
) else (
set LOCAL_JAVA=javaw.exe
)
echo Using java: %LOCAL_JAVA%
=================================
and add the below logic
#echo off
set LOCAL_JAVA=C:\Program Files (x86)\Java\jre7\bin\javaw.exe
echo Using java: %LOCAL_JAVA%
================================
make sure you add the correct path of javax.exe while adding above logic set LOCAL_JAVA=
and start the .bat file from CMD ..that's it. It should work. It worked for me.
I started getting this error in Android Studio after I updated it to version "Electric Eel".
It happened because Android Studio has changed where they put their JRE:
it used to be C:\Program Files\Android\Android Studio\jre
but now it is C:\Program Files\Android\Android Studio\jbr
To fix:
updated my JAVA_HOME environment variable to point to the new java location (C:\Program Files\Android\Android Studio\jre)
and then restarted Android Studio, and now it is fixed.
I agree with the above explanation but if the problem still persists try setting:
CLASSPATH = C:\Program Files\Java\jdk1.7.0_06\bin

Installing ant; clearly misunderstanding JAVA_HOME

I am installing ant on a Windows XP machine, and am following the instructions at Apache's manual site. It said to set JAVA_HOME, so I checked, saw there was no environment variable named JAVA_HOME, made one, and set it to "C:\Program Files\Java\jdk1.6.0_19"
When I try to run ant debug, however, it tells me that JAVA_HOME is currently set to "C:\Program Files\Java\jre6"
I'm guessing JAVA_HOME isn't an environment variable. But if it isn't one, I'm at a loss as to where to start looking for it. Anybody know?
Edit: Oh yeah - it's bugging me for tools.jar as well, but I'm guessing that when I fix the JAVA_HOME issue, that will help the terminal find tools.jar as well. Or maybe I'm wrong. Thanks
Following on Newtopian's suggestions, you can quickly confirm if that behavior is the problem by running in the terminal
C:\>set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_19
C:\>ant debug
Also, I'm not sure if the text you entered into the JAVA_HOME environment variable is literally "C:\Program Files\Java\jdk1.6.0_19", i.e., with quotes, but if so, you should remove the quote marks as they'll throw off ant.bat.
Here's the relevant bit from ant.bat
:checkJava
set _JAVACMD=%JAVACMD%
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if "%_JAVACMD%" == "" set _JAVACMD=%JAVA_HOME%\bin\java.exe
goto checkJikes
:noJavaHome
if "%_JAVACMD%" == "" set _JAVACMD=java.exe
... omitted ...
"%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% %ANT_CMD_LINE_ARGS%
If that doesn't help, could you post your debug task?
Two options to make it permanent:
Run this:
C:\>REG delete HKCU\Environment /V JAVA_HOME
C:\>REG delete HKLM\Environment /V JAVA_HOME
C:\>REG add HKCU\Environment /V JAVA_HOME /d "C:\Program Files\Java\jdk1.6.0_19"
(basically, ensure you only have one JAVA_HOME set and it's correct; be sure to close and reopen the terminal after doing this)
If all else fails, the crappy batch file solution:
#echo off
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_19
ant %*
save as ant_wrapper.bat (or whatever) and you should be able to do ant_wrapper debug.
(Both of these solutions are untested)
Make sure you check both user and system scope environment Variables. I am not certain what is the precedence of one over the other here but most likely you checked as only one and created it there and it is being overridden by the other.
Also when you create the environment variable make sure you open a new command shell for the changes to take effect. then try 'set' that will list all environment variables seen in the environment for the command prompt you just created.
If all is well there but Ant still does not see the correct one then check the batch files that start ANT if the javahome is not set there too. If it is make sure it uses the environment variable and does not try and set it again.
Hope this helps

What should I set JAVA_HOME environment variable on macOS X 10.6?

Many Java applications that use shell scripts to configure their environment use the JAVA_HOME environment variable to start the correct version of Java, locate JRE JARs, and so on.
In macOS X 10.6, the following paths seem to be valid for this variable
/Library/Java/Home
/System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Versions/Current
Some of these are symlinks to the actual current VM (as defined in the Java Preference pane).
But which one should be used—or is it okay to use any of them?
I just set JAVA_HOME to the output of that command, which should give you the Java path specified in your Java preferences. Here's a snippet from my .bashrc file, which sets this variable:
export JAVA_HOME=$(/usr/libexec/java_home)
I haven't experienced any problems with that technique.
Occasionally I do have to change the value of JAVA_HOME to an earlier version of Java. For example, one program I'm maintaining requires 32-bit Java 5 on OS X, so when using that program, I set JAVA_HOME by running:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.5)
For those of you who don't have java_home in your path add it like this.
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /usr/libexec/java_home
References:
Oracle explains the java_home command
An article for configuring the JDK in Spring Tool Suite (Eclipse
2019) on MacOS
Also, it`s interesting to set your PATH to reflect the JDK. After adding JAVA_HOME (which can be done with the example cited by 'mipadi'):
export JAVA_HOME=$(/usr/libexec/java_home)
Add also in ~/.profile:
export PATH=${JAVA_HOME}/bin:$PATH
P.S.: For OSX, I generally use .profile in the HOME dir instead of .bashrc
I am having MAC OS X(Sierra) 10.12.2.
I set JAVA_HOME to work on React Native(for Android apps) by following the following steps.
Open Terminal (Command+R, type Terminal, Hit ENTER).
Add the following lines to ~/.bash_profile.
export JAVA_HOME=$(/usr/libexec/java_home)
Now run the following command.
source ~/.bash_profile
You can check the exact value of JAVA_HOME by typing the following command.
echo $JAVA_HOME
The value(output) returned will be something like below.
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
That's it.
I'm on Mac OS 10.6.8
The easiest solution works for me is simply put in
$ export JAVA_HOME=$(/usr/libexec/java_home)
To test whether it works, put in
$ echo $JAVA_HOME
it shows
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
you can also test
$ which java
Nowadays Java seems to be installed in /Library/Java/JavaVirtualMachines
I tend to use /Library/Java/Home. The way the preferences pane works this should be up to date with your preferred version.
That above works not any more in YOSEMITE for GRAPHICAL APPLICATIONS! Like eclipse, or anything started with Spotlight. (.bash_profile, launchd.conf works for terminal sessions only.)
Before starting eclipse, just open a terminal window, and give out the following command:
launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
(With your installation path! Perhaps works with $(/usr/libexec/java_home) instead of the full path too.)
View the whole excellent article about the permanent solution here:
Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra?
It is recommended to check default terminal shell before set JAVA_HOME environment variable, via following commands:
$ echo $SHELL
/bin/bash
If your default terminal is /bin/bash (Bash), then you should use #hygull method
If your default terminal is /bin/zsh (Z Shell), then you should set these environment variable in ~/.zshenv file with following contents:
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
This method tested working in macOS Mojave Version 10.14.6.
I've found this stack to help, i was having the same issue and i could fix:
My java path was here:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
and was needed to put into my .bash_profile:
export JAVA_HOME=\"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home\"
Hope help
As other answers note, the correct way to find the Java home directory is to use /usr/libexec/java_home.
The official documentation for this is in Apple's Technical Q&A QA1170: Important Java Directories on OS X: https://developer.apple.com/library/mac/qa/qa1170/_index.html
For me maven seems to work off the .mavenrc file:
echo "export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)" > ~/.mavenrc
I'm sure I picked it up on SO too, just can't remember where.
Create file ~/.mavenrc
then paste this into the file
export JAVA_HOME=$(/usr/libexec/java_home)
test
mvn -v
Skipping Terminal setup since you mentioned applications, permanent system environment variable set up (works for macOS Sierra; should work for El Capitan too):
launchctl setenv JAVA_HOME $(/usr/libexec/java_home -v 1.8)
(this will set JAVA_HOME to the latest 1.8 JDK, chances are you have gone through serveral updates e.g. javac 1.8.0_101, javac 1.8.0_131)
Of course, change 1.8 to 1.7 or 1.6 (really?) to suit your need and your system
For Fish Shell users, use something like the following: alias java7 "set -gx JAVA_HOME (/usr/libexec/java_home -v1.7)"

How to set JAVA_HOME for multiple Tomcat instances?

I have 2 Java Web Projects. One runs on JDK 1.5 and the other runs on JDK 1.6. I want to run both of them on the same computer, but the JAVA_HOME environment variable can only have one value. I want to set JAVA_HOME for each Tomcat server.
place a setenv.sh in the the bin directory with
JAVA_HOME=/usr/java/jdk1.6.0_43/
JRE_HOME=/usr/java/jdk1.6.0_43/jre
or an other version your running.
One thing that you could do would be to modify the catalina.sh (Unix based) or the catalina.bat (windows based).
Within each of the scripts you can set certain variables which only processes created under the shell will inherit. So for catalina.sh, use the following line:
export JAVA_HOME="intented java home"
And for windows use
set JAVA_HOME="intented java home"
If you are a Windows user, put the content below in a setenv.bat file that you must create in Tomcat bin directory.
set JAVA_HOME=C:\Program Files\Java\jdk1.6.x
If you are a Linux user, put the content below in a setenv.sh file that you must create in Tomcat bin directory.
JAVA_HOME=/usr/java/jdk1.6.x
Also, note that there shouldn't be any space after =:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_27
You can add setenv.sh in the the bin directory with:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
and it will dynamically change when you update your packages.
In UNIX I had this problem, I edited catalina.sh manually and entered
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24
echo "Using JAVA_HOME: $JAVA_HOME"
as the first 2 lines. I tried setting the JAVA_HOME in /etc/profile but it did not help.
This worked finally.
I think this is a best practice (You may be have many Tomcat instance in same computer, you want per Tomcat instance use other Java Runtime Environment):
This is manual inside file: catalina.sh
# JRE_HOME Must point at your Java Runtime installation.
# Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
# are both set, JRE_HOME is used.
Linux based Tomcat6 should have /etc/tomcat6/tomcat6.conf
# System-wide configuration file for tomcat6 services
# This will be sourced by tomcat6 and any secondary service
# Values will be overridden by service-specific configuration
# files in /etc/sysconfig
#
# Use this one to change default values for all services
# Change the service specific ones to affect only one service
# (see, for instance, /etc/sysconfig/tomcat6)
#
# Where your java installation lives
#JAVA_HOME="/usr/lib/jvm/java-1.5.0"
# Where your tomcat installation lives
CATALINA_BASE="/usr/share/tomcat6"
...
I had the same problem my OS is windows 8 and I am using Tomcat 8,
I just edited the setclasspath.bat file in bin folder and set JAVA_HOME and JRE_HOME
like this...
#echo off
...
...
set "JRE_HOME=%ProgramFiles%\Java\jre8"
set "JAVA_HOME=%ProgramFiles%\Java\jdk1.7.0_03"
...
...
and it works fine for me now......
For Debian distro we can override the setting via defaults
/etc/default/tomcat6
Set the JAVA_HOME pointing to the java version you want.
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Just a note...
If you add that code to setclasspath.bat or setclasspath.sh, it will actually be used by all of Tomcat's scripts you could run, rather than just Catalina.
The method for setting the variable is as the other's have described.
I think you only need add in startup.sh or startup.bat the set JAVA_HOME=C:\Program Files\Java\jdk-19
After check...

Categories