Setting JAVA_OPTS in windows using command prompt - java

I am running the java program on windows server 2012, I want to set the JAVA_OPTS variable and use it, here is how I am doing it:
Open a command prompt in the bin of jdk where it is installed ,and executing the following command :
$set JAVA_OPTS = “-Xdebug , server=y”
Then in the next line in the command prompt only , when I try to run
$java $JAVA_OPTS –cp .Server
(where Server is the name of the java program), I get an error saying that:
Could not find or load assembly $JAVA_OPTS. Please let me know what mistake I am doing here. I am not using IDE for this purpose.

on windows you have to set the variable like:
set JAVA_OPTS = “-Xdebug , server=y”
and use it this way
java %JAVA_OPTS% –cp .Server

Windows uses "%JAVA_OPTS% rather than "$JAVA_OPTS" which is UNIX/LINUX.
You can check if the environment is updated with JAVA_OPTS by echoing that:
echo %JAVA_OPTS%.

Related

Windows 10 - setting Java and Maven as enviroment and system variables with bash terminal

I am working on a project on a virtual machine that is running on windows 10, and where I don't have the user access to system variables in GUI. Since, I need to use Maven I am wondering how can I set the java and maven variables with bash terminal?
I have tried to set the variable with this command:
export M2_HOME="/c/Program Files/apache-maven-3.6.3"
export M2="$M2_HOME/bin"
export MAVEN_OPTS="-Xms256m -Xmx512m"
And then if ran mvn --version in the terminal, I got:
bash: mvn: command not found
If I ran printenv I see in the list that the variables were set:
M2_HOME=/c/Program Files/apache-maven-3.6.3
M2=/c/Program Files/apache-maven-3.6.3/bin
MAVEN_OPTS=-Xms256m -Xmx512m
But, if I close the terminal and open it again, then I don't see these variables again.
What is the right way to set up Java and Maven env variables through bash on Windows?
You need to escape the string by surrounding it with quotes:
export M2_HOME="/c/Program Files/apache-maven-3.6.3"
EDIT:
To answer the question in the comments, note that you still need to add mvn's path to the $PATH variable in order to use it:
export PATH=${PATH}:${M2}

The system cannot find the path specified: Error while starting zookeeper(Apache Kafka)

I am getting the below error while starting Zookeeper server in the command prompt:
The system cannot find the path specified.
I am using Windows 8 OS, Kafka 2.12 and Java 8 JDK.
I have checked on the below:
Set JAVA_HOME to JDK bin folder.
Set the PATH environment variable correctly using JAVA_HOME as the relevant path.
Set the CLASSPATH environment variable correctly using JAVA_HOME as the relevant path.
Used shortened path in windows to avoid using spaces:
Ex: C:\Progra~1 instead of C:\Program Files
Checked on the below commands in the command prompt:
echo %JAVA_HOME%
echo %PATH%
echo %CLASSPATH%
where java
java -version
java -d64 -version
javac -version
All of them gave me the specified path. However it didn't resolved my issue.
I think JAVA_HOME should keep till JDK path not JDK\bin.
There is this file kafka-run-class.bat which gets referenced in most of the kafka scripts. It sets the JAVA parameter depending on the JAVA_HOME variable mentioned below:
set JAVA="%JAVA_HOME%/bin/java"
We need to modify this since JAVA_HOME already contains path until 'bin'. So now Kafka tries to append an extra bin directory to the path. We need to alter this as mentioned below:
set JAVA="%JAVA_HOME%/java"
Now on starting the zookeeper again in a fresh command prompt the error is gone and the zookeeper starts fine.
I was also facing the same issue:
My java home set was
C:\Program Files\Java\jdk1.8.0_144\bin
Then i did the following change:
1)changed the jdk location to C:\Java\jdk1.8.0_144\bin as earlier location was containing spaces between Program and Files.
2)Also i need to change the kafka-run-class.bat file from
IF ["%JAVA_HOME%"] EQU [""] (
set JAVA=java
) ELSE (
set JAVA="%JAVA_HOME%/bin/java"
)
to
IF ["%JAVA_HOME%"] EQU [""] (
set JAVA=java
) ELSE (
set JAVA="%JAVA_HOME%/java"
)
.
As my java home already contains /bin suffix.So either remove the bin suffix from your java home or modify the kafka-run-class.
But still i was getting same error when running from the command prompt.Then i closed the cmd and again opened the new command prompt and run the following command and it run successfully.
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
Note:If you modify the system variable then you need to restart the system.

echo %JAVA_HOME% returns %JAVA_HOME%

