简体   繁体   中英

Adding jar file to add class in a java project using ant command line

I have looked for hours on the net but could not find an answer to the following question(s)... I have an android project that runs OK using "ant release" command line (for various reasons I cannot use Eclipse nor Android Studio, etc.) on MacOSX. I need to extend a 3rd-party class that consists in a jar file (called mididriver.jar). I added the following line in my main java source file :

import mididriver.*;

What do I need to add to my build.xml file and where should I put the mididriver.jar file in my project folder structure so that it does not give me a "package mididriver does not exist" error?

Many thanks (in advance) !

Here is the content of my build.xml which WORKS BEFORE I ADD the new class:

<project name="MyProject" default="debug">
  <loadproperties srcFile="local.properties"/>
  <loadproperties srcFile="project.properties"/>
  <target name="clean" depends="android_rules.clean">
    <delete dir="libs"/>
    <delete dir="obj"/>
    <exec executable="${ndk.dir}/ndk-build" dir="${basedir}" failonerror="true">
      <arg value="clean"/>
    </exec>
  </target>
  <target name="-pre-build">
    <condition property="makefileConfig" value="Debug" else="Release">
      <equals arg1="${ant.project.invoked-targets}" arg2="debug"/>
    </condition>
    <condition property="ndkDebugValue" value="NDK_DEBUG=1" else="NDK_DEBUG=0">
      <equals arg1="${ant.project.invoked-targets}" arg2="debug"/>
    </condition>
    <condition property="app_abis" value="armeabi-v7a" else="armeabi-v7a">
      <equals arg1="${ant.project.invoked-targets}" arg2="debug"/>
    </condition>
    <exec executable="${ndk.dir}/ndk-build" dir="${basedir}" failonerror="true">
      <arg value="--jobs=2"/>
      <arg value="CONFIG=${makefileConfig}"/>
      <arg value="${ndkDebugValue}"/>
      <arg value="APP_ABI=${app_abis}"/>
    </exec>
    <delete file="${out.final.file}"/>
    <delete file="${out.packaged.file}"/>
  </target>
  <import file="${sdk.dir}/tools/ant/build.xml"/>
</project>

Create a lib directory in your project

my-project
   src
   target
   lib

Put the jar into the lib directory.

Modify the javac task to add the lib directory to the classpath.

<path id="lib.dir">
    <fileset dir="./lib">
        <include name="**/*.jar"/>
    </fileset>
</path>

<javac srcdir="src" destdir="target/classes" >
   <classpath refid="lib.dir"/>
</javac>

I don't know which target does not work for you. Is it javac? Or ndk-build? I don't know how to specify class path for ndk-build. There must be some option like -classpath .

好吧,在尝试定义lib文件夹失败很多之后,我将jar文件放到了现有的libs文件夹中,现在成功构建了...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM