简体   繁体   中英

Error running java -jar command

I created a jar file using the following ANT script

<manifestclasspath property="jar.classpath" jarfile="${bin.dir}/${jar.app.name}" maxparentlevels="0">
    <classpath refid="main.class.path" />
</manifestclasspath>
<target name="jar">
    <mkdir dir="${build.dir}/lib/isp"/>
    <mkdir dir="${build.dir}/lib/jasper"/>
    <copy todir="${build.dir}/lib/jasper">
            <fileset dir="${lib.jasper.dir}">
                    <include name="**/*.jar" />
            </fileset>
    </copy>
    <copy todir="${build.dir}/lib/isp">
            <fileset dir="${lib.isp.dir}">
                    <include name="**/*.jar" />
            </fileset>
    </copy>
    <jar jarfile="${bin.dir}/${jar.app.name}"
            index="true"
            basedir="${classes.dir}" excludes="lib/mytest.jar "
            >
            <manifest>
                    <attribute name="Main-Class" value="${main.class}" />
                    <attribute name="Class-Path" value="${jar.classpath}" />
            </manifest>
    </jar>
</target>

The resulting jar file has the following MANIFEST.MF entry.

Main-Class: dm.jb.Main
Class-Path: lib/isp/OfficeLnFs_2.2.jar lib/isp/RXTXcomm.jar lib/isp/ba
rbecue-1.0.6d.jar lib/isp/commons-logging-1.1.jar lib/isp/forms-1.0.5
.jar lib/isp/gnujaxp.jar lib/isp/helpUI.jar lib/isp/inspInstaller.jar
 lib/isp/itext-2.0.1.jar lib/isp/itext-2.0.2.jar lib/isp/jcalendar-1.
3.2.jar lib/isp/jcl.jar lib/isp/jcommon-1.0.10.jar lib/isp/jcommon-1.
0.9.jar lib/isp/jdnc-0_7-all.jar lib/isp/jdnc-runner.jar lib/isp/jdom
.jar lib/isp/jfreechart-1.0.6.jar lib/isp/jlfgr-1_0.jar lib/isp/junit
.jar lib/isp/log4j-1.2.9.jar lib/isp/looks-1.3.2.jar lib/isp/msbase.j
ar lib/isp/mssqlserver.jar lib/isp/msutil.jar lib/isp/mysql-connector

When I try to run the command java -jar mytest.jar , it fails and throws error saying dm.jb.Main not found. But I could run the class by specifying the classpath java -classpath dm.jb.Main

Please help me DM

If you run your jar like this

java -jar <your jar name>

then java will ignore all classpath parameters you give and try to find it's resources with the given classpath inside the manifest. But these pathes point to your local file system and not inside the jar. So you have to start the jar in a directory where your libs can be found at lib/isp/...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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