我想執行一個jar文件StartupUtil.jar,但它給出了無法找到並加載主類的錯誤。我看着其他類似的問題,並試圖但無法弄清楚什麼是錯的。捆綁可執行jar文件 - 找不到主類
我給創建StartupUtil.jar結構是
- > com.ihc.startup.util.StartupService
- > META-INF/MANIFEST.MF
清單的內容是:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.2
Created-By: 1.7.0_79-b15 (Oracle Corporation)
Main-Class: com.ihc.startup.util.StartupService
Class-Path: C:\Users\tgupta12\workspace_new\IHC_Startup\lib\bson-3.0.1
.jar C:\Users\tgupta12\workspace_new\IHC_Startup\lib\mongodb-driver-3
.0.1.jar C:\Users\tgupta12\workspace_new\IHC_Startup\lib\mongodb-driv
er-core-3.0.1.jar C:\Users\tgupta12\workspace_new\IHC_Startup\classes
這裏是我的build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="Startup" default="build" basedir=".">
<property file="./build.properties" />
<path id="lib-classpath">
<fileset dir="${libApp.dir}">
<include name="*.jar"/>
</fileset>
<pathelement path="${bin.dir}"/>
</path>
<target name="build" description="Compile main source tree java files">
<echo message=" Build Startup Utility" />
<mkdir dir="${bin.dir}"/>
<echo message=" Compiling source files" />
<javac destdir="${bin.dir}" source="${versionJDK}" target="${versionTarget}" debug="true"
deprecation="false" optimize="false" failonerror="true" includeantruntime="false">
<src path="${src.dir}"/>
<classpath refid="lib-classpath"/>
</javac>
<echo message=" ...Compilation of source files OK" />
<echo message=" Generating JAR for Startup - StartupUtility.jar" />
<delete file="${out.dir}/${startup-util-name}" />
<!-- convert classpath to a flat list/string -->
<pathconvert property="lib.classpath" pathsep=" ">
<path refid="lib-classpath" />
<!--<flattenmapper />-->
</pathconvert>
<jar destfile = "${out.dir}/${startup-util-name}" basedir = "${bin.dir}" includes = "**/*">
<manifest >
<attribute name="Class-Path" value="${lib.classpath}" />
<attribute name="Main-Class" value="com.ihc.startup.util.StartupService"/>
</manifest>
</jar>
<echo message=" ...JAR Created for Startup" />
</target>
<target name="run" depends="build">
<java jar="${out.dir}/${startup-util-name}" fork="true"/>
</target>
下面是我的build.properties文件:
#Directories
build.dir=build
src.dir=src
libApp.dir=lib
out.dir=out
web.dir=WebContent/WEB-INF
bin.dir=classes
webcontent.dir=WebContent
#File Name
war-file-name=StartupService.war
startup-util-name=StartupUtil.jar
#Target Properties
versionJDK=1.7
versionTarget=1.7
當它試圖執行目標來看,它給人
錯誤:無法找到或加載主類com.ihc.startup .util.StartupService
那麼*這個類是否存在?它在jar文件中嗎? –
是的,它存在於它的src目錄下,並且包com.ihc.startup.util。當我提取jar並檢查它存在於com/ihc/startup/util/StartupService.class時,它存在於jar文件中 –
它僅啓動,我犯了一個錯字錯誤 –