[英]Error when using java -cp with jar file
I am trying to run a jar file using java -cp but it keeps giving me error that could not find or load main class. 我正在尝试使用java -cp运行一个jar文件,但它一直给我找不到或加载主类的错误。
Here is my bat file 这是我的蝙蝠文件
:: install.bat
:: run the installer jar as a windows bat file
::
@echo off
:: setup some properties
set CLASSES=.
set JAVA_OPTS=
:: build a basic classpath
set CP="%CLASSES%"
:: locate the java executable
set JAVA_EXE="%JAVA_HOME%\bin\java.exe"
IF EXIST "%JAVA_EXE%" GOTO start
set JAVA_EXE=java.exe
:start
:: show off java version info
echo -------------------------------------------------
"%JAVA_EXE%" -version
REM echo JAVA_OPTS: %JAVA_OPTS%
REM echo CLASSPATH: %CP%
echo -------------------------------------------------
:: start the program
%JAVA_EXE% %JAVA_OPTS% -cp %CP% - Djava.util.logging.config.file="./enr_logging.properties" com.company.product.package.MainClass
Assuming that my fully qualified class name is com.company.product.package.MainClass and the jar is in the same folder as the .bat file 假设我的完全合格的类名称为com.company.product.package.MainClass,并且jar与.bat文件位于同一文件夹中
Running a jar with -cp
requires the classpath to list the jar, for instance : 使用
-cp
运行jar需要类路径列出jar,例如:
java -cp "Test.jar;lib/*" my.pretty.MainClass
NB : Test.jar
can be replaced by *
to match all jars, but *.jar
won't work. 注意:
Test.jar
可以用*
替换以匹配所有jar,但是*.jar
将不起作用。
Alternatively, you can run the jar with -jar
. 或者,您可以使用
-jar
运行jar。 This method requires the classpath to be defined in the jar's manifest and silently ignores other classpath declarations. 此方法要求在jar的清单中定义类路径,并且静默忽略其他类路径声明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.