When I do
echo %JAVA_HOME%
it returns %JAVA_HOME% on windows 10 what did I do wrong?
If you are sure that you have set them properly, you can print your environment variables like JAVA_HOME using any of the below methods in Windows 10.
Windows Command prompt ( cmd.exe )
C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.7.0_80
Git Bash within windows, you need to use the bash format
user12231#TP-UN103 MINGW64 /c
$ echo $JAVA_HOME
C:\Program Files\Java\jdk1.7.0_80
From the conversation, it looks like you are using Windows 10 powershell.
To print the environment variable in windows powershell, use one of the following commands as below
PS C:\>Get-ChildItem Env:JAVA_HOME
Name Value
---- -----
JAVA_HOME C:\Program Files\Java\jdk1.7.0_80
or
PS C:\> echo $env:JAVA_HOME
C:\Program Files\Java\jdk1.7.0_80
You can refer the Powershell documentation here.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-6#displaying-environment-variables
There is high possibility that you used the Windows10 PowerShell terminal unknowingly instead of the standard windows command prompt.
In a standard Windows command prompt, when you type the below command, you would get the JAVA_HOME path as expected.
echo %JAVA_HOME%
Upon issuing the same command in PowerShell you would see %JAVA_HOME% written out.
PowerShell does things differently.
In this case to output environment variables, you need to use
echo $env:JAVA_HOME
Additional tip:
To print all environment variables dictionary use
dir env:
The syntax depends on the shell/terminal you are using.
Try
echo $JAVA_HOME
this is the syntax for bash, for instance if you are using Git Bash to run your commands.
In windows, Open powershell and try this command
echo $env:JAVA_HOME
Or if you have Git Bash installed then try
echo $JAVA_HOME
If you just added the System Variable you need to reboot for System to read it
if you are using an classic cmd command "echo %JAVA_HOME%" in windowsJAVA is fine
Your command is correct for a windows 10 machine. And the result tells us, that this variable is not set.
You can look for the settings for the environment variables in your start menu. You'll see settings for other variables like Path, TEMP and so on. There you can add JAVA_HOME (here without %). The path would be like this (from my pc): C:\Program Files\Java\jdk1.8.0_161
It prints "JAVA_HOME" because you didn't set JAVA_HOME variable or you have typo in variable name. Just go to your environment variables settings and check if it's correct. If you don't have JAVA_HOME there just look at this question: How to set JAVA_HOME
I'm not sure, but i thought you need $ for Environment Variables.
Try: echo $JAVA_HOME
I know this answer is well overdue, but after hours of searching, it solved the problem for me.
Reinstall everything (git, jdk/jre, potentially maven), but when you do, leave EVERYTHING as its default value. Do not change any of the settings, DO NOT CHOOSE A SPECIFIC SAVE LOCATION that is convenient for you, etc. Leave everything as their default values.
Turns out, git is particularly rigid when it comes to flexibility, and it doesn't play well if you change the install location. When I was installing git, I changed the save location. I had been installing and practicing a bunch of new tools, and I wanted to have them all in one isolated spot. Just goes to show that the default way is usually the best way.
For Windows Powershell use
$env:JAVA_HOME
For Windows Command Prompt use
echo %JAVA_HOME%
i think u have installed jre, install jdk, your problem should be solved.
Check that you've added JAVA_HOME variable in a corresponding block. If wrong, add in the bottom block and restart Windows.

Not able to set JAVA_HOME variable in ubuntu 14.04 on manual installation

I've downloaded java jdk1.8.0.7.tar.gz file from the official website and unzipped it into my home directory. Now to set the $JAVA_HOME variable I used the follwing commands command nano .bashrc and then appending export $JAVA_HOME=/home/shivam/Java/jdk1.8.0.7 at the end of the file . But whenever I run the command sudo $CATALINA_HOME/bin/startup.sh I get an error message saying
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
I don't understand why it is unable to find the java path though I've installed tomcat and set its home variable the this way, which worked.
I wan't to install Java manually without using apt-get. Kindly guide .
You want to append the following to .bashrc:
JAVA_HOME=/home/shivam/Java/jdk1.8.0.7
Note the missing $ at the start.
Also remember that the file won't effect your current shell without sourceing it first.
Also, when running a command with sudo, you are running it as the root user, not as yourself. So the environment variable needs to be set for the root user, not yourself.
You can run sudo env | grep JAVA_HOME to see whether it is set for root.
Have you run .bashrc ?
source .bashrc
Try add the following 2 lines in your .bashrc file:
JAVA_HOME=/home/shivam/Java/jdk1.8.0.7/
export JAVA_HOME

Websphere Application Server 8.5 Java 7 questions

I have the following questions on WAS 8.5 installation:
Can Java 7 be installed outside {or}c:\IBM\Websphere\Appserver
Can the Java 7 name be other than Java1.7_64?
Also how to get the info. using any bat/sh file from IBM
Thanks in advance
No to both: there is no way to change the Java install directory.
To determine the configured JDK, source setupCmdLine and use the JAVA_HOME variable. For example, on UNIX:
. /path/to/profile/setupCmdLine.sh
echo $JAVA_HOME
...and on Windows:
C:\path\to\profile\bin\setupCmdLine.bat
echo %JAVA_HOME%
If you need to automate discovery, you might write a temporary batch file with the following contents, execute it (e.g., using ProcessBuilder), and then parse the resulting output:
#echo off
call "C:\path\to\profile\bin\setupCmdLine.bat"
echo JAVA_HOME=%JAVA_HOME%

Categories

Resources