Java小程序,将jar文件添加到manifest文件中

发布于 2024-08-22 18:18:06 字数 2576 浏览 1 评论 0原文

我正在做一些明显错误的事情。我有一个简单的小程序,需要将文件上传到服务器。我已经编写了一个 ant 脚本来构建 jar 文件。但是,manifest.mf 将类路径分为多行。

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Class-Path: lib/commons-codec-1.3.jar            lib/commons-httpclien
 t-3.1.jar            lib/commons-logging-1.0.4.jar            lib/plu
 gin.jar
Created-By: 14.3-b01-101 (Apple Inc.)

我的 build.xml 是:

<project name="ScreenShot" default="dist" basedir=".">
 <description>
        simple example build file
    </description>
 <!-- set global properties for this build -->
 <property name="src" location="src" />
 <property name="build" location="build" />
 <property name="dist" location="dist" />

 <target name="init">
  <!-- Create the time stamp -->
  <tstamp />
  <!-- Create the build directory structure used by compile -->
  <mkdir dir="${build}" />
 </target>

 <target name="compile" depends="init" description="compile the source ">


  <!-- Compile the java code from ${src} into ${build} -->
  <javac srcdir="${src}" destdir="${build}">
   <classpath>
    <pathelement path="${classpath}" />
    <pathelement path="lib/commons-codec-1.3.jar:lib/commons-httpclient-3.1.jar:lib/plugin.jar" />
   </classpath>

  </javac>
 </target>

 <target name="dist" depends="compile" description="generate the distribution">
  <!-- Create the distribution directory -->
  <mkdir dir="${dist}" />


  <copy todir="${build}/lib">
   <fileset dir="lib/" />
  </copy>

  <path id="libs.project">

   <!-- lib.home contains all jar files, in several subdirectories -->
   <fileset dir="lib">
    <include name="**/*.jar" />
   </fileset>
  </path>

  <manifestclasspath property="jar.classpath" maxParentLevels="1" jarfile="build/ScreenShot.jar">

   <classpath refid="libs.project" />
  </manifestclasspath>

  <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
  <jar jarfile="/Users/firemonk/red5/webapps/whiteboard/ScreenShot.jar" basedir="${build}">
   <manifest>
    <attribute name="Class-Path" value="${jar.classpath}" />
   </manifest>
  </jar>
 </target>



 <target name="clean" description="clean up">
  <!-- Delete the ${build} and ${dist} directory trees -->
  <delete dir="${build}" />
  <delete dir="${dist}" />
 </target>
</project>

I am doing some thing obvious wrong. I have a simple applet which needs to upload files to server. I have written an ant script to build the jar file. However, the manifest.mf has class-path split into multiple lines.

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Class-Path: lib/commons-codec-1.3.jar            lib/commons-httpclien
 t-3.1.jar            lib/commons-logging-1.0.4.jar            lib/plu
 gin.jar
Created-By: 14.3-b01-101 (Apple Inc.)

My build.xml is :

<project name="ScreenShot" default="dist" basedir=".">
 <description>
        simple example build file
    </description>
 <!-- set global properties for this build -->
 <property name="src" location="src" />
 <property name="build" location="build" />
 <property name="dist" location="dist" />

 <target name="init">
  <!-- Create the time stamp -->
  <tstamp />
  <!-- Create the build directory structure used by compile -->
  <mkdir dir="${build}" />
 </target>

 <target name="compile" depends="init" description="compile the source ">


  <!-- Compile the java code from ${src} into ${build} -->
  <javac srcdir="${src}" destdir="${build}">
   <classpath>
    <pathelement path="${classpath}" />
    <pathelement path="lib/commons-codec-1.3.jar:lib/commons-httpclient-3.1.jar:lib/plugin.jar" />
   </classpath>

  </javac>
 </target>

 <target name="dist" depends="compile" description="generate the distribution">
  <!-- Create the distribution directory -->
  <mkdir dir="${dist}" />


  <copy todir="${build}/lib">
   <fileset dir="lib/" />
  </copy>

  <path id="libs.project">

   <!-- lib.home contains all jar files, in several subdirectories -->
   <fileset dir="lib">
    <include name="**/*.jar" />
   </fileset>
  </path>

  <manifestclasspath property="jar.classpath" maxParentLevels="1" jarfile="build/ScreenShot.jar">

   <classpath refid="libs.project" />
  </manifestclasspath>

  <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
  <jar jarfile="/Users/firemonk/red5/webapps/whiteboard/ScreenShot.jar" basedir="${build}">
   <manifest>
    <attribute name="Class-Path" value="${jar.classpath}" />
   </manifest>
  </jar>
 </target>



 <target name="clean" description="clean up">
  <!-- Delete the ${build} and ${dist} directory trees -->
  <delete dir="${build}" />
  <delete dir="${dist}" />
 </target>
</project>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叫嚣ゝ 2024-08-29 18:18:06

检查${jar.classpath} 的值。看来它的价值本身就是多方面的。

Check the value of ${jar.classpath}. It seems its value itself is in multiple lines.

不…忘初心 2024-08-29 18:18:06

行不通吗?每个类路径条目之间都有很大的空格,这有点奇怪,但它看起来有效。

清单规范指出行的长度不得超过 72 个字节,并且较长的行应拆分并在下一行上以前导空格继续。

Does it not work? It's a bit odd that there are big spaces between each classpath entry but it looks valid.

The manifest specification states that lines must be no longer than 72 bytes and that longer lines should be split and continued on the next line with a leading space.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文