【问题标题】:IntelliJ generated Ant build overwrites my MANIFEST.MFIntelliJ 生成的 Ant 构建覆盖了我的 MANIFEST.MF
【发布时间】:2015-12-05 14:44:48
【问题描述】:

我在 IntelliJ 中有一个简单的项目,我在其中转到 项目结构 -> 工件 -> 从具有依赖项的模块中添加 Jar -> 复制到输出目录并通过清单链接(清单放在 %ProjectDir%/资源/清单/META-INF/MANIFEST.MF) -> OK -> OK

现在,如果我运行make,jar 将放在out/artifacts 下,如果我查看 jar 内部并打开 META-INF/MANIFEST.MF 文件,它包含正确的 Class-Path 信息。如果我然后回到 IntelliJ,生成一个 ant 构建并运行它,编译后的 jar 中的 META-INF/MANIFEST.MF 的内容现在看起来像这样:

Manifest-Version: 1.0 Ant-Version: Apache Ant 1.9.4 Created-By: 1.7.0_80-b15 (Oracle Corporation)

如您所见,Class-Path 条目已被完全删除,这使我无法从其他地方使用该 jar。

所以我的问题是:有谁知道为什么 intellij 生成的 ant 构建会覆盖 intellij 中内置 makefunctionality 使用的 MANIFEST.MF?

我还可以补充一点,我生成了这个 ant 构建,因为我想做一些简单的事情,比如在编译后将构建的 jar 复制到不同的位置。

编辑

如果我在生成的 ant 脚本中手动将 <jar ... filesetmanifest="mergewithoutmain"> 更改为 <jar ... filesetmanifest="merge">,则至少原始 MANIFEST.MF 中的 Class-Path 会出现在复制到 jar 文件中的 MANIFEST.MF 中。但是,我真的很想避免以这种方式手动更改生成的 ant 脚本。

【问题讨论】:

    标签: java intellij-idea ant


    【解决方案1】:

    您需要使用 -m 选项。要查看可用 JAR 选项的列表,请键入不带参数的 jar,输出将提供参数列表和示例。在您的情况下,您可能需要修改一些 Ant 或 IntelliJ 命令以使用提供的 MANIFEST.MF 文件生成 JAR。

    Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
    Options:
        -c  create new archive
        -t  list table of contents for archive
        -x  extract named (or all) files from archive
        -u  update existing archive
        -v  generate verbose output on standard output
        -f  specify archive file name
        -m  include manifest information from specified manifest file
        -e  specify application entry point for stand-alone application
            bundled into an executable jar file
        -0  store only; use no ZIP compression
        -P  preserve leading '/' (absolute path) and ".." (parent directory) components from file names
        -M  do not create a manifest file for the entries
        -i  generate index information for the specified jar files
        -C  change to the specified directory and include the following file
    If any file is a directory then it is processed recursively.
    The manifest file name, the archive file name and the entry point name are
    specified in the same order as the 'm', 'f' and 'e' flags.
    
    Example 1: to archive two class files into an archive called classes.jar:
           jar cvf classes.jar Foo.class Bar.class
    Example 2: use an existing manifest file 'mymanifest' and archive all the
               files in the foo/ directory into 'classes.jar':
           jar cvfm classes.jar mymanifest -C foo/ .
    

    【讨论】:

    猜你喜欢
    • 2017-02-19
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-25
    • 2014-01-24
    相关资源
    最近更新 更多