如何使用 ant 构建需要外部 jar 的小程序?

发布于 2024-08-10 10:48:54 字数 2003 浏览 2 评论 0原文

我写了一个java小程序,非常简单。单击按钮即可连接到 Oracle 数据库。它工作正常,当我使用 Eclipse 运行它时它可以连接。

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

这是我的 ant 构建文件。我需要的外部第 3 方 Jar 文件位于 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>

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.

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?

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>

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

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

发布评论

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

评论(3

忆梦 2024-08-17 10:48:54

将类路径中的文件(jar)列为相对位置(例如,简单地是 jar 的名称),然后将这些 jar 放在与小程序相同的目录中。
您在浏览器中使用小程序吗?或者用小程序查看器?
如果是使用浏览器,请尝试将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.

眼眸 2024-08-17 10:48:54

看看这个:http://marc.info/? l=ant-user&m=113147888530744&w=2

您拥有的内容类似,但存在一些差异,特别是 jar 所在目录的属性,以及如何将它们转换为类路径字符串。

Take a look at this: http://marc.info/?l=ant-user&m=113147888530744&w=2

What you have is similiar but there are some differences, specifically a property for the directory the jars are in, and how those are converted to classpath string.

痞味浪人 2024-08-17 10:48:54

C:/JarFiles 中还有更多子文件夹吗?如果是这样,文件集中的包含内容应为

Are there any more subfolders in C:/JarFiles? If so, the include in your fileset should be <include name="**/*.jar"/>

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