如何包括依赖项目和分离罐分成两罐子? [英] How to include dependent project and splitting jar into two jars?

查看:169
本文介绍了如何包括依赖项目和分离罐分成两罐子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次我写在这里,所以我希望我做的一切权利。

It is my first time I'm writing here, so I'm hoping that I'm making everything right.

我有一个Java应用程序,我们称之为A.此应用程序依赖于另一个项目B(构建路径所需的项目)。该项目结构如下所示:

I have a Java application, let's call it A. This application depends on another project B (required project on the build path). The project structure looks as follows:

CommonFolder /项目B

CommonFolder/Project B

 -- src

 -- lib

 build.xml

CommonFolder /子文件夹/项目A

CommonFolder/subfolder/Project A

 -- src

 -- lib

 -- config

 build.xml

在项目B中的build.xml运作良好,并创建一个文件夹DIST一个jar文件。现在,在项目A build.xml文件应首先从项目B调用build.xml文件,然后它应该创建jar文件。不知怎的,这是行不通的。如果我刚刚从B项目的jar文件复制到项目A的lib文件夹它的工作原理,但我不想手动完成。

The build.xml in Project B works well and create a jar file in a dist folder. Now in Project A the build.xml file should first call build.xml from Project B and then it should create the jar file. Somehow this does not work. If I just copy the jar file from Project B into the lib folder of Project A it works but I don't want to do this manually.

我的第二个问题是项目A的最后一个jar文件将是pretty大,因为有lib文件夹中有很多库。我想的jar文件拆分成两个文件:libraries.jar(也含B项目的依赖)和application.jar。当application.jar启动它应该使用libraries.jar(在同一文件夹两个罐子)。这样做的好处是,我只需要上传application.jar这是小得多(如果我不改变库)。

My second problem is that the final jar file of project A will be pretty big because there are a lot of libraries in the lib folder. I would like to split the jar file into two files: libraries.jar (also containing the dependency from project B) and application.jar. When application.jar is started it should use libraries.jar (both jars in the same folder). The benefit is that I only have to upload application.jar which is much smaller (if I don't change the libraries).

如何才能做到这一点?

我期待着答案。

下面都的build.xml文件。

Here are both build.xml files.

项目B

<?xml version="1.0" encoding="UTF-8" standalone="no"?>  
<project default="complete build" name="Create runnable jar file">  
    <property name="src.dir" location="src" />  
    <property name="lib.dir" location="lib" />  
    <property name="build.dir" location="bin" />  
    <property name="dist.dir" location="dist" />  
    <property name="build.sysclasspath" value="last" />  

    <path id="project-classpath">  
        <fileset dir="${lib.dir}" includes="*.jar" />  
    </path>  

    <target name="remove release">  
        <delete dir="${dist.dir}" />  
    </target>  

    <target name="clean build">  
        <delete dir="${build.dir}" />  
    </target>  

    <target name="compile" depends="clean build">  
        <mkdir dir="${build.dir}" />  
        <javac srcdir="${src.dir}" destdir="${build.dir}" debug="on" target="1.8" source="1.8">  
            <classpath refid="project-classpath" />  
            <compilerarg value="-Xlint:none" />  
        </javac>  
    </target>  

    <target name="build jar" depends="remove release, compile">  
        <mkdir dir="${dist.dir}" />  
        <jar destfile="${dist.dir}/projectA.jar">  
            <fileset dir="${build.dir}" />  
            <zipgroupfileset dir="lib" excludes="META-INF/**" includes="*.jar"/>  
        </jar>  
        <antcall target="clean build" />  
    </target>  

    <target name="complete build" depends="build jar, clean build" />  
</project> 

A计划
结果
结果
    结果
    结果
    结果
    结果
    结果
    结果
      

Project A







<path id="project-classpath">  
    <fileset dir="${lib.dir}" includes="*.jar" />  
</path>  

<target name="remove release">  
    <delete dir="${dist.dir}" />  
</target>  

<target name="clean build">  
    <delete dir="${build.dir}" />  
</target>  

<target name="clean docs">  
    <delete dir="${docs.dir}" />  
</target>  

<target name="build-deps">  
    <ant antfile="../../ProjectB/build.xml" target="complete build"/>  
</target>  

<target name="compile" depends="clean build, build-deps">  
    <mkdir dir="${build.dir}" />  
    <javac srcdir="${src.dir}" destdir="${build.dir}" debug="on" target="1.8" source="1.8">  
        <classpath refid="project-classpath" />  
        <compilerarg value="-Xlint:none" />  
    </javac>  
</target>  

<target name="docs" depends="clean docs, compile">  
    <mkdir dir="${docs.dir}" />  
    <javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">  
        <fileset dir="${src.dir}">  
            <include name="**" />  
        </fileset>  
    </javadoc>  
</target>  

<target name="build jar" depends="remove release, compile">  
    <mkdir dir="${dist.dir}" />  
    <jar destfile="${dist.dir}/ProjectA.jar">  
        <manifest>  
            <attribute name="Main-Class" value="something.main.Main" />  
            <attribute name="Class-Path" value="." />  
        </manifest>  

        <fileset dir="${build.dir}" />  
        <zipfileset dir="config" />  
        <zipgroupfileset dir="lib" excludes="META-INF/**" includes="*.jar"/>  
    </jar>  
    <antcall target="clean build" />  
</target>  

<target name="complete build" depends="docs, build jar, clean build" />  

推荐答案

以下的答案介绍了如何使用Apache常春藤来处理和管理多模块项目构建一个具有相互依存关系:

The following answer describes how to use Apache ivy to handle and manage multi-module project builds that have interdependencies:

  • How to import properties and targets from ant build file properly?

它演示了以下内容:

  • Each module can be built independently using cached files
  • Module build order is determined using the ivy buildlist task
  • The ivy buildnumber task is used to auto generate the release numbers
  • The ANT manifestclasspath task can be used to create an executable jar with the list of dependent jars.

希望帮助

这篇关于如何包括依赖项目和分离罐分成两罐子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