I run my java application on unix machine. After I input the command, it show me ">" sign. It seems I am in a interactive state with my application, but my application shouldn't interact with me. Instead, it just write something to files.
root#ip...:/mnt/test/java -cp "./" pack.foo
>
On windows machine, it just works file.
I also tried:
nohup root#ip...:/mnt/test/java -cp "./" pack.foo &
but still
On any UNIX system, the java syntax should be:
javac -cp <classpath of application> MyClass.java
java -cp <same classpath as above> MyClass
the second command should just be the name of the .class file you are attempting to run, and if everything is in the current directory, the argument for -cp should be "." without quotation marks
java -cp . MyClass
Related
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
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.
I am currently trying to write a program that reads the metadata of images using the library from here: https://github.com/drewnoakes/metadata-extractor/wiki/GettingStarted. My issue is that I cannot figure out how to compile the program using more than one .jar file (and it requires two). Both jar files are in my working directory, with the java file I'm trying to compile.
This is the command I am using, with just one .jar file referenced.
javac -cp metadata-extractor-2.7.2.jar MetadataPhotoExtractor.java
Thanks for any help
-Aaron
Use colon on unix-like systems as separator.
javac -cp metadata-extractor-2.7.2.jar:my-other-jar.jar MetadataPhotoExtractor.java
On Windows use semicolons because the colon is restricted for drive letter separation.
for windows
javac -cp metadata-extractor-2.7.2.jar;myother.jar MetadataPhotoExtractor.java
for Linux
javac -cp metadata-extractor-2.7.2.jar:myother.jar MetadataPhotoExtractor.java
More arguments are accountet as a list separated with : of the current parameter.
javac -cp lib1.jar:lib2.jar:lib3.jar myClass.java
Have you tried:
javac -cp metadata-extractor-2.7.2.jar:xmpcore-5.1.2.jar MetadataPhotoExtractor.java
I am following this tutorial to make a program that interacts with the database. I am stuck at the last step where I run it. The given example is
C:\test>java -cp c:\test\postgresql-8.3-603.jdbc4.jar;c:\test JDBCExample
I have both the .class file and the .jar for the JDBC in my home directory. I tried
java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF/QueryDB.class and I get "cannot exectue binary file"
I tried
java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF/QueryDB and I get "no such file or directory"
I tried
java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF QueryDB and I get "JohnF is a directory"
I used chmod to set the file permissions to 777. How do I get this to run?
You are using semicolon as classpath separator - this will not work on Linux.
Try replacing ";" with ":" in classpath and it should work.
Edit: explanation of what is happening here.
In Linux, ";" is command separator. Your line of
java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF QueryDB
is really expanded into 2 executed one by one:
java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar
/home/JohnF QueryDB
First one does nothing and successfully quits.
Second tries to invoke /home/JohnF as executable, and this is really not an executable, but a directory!
FIX: Use : instead of ;
WHY? The file-separator in *nix environment is ':' and not ';'
this is the command.
java -cp clojure.jar;sum.jar CalculateSum
sum.jar is a jar file made from clojure and java code.
CalculateSum is file which contains main method of java.
error from cygwin
can't execute binary file, Error 126
Cygwin provides you with a *nix environment within Windows, so that you might have to change the classpath separator to colons:
java -cp clojure.jar:sum.jar CalculateSum
Try:
java -cp clojure.jar:sum.jar:. CalculateSum
If you execute in the place you have the root of packages for CalculateSum.class
java -cp "clojure.jar;sum.jar" CalculateSum this is working