可执行的JAR和放大器;蚂蚁 [英] Executable JAR & Ant

查看:176
本文介绍了可执行的JAR和放大器;蚂蚁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的第一次一个可执行的JAR一个Ant build.xml文件,并很为难,以什么我需要在JAR包括

I'm writing an Ant build.xml file for an executable JAR for the first time, and am stumped as to what I need to include in the JAR.

该项目可以被认为正在由下列人员组成:

The project can be thought of being composed of the following:


  1. 源$ C ​​$ C

  2. 依赖JAR的少数

  3. 通过的ClassPathXmlApplicationContext为国际奥委会Spring配置文件(XML)

下面是我的问题:因为这是一个可执行的JAR,我应该不和谐了所有的依赖JAR文件为好,或者我应该让他们分开?我怀疑我需要包括他们在JAR,如果这是真的,你会最佳实践要求组织我的JAR?

Here's my question: since this is an executable JAR, should I be JARring up all the dependency JARs as well, or should I keep them separate? I suspect I need to include them in the JAR, and if this is true, what would best practices dictate for organizing my JAR?

这是我第一次尝试:

MyExecutableJARProgram.jar/
    META-INF/
        ...
    com/
    lib/
    config/

其中, COM / 是我的顶级包,的lib / 是一个目录房屋所有这些相关性,和配置/ 保存所需的XML文件。

Where com/ is my top-level package, lib/ is a directory housing all of these dependencies, and config/ holds the required XML files.

(1)有什么想法?

此外,作为一个侧面的问题,因为JAR文件会比我的Eclipse项目不同的目录结构,我需要好歹(所以它知道要查找在设置CLASSPATH为我的JAR,比方说,的lib / 对于它的依赖),以及指定到哪里寻找我的Spring XML文件。

Also, as a side question, since the JAR file will have a different directory structure than my Eclipse project, I need someway of setting up the classpath for my JAR (so it knows to look in, say, lib/ for its dependencies), as well as specifying where to look for my Spring XML file.

(2)如何在JAR配置此 - manifest文件必须有某种方式来配置清单(或任何为这个问题的答案)通过蚂蚁,所以我的文件不需要每次我建造时间手工编辑JAR。

(2) How do I configure this in the JAR - the manifest file? There must be some way to configure the manifest (or whatever is the answer to this question) file through Ant so I don't need to manually edit the JAR every time I build.

感谢任何投入!

推荐答案

除非你愿意写一个定制ClassLoader,该清单类路径不支持嵌套JAR文件。相反,一个典型的方法是放在同一个(或知名)目录中的任何第三方二进制文件和你的JAR文件,并指使用清单类路径彼此。请记住,在清单类路径条目是相对于主缸。

Unless you are willing to write a custom classloader, the manifest classpath does not support nested JARs. Instead, a typical approach is to place any third party binaries and your JARs in the same (or well known) directory, and refer to one another using manifest classpaths. Remember that that entries in the manifest classpath are relative to the main jar.

有那么一段不平凡的项目,你的发行布局可能如下:

So for some non-trivial project, your distribution layout may look like:

[apphome]
  +-- bin
        +-- command1.sh / .bat  (to supply -Xmx etc)
        +-- command2.sh / .bat
            ...
  +-- lib
        +-- module1.jar
        +-- module2.jar
            ...
        +-- command1.jar (manifest cp contains modules, 3rd party, main-class)
        +-- command2.jar
            ...
  +-- deps
        +-- 3rdparty1.jar
        +-- 3rdparty2.jar
             ...

这篇关于可执行的JAR和放大器;蚂蚁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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