简体   繁体   English

Java-Windows命令行中的classNotFound异常,但Eclipse不存在

[英]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. 我的代码在Eclipse中运行良好,没有构建路径错误或其他任何问题,但是当我尝试从命令行运行Java程序时,我在一个内部类上收到classNotFound Exception 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. 我不仅不知道如何获取此异常,而且甚至不确定如何调试它,因为它在IDE环境中看起来和可以正常工作。 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. 我正在为称为J--的Java子集编写一个编译器,所以我真的不想完全了解它的工作原理。 But instead of calling javac HelloWorld.java I would call the equivalent j-- HelloWorld.java . 但是, javac HelloWorld.java调用javac HelloWorld.java而不是调用等效的j-- HelloWorld.java javac works fine. javac正常工作。 You might say well the issue is with your code, but again it compiles and runs fine in Eclipse. 您可能会很好地认为问题出在您的代码上,但是它再次编译并在Eclipse中运行良好。 So somewhere there seems to be a disconnect. 因此,某个地方似乎存在断开连接。 Here is the Windows bash script if it helps: 这是Windows bash脚本(如果有帮助的话):

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. 感谢Aubin,输出.jar文件并将其与class not foundclass not found进行比较是我能够解决此冲突的方法。

Usually Eclipse takes the sources from src and produces classes file into bin . 通常,Eclipse从src获取源代码并将类文件生成到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: 要将工具称为j-- <args>您需要编写一个嵌入命令的shell:

java -cp bin a.b.c.d.MyClass $*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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