从XML文件添加类路径

时间:2015-12-23 18:10:36

标签: java

如何将此XML文件添加到classpath?

命令行

# java -classpath . dk.firma.klient.webservice.OiosiRaspClient

的.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
    <classpathentry kind="lib" path="lib/axis2/transport/axis2-transport-base-1.0-SNAPSHOT.jar"/>
    <classpathentry kind="lib" path="lib/axis2/transport/axis2-transport-mail-1.0-SNAPSHOT.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-adb-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-adb-codegen-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-ant-plugin-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-clustering-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-codegen-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-corba-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-fastinfoset-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-java2wsdl-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-jaxbri-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-jaxws-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-jibx-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-json-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-kernel-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-metadata-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-mtompolicy-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-spring-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-saaj-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-transport-http-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-transport-local-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axis2-xmlbeans-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/apache_commons/collections/commons-collections-3.2.1.jar"/>
    <classpathentry kind="lib" path="lib/apache_commons/configuration/commons-configuration-1.6.jar"/>
    <classpathentry kind="lib" path="lib/apache_commons/jxpath/commons-jxpath-1.3.jar"/>
    <classpathentry kind="lib" path="lib/apache_commons/lang/commons-lang-2.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/activation-1.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axiom-api-1.2.8.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axiom-dom-1.2.8.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/axiom-impl-1.2.8.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/bcel-5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/commons-codec-1.3.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/commons-fileupload-1.2.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/commons-httpclient-3.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/commons-io-1.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/commons-lang-2.3.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/commons-logging-1.1.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/geronimo-annotation_1.0_spec-1.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/geronimo-jaxws_2.1_spec-1.0.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/geronimo-stax-api_1.0_spec-1.0.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/geronimo-saaj_1.3_spec-1.0.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/geronimo-ws-metadata_2.0_spec-1.1.2.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/httpcore-4.0.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/jalopy-1.5rc3.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/jaxb-api-2.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/jaxb-impl-2.1.7.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/XmlSchema-1.4.3.jar"/>
    <classpathentry kind="lib" path="lib/axis2/mercury/mercury-core-0.91.jar"/>
    <classpathentry kind="lib" path="lib/axis2/mercury/mercury-persistence-0.91.jar"/>
    <classpathentry kind="lib" path="lib/axis2/rampart/opensaml-1.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/rampart/rampart-core-1.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/rampart/rampart-policy-1.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/rampart/rampart-trust-1.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/rampart/wss4j-1.5.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/rampart/xmlsec-1.4.1.jar"/>
    <classpathentry kind="lib" path="lib/backports/backport-util-concurrent.jar"/>
    <classpathentry kind="lib" path="lib/openuddi/openuddi-client-1.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/jaxb-xjc-2.1.7.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/jaxen-1.1.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/jettison-1.0-RC2.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/jibx-bind-1.2.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/jibx-run-1.2.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/log4j-1.2.15.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/mail-1.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/mex-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/neethi-2.0.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/smack-3.0.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/smackx-3.0.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/soapmonitor-1.5.1.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/woden-api-1.0M8.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/woden-impl-dom-1.0M8.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/wsdl4j-1.6.2.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/wstx-asl-3.2.4.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/xalan-2.7.0.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/xercesImpl-2.6.2.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/xml-apis-1.3.02.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/xmlbeans-2.3.0.jar"/>
    <classpathentry kind="lib" path="lib/axis2/core/xml-resolver-1.2.jar"/>
    <classpathentry kind="lib" path="lib/bouncycastle/bcpkix-jdk15on-147.jar"/>
    <classpathentry kind="lib" path="lib/bouncycastle/bcprov-jdk15on-147.jar"/>
    <classpathentry kind="lib" path="lib/nemhandel/dk.gov.oiosi.library-2.1.0.21718.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

1 个答案:

答案 0 :(得分:5)

你不能按照你想要的方式去做。您不能直接在命令行中添加.classpath文件(我猜是由eclipse生成)。您需要使用ant,maven或gradle等外部工具来完成工作。或者您可以手动添加主jar的MANIFEST文件中列出的所有依赖项。

编辑:使用Ant的解决方案

1 - 打开build.xml文件

2-Add Path元素:

<path id="dep.runtime">
    <fileset dir="paht/to/external/dependency/dir"    includes="**/*.jar"/>
</path>

路径元素是一种抽象用途,用于描述项目所需的库。因此,它必须反映.classpath文件的依赖项kind =“lib”。在你的情况下,我给你开始你的道路,并希望它将帮助你了解它是如何工作的。如果不是谷歌是你的朋友。

<path id="dep.runtime">
        <fileset dir="lib/axis2/core"  includes="**/*.jar"/>
        <fileset dir="lib/axis2/rampart"  includes="**/*.jar"/>
        <fileset dir="lib/axis2/transport"  includes="**/*.jar"/>
        <fileset dir="lib/apache_commons"  includes="**/*.jar"/>
        <fileset dir="lib/axis2/mercury" includes="**/*.jar"/>
        <!--you need to complete this list by inspiring you of those examples -->
</path>

3 - 在目标调用“jar”中添加一个Jar元素,这取决于负责编译java文件的目标。

<target name="jar" depends="compile">

<!-- This element will write inside the manifest file all your dependencies needed to execute your project.-->
    <manifestclasspath property="manifest_cp" jarfile="myProject.jar" maxParentLevels="10">

<!-- This is the reference to your classpath description inside element path -->
        <classpath refid="dep.runtime" />
    </manifestclasspath>

    <jar jarfile="myProject.jar" basedir="./src">
        <manifest>
            <attribute name="Main-Class" value="dk.firma.klient.webservice.OiosiRaspClient"/>
            <attribute name="Class-Path" value="${manifest_cp}"/>
        </manifest>

    </jar>
</target>

4 - 使用ant启动build.xml(确保ant使用名为“jar”的目标)。通常,如果一切顺利,它会生成一个名为myProject.jar的jar。如果使用zip工具打开它,您将看到META-INF / MANIFEST.MF文件。在其中,有一个类路径行,其中列出了所有依赖项。

5 - 键入命令行java -jar myProject.jar

如果一切顺利,它将启动你的程序。