如何使用 ant 构建需要外部 jar 的小程序? [英] How do I build an applet which needs an external jar, using ant?

查看:23
本文介绍了如何使用 ant 构建需要外部 jar 的小程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个非常简单的java小程序.单击按钮后,它连接到 oracle 数据库.它工作正常,当我使用 Eclipse 运行它时它会连接.

I have wrote a java applet which is pretty simple. It connects to a oracle database upon clicking a button. It works fine, it connects when I run it using Eclipse.

但是,当我使用 ant 创建 jar 文件时,我不知道如何将 ojdbc6.jar 作为类路径包含在内.我该怎么做?

However, when I use ant to create the jar file I don't know how to include the ojdbc6.jar as a classpath. How would I do this?

这是我的 ant 构建文件.我需要的外部 3rd 方 Jar 文件位于 C:\JarFiles.

Here is my ant build file. My external 3rd party Jar files that I need are in C:\JarFiles.

<project default="jar">
  <property name="build" value="build"/>
  <property name="java.home" value="C:\Program Files/Java/jdk1.6.0_10" />
  <property name="project.home" value="C:\Documents and Settings\bmcgeary\workspace\New_Holiday_Editor" />

  <property name="build.home" value="${project.home}/build" />

  <path id="files-classpath">  
    <fileset dir="c:/JarFiles" >  
      <include name="*.jar"/>  
    </fileset>  
  </path>  

  <!-- convert classpath to a flat list/string for use in manifest task -->
  <pathconvert property="files-classpath" pathsep=" ">
    <path refid="files-classpath" />
    <flattenmapper />
  </pathconvert>

  <manifest file="MANIFEST.MF">
    <attribute name="Built-By" value="${manifest.built.by}"/>
    <attribute name="Created-By" value="${manifest.created.by}"/>
    <attribute name="Main-Class" value="${manifest.main.class}"/>
    <attribute name="Implementation-Version" value="${version.number}-b${build.number}"/>   
    <attribute name="Class-Path" value="${files-classpath}" />
  </manifest>

  <target name="compile">
    <javac srcdir="." />
  </target>

  <target name="compileProject" description="compiles project Classes">  
    <echo>compiling the project classes</echo>  
    <javac srcdir="src" destdir=".">  
      <classpath>  
    <path refid="files-classpath" />  
      </classpath>  
    </javac>  
  </target> 

  <target name="jar" depends="compileProject" >
    <jar jarfile="myJar.jar"
     basedir="."
     index="true"
     manifest="MANIFEST.MF" />
  </target>


</project>

推荐答案

将类路径中的文件(jars)列出为相对位置(例如简单的jar名称),然后将这些jar放在同一个目录下作为小程序.您在浏览器中使用小程序吗?还是用appletviewer?如果是浏览器,请尝试将 archive 属性设置为 yourapplet.jar,ojdbc6.jar

List the files (jars) in the classpath as relative locations (simply the name of the jar, for example), and then place those jars in the same directory as the applet. Are you using the applet in browser? Or with appletviewer? If it is with browser, try setting the archive property to yourapplet.jar,ojdbc6.jar

并粘贴已生成的清单,可能有问题.

And paste the manifest that has been generated, there might be something wrong with it.

这篇关于如何使用 ant 构建需要外部 jar 的小程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