使用ant或命令行导入库

时间:2016-08-18 11:49:17

标签: java android

我正在研究我需要导入的android蓝牙 " appcompact-v7库位于我的android-sdk \ extras \ android \ m2repository \ com \ android \ support \ appcompat-v7"夹 有人可以帮我如何在/ libs文件夹和.java代码中导入库吗?

我没有使用任何IDE,我的操作系统是Windows

1 个答案:

答案 0 :(得分:0)

In project root folder add ivy.xml
<ivy-module version="2.0">
    <info organisation="BCT" module="Build Process" />
    <dependencies>
        //your jar file from ivy    
    </dependencies>
</ivy-module>


In project root folder build.properties
# Only required is ANT should deploy in an Available TomEE Container
tomcat.home = C:/Abhijit/Server/billinservertomee

# These are internal properties and do not need any change
project.webdir = .
project.lib = ./WebContent/WEB-INF/lib
project.webinf = ./WebContent/WEB-INF
project.build.baseline = C:/
project.war.name = project.war
project.name = projectname

In project root folder add ivysettings.xml
<ivysettings>
    <property name="ivy.local.default.root" value="${ivy.default.ivy.user.dir}/local"
        override="false" />
    <property name="ivy.local.default.ivy.pattern"
        value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
        override="false" />
    <property name="ivy.local.default.artifact.pattern"
        value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
        override="false" />

    <settings defaultResolver="chain" />
    <resolvers>
        <chain name="chain">
            <ibiblio name="public" m2compatible="true" />
        </chain>
    </resolvers>
</ivysettings>

