简体   繁体   中英

Java - classNotFound Exception from Windows command line but not Eclipse

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 $*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM