I am using grunt-jsdoc to manage the execution of jsdoc command, which depends on Java and needs to have the JAVA_HOME environment variable set. Assuming they already have node.js and Java, I'm trying to limit the local developer setup (on either Linux or Windows) to:
Checkout the project
run npm install
I have this working on Linux by using the grunt-shell plugin and running a task like this right before the jsdoc task:
// left out the part where I don't execute this task if JAVA_HOME already set
shell: {
getjavahome_linux: {
command: 'readlink -f /usr/bin/java | sed "s:bin/java::"',
options: {
callback: function(err, stdout, stderr, cb) {
process.env.JAVA_HOME = stdout;
cb();
}
}
}
}
But I have not been able to find a similar command for Windows, to say nothing of other platforms. My question:
A) Is there a better approach in Grunt that does not require these platform-specific commands?
OR
B) If not, anyone have a Windows command that will do the equivalent of the Linux version above?
Note: actually setting JAVA_HOME inside the shell command does not work with grunt-jsdoc, but getting the output and setting process.env.JAVA_HOME works great.
The JAVA_HOME env var check becomes a simple warning since version 0.3.3 of grunt-jsdoc
And since version 0.5.0, it doesn't require the Java version of jdsoc anymore. It fully runs on node.js
On windows, I use cygwin shell (the git-bash version) to run Grunt where JAVA_HOME is set...
But it should work from the windows cmd, I've juste tried:
test.js
console.log(process.env.JAVA_HOME);
cmd.exe
set JAVA_HOME=D:\path
node test.js
displays the path
Related
I'm making a NSIS installer for a program that requires Apache Tomcat 8 as Windows Service. JAVA_HOME is set as an environment variable in NSIS installer script, and I've made Powershell Script file to deal with Tomcat specific variables (CATALINA_HOME, JvmMX, JvmArgs) and to run service.bat install in the end.
When I run the following Powershell script independently (with JAVA_HOME environment variable set) service.bat install installs the Tomcat service finding the right correct JAVA_HOME path. However, when it's done via installer, as shown in the image below, it gets an empty path for both JAVA_HOME and JRE_HOME.
I'm relying on psExec.nsh plug-in to execute Powershell script (${PowerShellExecFileLog})
I don't seem to be able to find why this is happening.. any help would be very appreciated!
My only speculation is that it has something to do with 32-bit/64-bit. I'm confident that I'm wrong so please correct me but here goes my thought: The system is 64-bit and the JAVA_HOME environment variable is 64-bit, but the installer is 32-bit, making the Powershell it's calling is 32-bit so the Powershell can't retreive the 64-bit environment variable.
Followings are the relevant codes snippets:
[PowerShell Script -- Tomcat-Setup.ps1]
$PhysMemory=(Get-WmiObject -class "cim_physicalmemory" | Measure-Object -Property Capacity -Sum).Sum / 1024 / 1024 / 1024
$SERVICE_STARTUP_MODE="auto"
if($PhysMemory -le 16) {
$JvmMX=2048
} elseif($PhysMemory -le 32) {
$JvmMX=4096
} else {
$JvmMX=8192
}
$JvmArgs="-Djavax.servlet.request.encoding=UTF-8;-Dfile.encoding=UTF-8;-XX:+HeapDumpOnOutOfMemoryError;-XX:+ExitOnOutOfMemoryError;-Dconf.home=$env:LGCDM_HOME\conf\service"
$CATALINA_HOME="$env:LGCDM_HOME\apache-tomcat"
Set-Location $CATALINA_HOME
& .\bin\service.bat install LG_Tomcat
Set-Service -Name LG_Tomcat -StartupType Automatic -DisplayName LG_Tomcat
[NSIS Script]
Section "MainSection" SEC02
InitPluginsDir
${PowerShellExecFileLog} "$INSTDIR\Tomcat-Setup.ps1"
SectionEnd
Writing to the registry does not affect the installer and any child processes you might start, you should also update the installer process itself:
!include "winmessages.nsh"
${registry::Write} ...
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
System::Call 'KERNEL32::SetEnvironmentVariable(t "JAVA_HOME", ts)' "$INSTDIR\amazon_jdk\jdk11.0.12_7" ; Update this process
...
; Start Powershell script...
This question already has answers here:
Java command not found on Linux
(6 answers)
Closed 6 years ago.
i try to run spark application on a cluster standalone mode, when i access to some remote machines and use "java -version" command i get the information(java version ..), but on others i get an error
-bash: command not found
so i thought that maybe java is not installed on those nodes so i tried with:
sudo apt -get install openjdk-8-jdk
but i get the same error, so wanna know how can i fix this, and i have some questions:
-Is it necessary that i install java on all remote machines? or if i install it only on the master node it is enough?
-if i have to install it on each node, how can i fix the problem that i explained before? (can not use install command...)
-In my code, i used expressions that are only supported with jdk 8, but some nodes (in which i could get "java version") it is installed jdk7, so do i have to reinstall jdk8 ?
"command not found" error means that particular command you're trying to invoke is not found in neither of directories listed in $PATH system variable.
There are two ways how to fix this:
1) Specify full path when running an executable:
/opt/jdk-12345/bin/java -version
2) add the very same path to the beginning of PATH (change will be applied to current session only):
export PATH=/opt/jdk-12345/bin:$PATH
java -version
To fix this permanently, add that line (export PATH=/opt/jdk-12345/bin:$PATH) to ~/.bashrc (if BASH is default shell for that user) or to ~/.profile
Also because this is Unix Java, make sure to set up LD_LIBRARY_PATH and CLASSPATH variables if you're running some server applications. Usually this is done in application startup scripts, no need to go global.
Please verify which Server OS you're running ( uname -a or /bin/uname -a ) because different Unix systems have different package managers: apt-get is for Ubuntu/Debian, rpm for RedHat, Entropy for Sabayon/Gentoo, etc...
I'm trying to install Jasperserver onto a Windows VM with Powershell.
I can install Java just fine, but some subsequent bat files that get run are complaining they can't find environment variables such as JAVA_HOME. I can see they exist however.
I add the environment variables:
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Java\jdk1.8.0_91", "Machine")
[Environment]::SetEnvironmentVariable("JRE_HOME", "C:\Program Files\Java\jre1.8.0_91", "Machine")
[Environment]::SetEnvironmentVariable("CLASSPATH", "C:\Program Files\Java\jdk1.8.0_91\jre1.8.0_91\lib\rt.jar", "Machine")
And also the path variable. Going into System -> Advanced System Settings -> Environment variables I can see they are there, so I assume it's not just setting the powershell session.
When I try to run ANT (though a build in batch)
cd C:\Jaspersoft\jasperreports-server-6.2.0\apache-tomcat\bin
$arguments = '/c service.bat install'
Start-Process cmd -Wait -PassThru -ArgumentList $arguments
it gives me this error:
> WARNING: JAVA_HOME environment variable not found [minimal] Running
> install-minimal-pro Ant task
> ---------------------------------------------------------------------- '"java.exe"' is not recognized as an internal or external command,
> operable program or batch file. Checking Ant return code: OK
I've tried:
Setting the environments several ways (setx.exe, etc)
Running the bat in many ways, start-process, cmd, in an invoke-command, etc
If I reboot the server it will install fine. Also, if I run the batch directly in a command prompt it's fine.
Before I have to use an image with Java already installed, I want to understand why this is happening and ideally make it work.
Both SetEnvironmentVariable(..., "Machine") and setx set the variable in the registry. This value is used for future processes launched by explorer (such as after a reboot), but it is NOT set for the current process or its children. Your script needs to set the variables for the current process.
Using the .NET syntax:
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Java\jdk1.8.0_91", "Process")
Or, using PS syntax
$env:JAVA_HOME = "C:\Program Files\Java\jdk1.8.0_91"
There's an issue when I run the android Runtime.getRuntime().exec method.
I have a native binary file to be run on android and I start it with the java method Runtime.getRuntime().exec. But running this native binary file requires the addition of an environment variable. So I execute this command:
envSetCmd = {"sh", "-c", "export LD_LIBRARY_PATH="+excBinFilepath+":$LD_LIBRARY_PATH"}.
It doesn't work when I check the environment variable with the command:
sh, -c, echo $LD_LIBRARY_PATH.
I think the reason is that when I set the environment variables I start a shell and when I check it with the command "echo" another shell was started. So the environment variables didn't work in the shell I check it.
I think there are two ways to solve this issue. The one is that running two commands in one shell. So I tried to use the command:
{"sh", "-c", "export LD_LIBRARY_PATH="+excBinFilepath+":$LD_LIBRARY_PATH", "-c", "echo $LD_LIBRARY_PATH"}.
Unfortunately it is illegal. The other is that I add the environment variables to the android user startup files. I tried to echo the $PATH, and I see the /system/bin/ and other path was loaded at the startup of android.
So I think there must be a file just like the ~/.bashrc in linux which could set the users' environment.
Any one could give me some clues about the ways I listed above? By the way, I shouldn't root the phone!
try to execute whatever you need to execute with env:
{"env", "LD_LIBRARY_PATH="+excBinFilepath, "yourCmd"}
I want to make a script starting with a line:
#!java hogehoge.Hoge
In my machines of OS X and CentOS7, it runs.
But machines of CentOS6 give me an error:
./test.sh: bad interpreter: java
(My OS is JP so I omitted some of error messages but anyway it says java does not exist.)
All the environments are under zsh and
of course, every $PATH contains a certain PATH like /usr/bin.
If I try a new script starting with:
#!/usr/bin/java hoge.Hoge
then it runs even in where the script with "java" does not work.
Does the difference come from the one between OSs?
or is there anything else that I do not realize?
Java isn't a script interpreter, but you can run your java process with a script. Something like
#!/usr/bin/env bash
# export JAVA_HOME="/path/to/java_installation"
# export PATH="$PATH:$JAVA_HOME/bin"
java hoge.Hoge
You may need to define JAVA_HOME and add it to your PATH (depending on your installation of Java).