Java和Batch不希望加载主类

时间:2014-02-03 22:16:03

标签: java batch-file

@echo off
title Windows
color a

set mainclass="Interface"

:start
if exist "%HOMEDRIVE%/Program Files (x86)/Java/jre7/bin/"  goto x64(J7)
if exist "%HOMEDRIVE%/Program Files/Java/jre7/bin/" goto x86(J7)

if exist "%HOMEDRIVE%/Program Files (x86)/Java/jre6/bin/"  goto x64(J6)
if exist "%HOMEDRIVE%/Program Files/Java/jre6/bin/" goto x86(J6)
if defined java goto :x121

:x121
CLS
java -Xmx1024m %mainclass%
pause
exit

:x64(J6)
CLS
"%HOMEDRIVE%/Program Files (x86)/Java/jre6/bin/java.exe" -Xmx1024m %mainclass%
pause
exit


:x86(J6)
CLS
"%HOMEDRIVE%/Program Files/Java/jre6/bin/java.exe" -Xmx1024m %mainclass%
pause
exit

:x64(J7)
CLS
"%HOMEDRIVE%/Program Files (x86)/Java/jre7/bin/java.exe" -Xmx1024m %mainclass%
pause
exit

:x86(J7)
CLS
"%HOMEDRIVE%/Program Files/Java/jre7/bin/java.exe" -Xmx1024m %mainclass%
pause
exit

此问题仅在此程序中出现。每当我尝试通过这个批处理脚本加载我的java程序时,它从一开始就一直工作,它给了我一个“无法找到或加载主类”的错误。有人请告诉我我做错了什么,因为我刚刚用不同的java文件测试了这段代码而不是5分钟前它已经有用了。

1 个答案:

答案 0 :(得分:0)

通过取消'package InterfacePackage;'解决问题在java文件的顶部。我重新编译然后它工作正常。