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"
Related
So, I am trying to run a program from jar files. It uses javaswing and has a gui.
The program runs fine in netbeans and in eclipse.
When I try to run it from the exported jar file it says this:
Unable To Install Java
There are errors in the following switches:
"C:\Users\CNC Department\Desktop\ValveConversion.jar";.
Check that the commands are valid and try again.[java installation not complete
Now, I also tried doing it from the command prompt. Here is what came up:
[cmd prompt attempt][1] [1]: https://i.stack.imgur.com/7reZ3.png
So, I reinstalled the java JDK, java SDK, netbeans and eclipse. The issue is still occurring in both command prompt and from running the jar file directly.
What am I doing incorrectly here? What do you recommend that I do to get this to run from a .jar file?
You need to set the java path
Open a cmd with elevated privileges and run this command to set the JAVA_HOME environment variable using setx command:
setx JAVA_HOME -m "C:\Program Files\Java\jdk-11.0.2"
Then restart the cmd and run java -version to check if it's all ok.
For reference setx command documentation
Or simply use the following snippet if you prefer to use java without setting the PATH variable:
"C:\Program Files\Java\jdk-11.0.2\bin\java" -jar "C:\Users\CNC Department\Desktop\ValveConversion.jar"
I downloaded SymmetricDS, a tool for Database replication and tried to run it on my Windows7 machine. The program can be launched from command line and it works with Windows Terminal. However I always prefer Git Bash for command line stuff. When I run command sym though, I got error:
Error: Could not find or load main class org.jumpmind.symmetric.SymmetricLauncher
This tool is written in Java. I have JDK 1.8 installed. Git Bash inherits all environmental variables including $PATH and $JAVA_HOME from Windows. But why is it complaining about not finding the class?
The sym command is really running the following command:
exec "$SYM_JAVA" $SYM_OPTIONS -cp "$CLASSPATH" org.jumpmind.symmetric.SymmetricLauncher "$#"
All the jars are located in lib under the root directory of the application. The classpath is defined in a sym.service.conf inside conf directory:
# Java Classpath
wrapper.java.classpath.1=patches
wrapper.java.classpath.2=patches/*
wrapper.java.classpath.3=lib/*.jar
wrapper.java.classpath.4=web/WEB-INF/lib/*.jar
# Application main class and arguments
wrapper.app.parameter.1=org.jumpmind.symmetric.SymmetricLauncher
I added echo $CLASSPATH right before the exec to print out the class path and it did seem to get all of them right:
/c/Users/dnj0109/Apps/symmetric-server-3.8.29/patches:
/c/Users/dnj0109/Apps/symmetric-server-3.8.29/patches/*:
/c/Users/dnj0109/Apps/symmetric-server-3.8.29/lib/*:
/c/Users/dnj0109/Apps/symmetric-server-3.8.29/web/WEB-INF/lib/*
That could be related to this thread:
On Windows, the path separator is a semicolon (';' instead of ':').
Don't ask why. Traditionally, the semicolon is interpreted by the Bash as
the command separator, so you'll have to escape it:
$ java -cp lib/clojure-1.1.0.jar\;lib/clojure-contrib-1.1.0.jar
If you wonder why it works with PATH: MSys has special handling routines
for that.
Another reason that a java app may run in a Windows CMD shell but not in a Windows git bash shell is that the classpath used to run the app contains one of the following:
relative paths (e.g. ../foo)
network drives (e.g. //servername/bah
See:
https://github.com/git-for-windows/git/issues/1028
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 followed all the steps on pig.apache.org ,but not able to remove this error by setting java variable. I set the variable earlier while installing java jdk but its asking again for the variable.
You need to understand how environment variables work in Linux (or Windows).
The chances are that you only set JAVA_HOME temporarily in the shell that you used to do the installation. To set JAVA_HOME permanently (on Linux / UNIX) you need to set it in a shell "rc" file that gets run each time a new shell is created. (It depends on which shell you are using, but man can tell you about that ...)
if you are installing PIG on ubuntu do this
open bashrc file using below command and and lines to the end of the file
vi ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-i386
then log out or Restart your system and try again.
For CentOS
Create a new file called java.sh
vim /etc/profile.d/java.sh
Within this file, initialize the necessary environment variables
export JRE_HOME=/usr/java/jdk1.5.0_12/jre
export PATH=$PATH:$JRE_HOME/bin
export JAVA_HOME=/usr/java/jdk1.5.0_12
export JAVA_PATH=$JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin
Replace java path with your java installation.
Source
To set your JAVA_HOME variable for your current shell, use the export command. This will immediately create an environment variable for JAVA_HOME, but the variable is lost when your shell is closed.
export JAVA_HOME=<path_to_java_sdk>
The best way to set the JAVA_HOME environment variable for Pig and Hadoop use is by adding it to your local rc file. The reason for this is that some distributions of Hadoop (Cloudera, Hortonworks, MapR) may include their own Java installation for the Hadoop application itself. You may not want to create a global environment variable, since it may interfere with Hadoop/Hive/etc.
To have the variable set for individual Hadoop/Pig users on the server, they need to run the following command:
echo "export JAVA_HOME=<path_to_java_sdk>" >> ~/.bashrc
Afterward executing the command, they can source ~/.bashrc to instantiate the environment variable.
What I'm trying to do is running a .java source by compiling and running it from command prompt (not using any IDE) using commands javac and java and the program connects with MySQL, so everytime I run the program from cmd, I need to specify path of the MySQL connector using -classpath switch of java. And entire command to run the program gets something like below:
java -class .;path/to/connector/mysql-connector.jar MySQLConnect
where I want it to be as simple as for other programs like java MySQLConnect
and it should run the program.
Is there any way I can add the connector's path to environment variables of Windows that java make use of it. I already tried by creating a new CLASSPATH variable in Windows environment variables and added absolute path of the connector with file name along, but that didn't worked.
Please provide me the workaround of this Windows and Ubuntu as well.
Thanks.
WIndows : Copy mysql-connector.jar to C:\Program Files\Java\jdk1.6.0\jre\lib\ext
and copy the same file to C:\Program Files\Java\jre1.6.0\lib\ext
go to My Computer -> Properties -> Advanced -> Environment Variables
Set these paths
JAVA_HOME
C:\Program Files\Java\jdk1.6.0
PATH
C:\Program Files\Java\jdk1.6.0\bin;
CLASSPATH
.;C:\Program Files\Java\jre1.6.0\lib\ext\mysql-connector.jar;.;
open a fresh command propmpt
type
java -version press Enter
WINDOWS
Go to My Computer -> Properties -> Advanced -> Environment Variables
then find CLASSPATH variable in System variables and click on edit to add your jar file there.
LINUX or MAC
In your shell use a variable CLASSPATH in your .bashrc or .profile to set a default class path.
Set classpath=%classpath%;location of mysql-connector with connector file name.jar. For example:
set classpath=%classpath%;D:\TECHNICAL\JAVA WORLD\JDBC\mysql-connector-java-5.1.18-bin.jar;
D:\TECHNICAL\JAVA WORLD\JDBC\ is the location of mysql-connector.
To set this path go to Advanced System Settings->Environment variables->User variables->CLASSPATH->Edit, then type set classpath=%classpath%;D:\TECHNICAL\JAVA WORLD\JDBC\mysql-connector-java-5.1.18-bin.jar; and finally press OK.
I have done in this style. After that, I got result of programs correctly. Then there is noCLassNotFoundException.