In project root folder add build.xml
<?xml version="1.0" ?>
<project name="Build Process" default="war" xmlns:ivy="antlib:org.apache.ivy.ant">

    <!-- read valuable properties from build.properties -->
    <property file="${basedir}/build.properties" />

    <target name="init">
        <tstamp>
            <format property="init.time" pattern="yyyy-MM-dd_HH.mm" />
        </tstamp>
        <echo message="================================================================================" />
        <echo message="|| Build Process Started: ${init.time} " />
        <echo message="|| ANT Version: ${ant.version}" />
        <echo message="|| Java Version: JAVA ${java.version}" />
        <echo message="|| Project Default Target: ${ant.project.default-target}" />
        <echo message="|| Generated WAR Name: ${project.war.name}" />
        <echo message="================================================================================" />
    </target>

    <!-- Dependency resolved with apache ivy -->
    <target name="resolvejar" depends="init">
        <ivy:settings file="ivysettings.xml" />
        <ivy:retrieve type="bundle,jar" pattern="WebContent/WEB-INF/lib/[artifact]-[type]-[revision].[ext]" />
    </target>

    <!-- add .jar files in classpath -->
    <path id="compile.classpath">
        <fileset dir="${project.lib}">
            <include name="*.jar" />
        </fileset>
    </path>

    <!-- Make folders build/classes, dist and a backup folder with datetimestamp -->
    <target name="starting" depends="resolvejar">
        <tstamp>
            <format property="start.time" pattern="yyyy-MM-dd_HH.mm" />
        </tstamp>
        <echo message="After Resolve jar: ${start.time}" />
        <mkdir dir="${project.webdir}/build/classes" />
        <mkdir dir="${project.webdir}/dist" />
    </target>

    <!-- Compile .java files from src folder and put generated .class files in build/classes -->
    <target name="compile" depends="starting">
        <javac destdir="${project.webdir}/build/classes" debug="true" srcdir="${project.webdir}/src">
            <classpath refid="compile.classpath" />
        </javac>
    </target>

    <!-- Make WAR using class files, lib and content in the WebContent folder -->
    <target name="war" depends="compile">
        <!-- Deleting API jar to avoid conflict with App Server bundled version -->
        <delete file="WebContent/WEB-INF/lib/javaee-api-jar-6.0.jar" />


        <war destfile="${project.webdir}/dist/${project.war.name}" webxml="${project.webdir}/WebContent/WEB-INF/web.xml">
            <fileset dir="${project.webdir}/WebContent">
                <!-- include files of WebContent with following extention only -->
                <include name="**/*.xhtml" />
                <include name="**/*.html" />
                <include name="**/*.md" />
                <include name="**/*.MF" />
                <include name="**/*.properties" />
                <include name="**/*.xml" />
                <include name="**/*.js" />
                <include name="**/*.gif" />
                <include name="**/*.png" />
                <include name="**/*.jpg" />
                <include name="**/*.css" />
                <include name="**/*.ini" />
                <include name="**/server-config.wsdd" />
                <include name="**/*.class" />
                <include name="**/*.rptdesign" />
                <include name="**/*.jsp" />
                <include name="**/*.sql" />
                <include name="**/*.ico" />
                <include name="**/*.json" />
                <include name="**/*.eot" />
                <include name="**/*.svg" />
                <include name="**/*.ttf" />
                <include name="**/*.woff" />
                <include name="**/*.woff2" />
                <include name="**/*.default" />
                <include name="**/*.txt" />
            </fileset>
            <fileset dir="${project.webdir}">
                <!-- include files of WebContent with following extention only -->
                <include name="CHANGELOG**" />  
                <include name="contrib/**" />
            </fileset>
            <lib dir="${project.lib}" />
            <classes dir="${project.webdir}/build/classes" />
        </war>
        <tstamp>
            <format property="end.time" pattern="yyyy-MM-dd HH:mm" />
        </tstamp>
        <echo message="WAR Created Successfully: ${end.time}" />
    </target>

    <!-- Deploy the WAR file in TomEE's apps profile -->
    <target name="deploy" depends="war, cleandeploy, undeploy">
        <copy file="${project.webdir}/dist/${project.war.name}" todir="${tomcat.home}/webapps" />
        <tstamp>
            <format property="end.time" pattern="yyyy-MM-dd HH:mm" />
        </tstamp>
        <echo message="WAR Deploy Successfully: ${end.time}" />
    </target>

    <!-- Create a back up of the WAR file in a current date-time folder(yyyy-MM-dd_hh.mm) of a specific path defined in build.properties file -->
    <target name="baseline" depends="war">
        <mkdir dir="${project.build.baseline}/${start.time}" />
        <copy file="${project.webdir}/dist/${project.war.name}" todir="${project.build.baseline}/${start.time}" />

        <tstamp>
            <format property="end.time" pattern="yyyy-MM-dd HH:mm" />
        </tstamp>
        <echo message="Base Line Created Successfully: ${end.time}" />
    </target>

    <!-- It is similar as clean project of eclipse -->
    <target name="clean" depends="init">
        <delete quiet="yes">
            <fileset dir="${project.webdir}/WebContent/WEB-INF/classes">
                <include name="**/*.class" />
            </fileset>
        </delete>
        <delete dir="${project.webdir}/dist" />
        <delete dir="${project.webdir}/build" />

        <tstamp>
            <format property="end.time" pattern="yyyy-MM-dd HH:mm" />
        </tstamp>
        <echo message="Clean Project Successfully: ${end.time}" />
    </target>

    <!-- Undeploy(or remove) the WAR from TomEE's apps folder -->
    <target name="undeploy" depends="init">
        <delete file="${tomcat.home}/webapps/${project.war.name}" />
        <delete dir="${tomcat.home}/webapps/${project.name}" />
        <tstamp>
            <format property="end.time" pattern="yyyy-MM-dd HH:mm" />
        </tstamp>
        <echo message="Undeploy Project Successfully: ${end.time}" />
    </target>

    <!-- Delete folder content of temp, log and work of TomEE -->
    <target name="cleandeploy" depends="init">
        <delete file="${tomcat.home}/temp/*" />
        <delete file="${tomcat.home}/logs/*" />
        <delete file="${tomcat.home}/work/*" />
        <tstamp>
            <format property="end.time" pattern="yyyy-MM-dd HH:mm" />
        </tstamp>
        <echo message="Server Clean Before Deploy Successfully: ${end.time}" />
    </target>

    <!-- Help of different target -->
    <target name="help">
        <echo message="Target init: Echo start time, ant version, java version, project default target and generated war name" />
        <echo message="Target resolvejar: Dependency resolved with apache ivy" />
        <echo message="Target starting depends on resolvejar: Make folders build/classes and dist" />
        <echo message="Target compile depends on starting: Compile .java files from src folder and put generated .class files in build/classes" />
        <echo message="Target war depends on compile: Create a version.properties file which contains repository version in WEB-INF folder and make WAR using class files, lib and content in the WebContent folder" />
        <echo message="Target deploy depends on war: Deploy the WAR file in Tomcat's webapps profile" />
        <echo message="Target baseline depends on war: Create a back up of the WAR file in a current date-time folder(yyyy-MM-dd_hh.mm) of a specific path defined in build.properties file" />
        <echo message="Target clean: It is similar as clean project of eclipse(delete build, classes and dist folder)" />
        <echo message="Target undeploy: Undeploy(or remove) the WAR from Tomcat's webapps profile" />
        <echo message="Target cleandeploy: Delete folder content of temp, log and work of TomEE(Server clean before deploy)" />
    </target>

</project>


Go to the project root folder and open command prompt..
run command ant deploy

enter image description here enter image description here

mysqldump

enter image description here enter image description here