I've written a java program and I'm trying to run it from cmd both in Windows and Linux.
I first compiled and then run it , and it worked just fine on Windows.
The problem comes up when I'm trying to do the same thing on Linux. The commands I've used on Linux are :
javac -cp aspose-cells.jar:aspose-words.jar:aspose-slides.jar ConvertToPdf.java
java -cp aspose-cells.jar:aspose-words.jar:aspose-slides.jar ConvertToPdf
The first command , which starts with javac, works just fine and outputs the ConvertToPdf.class file. The problem comes up after running the second one , which outputs the following error:
Error: Could not find or load main class ConvertToPdf
I'd like to know what am I doing wrong , and I'd be grateful if anyone could point me to the solution.
Thanks in advance.
Add the current directory . to the classpath:
java -cp aspose-cells.jar:aspose-words.jar:aspose-slides.jar:. ConvertToPdf
your working directory is not included in class path.
do this :
export CLASSPATH=$CLASSPATH:<your-jars>:.
it should work !!!
Related
I am running a java program using a .bat file. It works well after double clicking direcctly on the .bat, that's not the problem.
What I want now, is to run that .bt file (and the java program by extends) from the cmd at first, and then to be able to compile it from any other machine.
I have followed at first the following answer : How do I run a java program from a different directory? , but it didn't work for me.
Here is my .bat file :
#echo on
set CLASSPATH=%CLASSPATH%;.;lib/console.jar;lib/log4j-1.2.13.jar;lib/prog1.jar;lib/prog1_newOption.jar;lib/org.hamcrest.core_1.3.0.v201303031735.jar;lib/RXTXcomm.jar;lib/trace.jar;lib/xercesImpl.jar;lib/xml-apis.jar
java -cp "$/prog1_newOption/src/main/Main" %UsersCommand%
pause
exit
%cmd%
Maybe have I to look for the main path in the .bat file and then parse it the the "java command programm" line?
Thank you so much for your help
I'm trying to run a jar file from a Windows command prompt. From what i can see all the code and dependencies are there. The code given to run this is :
java -Xms1280m -Xmx1280m -cp
"target/osm-0.2.2-neo4j-3.5.1.jar:target/dependency/*"
org.neo4j.gis.osm.OSMImportTool --skip-duplicate-nodes --delete --into
target/databases/map2 samples/map2.osm.bz2
The error returned is:
java could not find or load the main class
org.neo4j.gis.osm.OSMImportTool.
Have tried playing around with the path but no luck. Any suggestions how to make this work would be great.
Thanks
java -Xms1280m -Xmx1280m -cp "target/osm-0.2.2-neo4j-3.5.1.jar;target/dependency/*" org.neo4j.gis.osm.OSMImportTool --skip-duplicate-nodes --delete --into target/databases/map2 samples/map2.osm.bz2
replaced the colon with a semi colon
I've been reading up on this error but am now confused. I'm trying to run my java test file from the win7 cmd line but am getting that dreaded error cannot find class in classpath.
The script runs fine as a testNG file inside the Eclipse IDE but not from the cmd line.
My classpath dump:
C:\lib\selenium-java-2.37.0.jar;
C:\lib\selenium-server-standalone-2.37.0.jar;
C:\EclipseIDE\ProteinBar\bin;
C:\EclipseIDE\ProteinBar\src\com\proteinbar\staging;
C:\TestNG;
My cmd line test string:
java -cp C:\lib\*;C:\EclipseIDE\ProteinBar\bin org.testng.TestNG DeleteBillingAddress.xml
Thanks for any help...
it doesn't appear that the testng jars are on your classpath. I'm guessing they live under c:/testng so you'll want to add something to your -cp reflecting that.
You need to specify the jars individually, e.g.,
java -cp C:\lib\selenium-java-2.37.0.jar;C:\lib\selenium-server-standalone-2.37.0.jar;...
My code works fine in Eclipse, no build path errors or anything, however when I try to run my Java program from the command line, I get a classNotFound Exception on one of my inner classes. Not only do I not understand how I am getting this exception, but I am not even sure how to go about debugging it, since it looks and works fine in the IDE environment. Any help is appreciated!
Edit
I am writing a compiler for a subset of Java called J--, so I dont really want to get too into how it all works. But instead of calling javac HelloWorld.java I would call the equivalent j-- HelloWorld.java. javac works fine. You might say well the issue is with your code, but again it compiles and runs fine in Eclipse. So somewhere there seems to be a disconnect. Here is the Windows bash script if it helps:
set BASE_DIR=%~dp0
set j="%BASE_DIR%\..\"
set JAVA=java
set CPATH="%BASE_DIR%\..\lib\j--.jar;%BASE_DIR%\..\lib\spim.jar"
if "%CLASSPATH%" == "" goto runApp
set CPATH=%CPATH%;"%CLASSPATH%"
:runApp
%JAVA% -classpath %CPATH% jminusminus.Main "j--" %*
set JAVA=
set BASE_DIR=
set CPATH=
Edit
Thanks to Aubin, outputting the .jar file and comparing that with the class not found was how I was able to solve this conflict.
Usually Eclipse takes the sources from src and produces classes file into bin.
Try:
java -cp bin a.b.c.d.MyClass
To call your tool as j-- <args> you need to write a shell which embed the command:
java -cp bin a.b.c.d.MyClass $*
I made a program which runs fine on windows. When I moved it over to CentOS, I got this error:
Error: Could not find or load main class org.wbc.WBCController
This is the file setup and .sh on linux:
And this is the file setup and .bat on windows:
Does anybody know what the problem is, and how I can fix it?
Java will respond with this error even if it cannot find the file wbc.jar. I am guessing that that is your problem. You might want to see that your are executing the shell script from within the right working directory.
Check to see if you can run wbc.sh from the console or put this in wbc.sh to make sure it searches for the jar in the same directory as the shell script:
#!/bin/sh
java -cp `dirname $0`/wbc.jar org.wbc.WBCController