Java -jar command error

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 an error saying dm.jb.Main was not found. But I could run the class by specifying the classpath java -classpath dm.jb.Main

Please help me DM

+2


a source to share


1 answer


If you run your bank like this,

java -jar <your jar name>

      



then java will ignore all path class parameters you give and try to find it by resources with given path class inside manifest. But these fixes point to your local filesystem, not inside the jar. Therefore, you have to run the jar in the directory where your libraries can be found in lib / isp / ...

+1


a source







All Articles