English 中文(简体)
How do I build an applet which needs an external jar, using ant?
原标题:

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 SettingsmcgearyworkspaceNew_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>
问题回答

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.

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.

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





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签