Failed to run a Java app with Git Bash - java

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

Related

Cannot compile java file using javac command under JDK on ubuntu (APARAPI)

I have run the same command under windows using the windows Java Development Kit and it worked.Now i try to run it ubuntu and i get this error.Please help
Different OS have different dist package manager, you try to install Java environment in your Linux system by below Reference
It looks like you are specifying the -cp argument incorrectly.
On Linux, the path separator character is ":" not ";". The ";" character separates commands on the command line, assuming that you are using bash or similar as your shell.
It looks like your command has been interpreted as two commands:
$ javac -g -cp ../dist_windows_x86_64/something
$ . GPUGalaxySim.java
The javac command fails because there are no source filenames on that command line ... just like the error message says.
Then the second command:
The dot command (".") is a built-in shell command that "sources" a file and attempts to interpret it as shell commands.
If you attempt to "source" a file that is actually Java source code, you get nonsense error messages, basically because the shell has no clue what Java code means.

asadmin command doesn't work in ubuntu

I'm using Java EE with Glassfish.
I can't run asadmin command as well. I did the following, but output from terminal is:
No command 'asadmin' found, did you mean: Command 'amadmin' from package 'amanda-server' (universe) Command 'acsadmin' from package'ion' (universe) asadmin: command not found
I have Ubuntu 14.04 Trusty Tahr. I should be in bin directory of glassfish, so I'm in /opt/glassfish4/bin.
But always nothing happend, just error message above.
In Ubuntu and Linux in generĂ¡l, you run commands from current directory like this: ./asadmin, ie. you must prepend ./ to make it explicit that you run a command I current directory. This is traditionally for some security reasons.
Try following command export PATH=/installationDirectory/glassfishName/bin:$PATH
In my case it was export PATH=/opt/glassfish4/bin:$PATH
The asadmin command needs to be read from glassfish bin directory when executing commands, hence you need to export the following in your environment variables.
On mac,
export PATH=/Users/macpro15/Downloads/glassfish5/bin:$PATH
I think you are creating the domain inside the default domain. You should make your own domain in the domains folder, and the run the following command in your terminal:
sh asadmin start-domain DOMAIN_NAME

Run java in $PATH as an interpreter

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).

cannot compile java files using cygwin

I am trying to compile some files using cygwin shell.
java file that I am trying to compile is C:\Users\Programs\x.java
For windows command prompt
C:\Users\Programs>javac x.java
No errors.
For Cygwin shell
$ javac /cygdrive/c/Users/Programs/x.java
Error:
javac: file not found: \cygdrive\c\Users\Programs\x.java
Why do I get an error in cygwin shell though it runs in windows command prompt
javac is Windows application. It has no clue about /cygdrive. Always keep it in mind and pass valid Windows paths.
So use javac 'c:/Users/Programs/x.java' or javac c\:/Users/Programs/x.java
Also, as in most Unix shells \ must be escaped if you need to use it.
I think that the problem is that "cygdrive" is a pseudo-device that is implemented in a Cygwin-specific library. If the executable you are running has not been linked against that library (and the Oracle Java executables have not!) it won't correctly resolve the "/cygdrive" path component.

Do commands run from current directory in a shell script?

In a bash shell script I tried these two versions:
java -jar abc.jar&
and
CMD="java -jar abc.jar&"
$CMD
The first verison works, and the second version complains that abc.jar cannot be found. Why?
Commands do run from current directory in a shell script.
This is why the first command in your test script worked.
The second command may not work because either java isn't in your ${PATH} or abc.jar isn't in your ${CLASSPATH}. You could echo these environment variables or set +x to debug your bash script.
Bash (and others) won't let you do backgrounding (&) within the value of a variable (nor will they let you do redirection that way or pipelines). You should avoid putting commands into variables. See BashFAQ/050 for some additional information.
What is the actual error message you're getting? I bet it's something like "abc.jar& not found" (note the ampersand) because the ampersand is seen as a character in the filename.
Also, the current directory for the script is the directory that it is run from - not the directory in which it resides. You should be explicit about the directory that you want to have your file in.
java -jar /path/to/abc.jar&

Categories