I have a Java code where I am importing Guava packages. I run it in windows command prompt using following commands:
javac -cp guava-11.0.2.jar Test.java
java -cp guava-11.0.2.jar;. Test
However, in Linux it is giving error. Can anybody help me to solve this issue.
The path separator on Linux/Unix is a colon, i.e. :.
So in your case the second command on Linux/Unix would be:
java -cp guava-11.0.2.jar:. Test
class path entries are separated by colons in Linux (not semicolons as in Windows)
Try that:
java -cp guava-11.0.2.jar:. Test
Related
I am currently following this tutorial on tomcat, Step 6(b) Compiling the Servlet. I was able to compile in cmd, but I want to try to get it to work in Powershell as well.
cmd:
javac -cp .;c:\myProject\tomcat\lib\servlet-api.jar HelloServlet.java
How would I compile using Powershell?
I saw this somewhere, but this isn't compiling the java source file into a class:
java -cp '{jar path}' -Dcontext=atest1 -Dresourcepath=." DW_Install
I'm fairly novice at powershell, so I don't really understand if I need -Dcontext and -Dresourcepath. What does -D do?
I imagine the problem is the semi colon. In PowerShell, the semi colon is an end of statement character, so the above command will be treated as if it were two separate commands:
javac -cp .
c:\myProject\tomcat\lib\servlet-api.jar HelloServlet.java
To fix this, I imagine you'll need to quote the class path argument:
javac -cp '.;c:\myProject\tomcat\lib\servlet-api.jar' HelloServlet.java
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
How to add multiple .jar files in the javac/java class path - for Debian Linux.
Iam using,
javac -cp a.jar folder1\folder2\b.jar Test.java
But, it is giving Invalid flag error. Can anybody help me how to compile and run it ?
Separate the class path entries by : colons, not spaces.
Also you should use '/' instead of '\' as directory separator.
Also use quotation marks " to specify a classpath when using Powershell:
javac -cp ".;folder1\folder2\b.jar" Test.java
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