繁体   English   中英

捆绑的可执行jar文件-找不到主类

[英]bundled executable jar file - couldnot find main class

我正在尝试执行一个jar文件StartupUtil.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

我强烈怀疑问题在于找不到依赖项,这意味着它无法正确加载主类。 我以前从未看过清单中给出的绝对文件名,也不相信您是如何打破常规的(尽管这可能是有效的)。 鉴于使用绝对文件名非常难用,我强烈建议您只使用相对文件名。

将清单更改为:

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: bson-3.0.1.jar mongodb-driver-3.0.1.jar mongodb-driver-core-3.0.1.jar

然后将这些jar文件放在与StartupUtil.jar相同的目录中。

暂无
暂无

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

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