在eclipse中为android项目创建jar

时间:2012-07-02 06:21:39

标签: java android eclipse jar

大家好我怎样才能创建使用eclipse在android中创建的项目的jar文件。我这样做了项目 - >右键单击 - >导出 - >选择构建器 - > antbuilder - >确定然后在此过程之后将创建 build.xml 。在bulid.xml上,我将创建新的构建器。

  • 右键点击项目 - >属性 - >选择new - >给build.xml和项目路径,然后按“确定”,将创建新的构建器。
  • 现在从项目属性中选择该构建器,然后按确定。
  • 现在构建您的项目,您的jar将在bin文件夹中创建。

我已经按照上面的过程但在bin文件夹中找不到我的jar。我可以看到我的build.xml已创建,所有进程都顺利但仍未创建jar。谁能告诉我怎么能这样做?

我的build.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="testtttttttttt">
    <property environment="env"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.6"/>
    <property name="source" value="1.6"/>
    <path id="Android 2.2.libraryclasspath">
        <pathelement location="C:/Program Files (x86)/Android/android-sdk/platforms/android-8/android.jar"/>
    </path>
    <path id="com.android.ide.eclipse.adt.LIBRARIES.libraryclasspath"/>
    <path id="testtttttttttt.classpath">
        <pathelement location="bin/classes"/>
        <path refid="Android 2.2.libraryclasspath"/>
        <path refid="com.android.ide.eclipse.adt.LIBRARIES.libraryclasspath"/>
    </path>
    <target name="init">
        <mkdir dir="bin/classes"/>
        <copy includeemptydirs="false" todir="bin/classes">
            <fileset dir="src">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="bin/classes">
            <fileset dir="gen">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="bin/classes"/>
    </target>
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin/classes" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="testtttttttttt.classpath"/>
        </javac>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin/classes" source="${source}" target="${target}">
            <src path="gen"/>
            <classpath refid="testtttttttttt.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
    <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
        <copy todir="${ant.library.dir}">
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </copy>
        <unzip dest="${ant.library.dir}">
            <patternset includes="jdtCompilerAdapter.jar"/>
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </unzip>
    </target>
    <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>
    </target>
</project>

2 个答案:

答案 0 :(得分:26)

在Eclipse中,选择项目,右键单击项目,选择Export,从中选择Jar。然后按照简单向导将目标放在要保存jar的位置,然后完成。你可以在那里找到你的罐子。 enter image description here

答案 1 :(得分:1)

步骤1.按照here的说明创建Android库项目。

步骤2.现在,您需要将步骤1中创建的Android库项目引用到您的客户端应用程序。有两种方法可以做到这一点。

•通过客户端应用程序提供Android库项目本身的参考    property - &gt;在左侧窗格中选择“Android” - &gt;在Libraty部分,添加    Android Libraty项目(这在第1步中给出的链接中进行了解释    上面)

•提供Android Library项目的.jar文件的引用    (来自Android Library项目的位置 - &gt; bin - &gt; .jar文件)。    客户申请 - &gt;属性 - &gt;单击lefe中的“Java Build Path”    窗格 - &gt;转到“图书馆”标签 - &gt;单击“添加外部JAR”按钮和    选择.jar文件 - &gt;转到“订购和导出”选项卡,然后选择    添加.jar文件引用并将其移至顶部。

希望这会对你有所帮助

相关问题