如何在Netbeans的清单类路径中包含lib文件夹 [英] How to include the lib folder in the manifest classpath in Netbeans

查看:142
本文介绍了如何在Netbeans的清单类路径中包含lib文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的java应用程序使用的库需要在类路径中查找文件(log4j.xml)。我使用netbeans来管理我的项目,但我找不到包含lib /文件夹的方法。

A library that my java application uses needs looks for a file (log4j.xml) in the class path. I use netbeans to manage my project, but I can't find a way to include the lib/ folder.

Netbeans会自动在应用程序jar中创建一个MANIFEST.MF文件并创建一个名为lib /的文件夹,其中包含所有依赖项。此清单指定Class-Path属性,该属性覆盖命令行上提供的任何-cp参数。我可以在netbeans的库面板中选择一个任意文件夹,但它会在清单的类路径中创建一个子文件夹。我想要lib /文件夹中的所有依赖项和log4j.xml文件。

Netbeans automatically creates a MANIFEST.MF file inside the application jar and also creates a folder called lib/ which includes all dependencies. This manifest specifies a Class-Path attribute that overrides any -cp argument provided on the command line. I can select an arbitrary folder in netbeans' library panel, but it creates a sub folder in the manifest's classpath. I'd like all dependencies and the log4j.xml file inside the lib/ folder.

希望可以在IDE中执行此操作。我包含了自动生成的build-impl.xml文件的片段。

Hopefully it's possible to do this in the IDE. I include a snippet of the auto-generated build-impl.xml file.

<target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries">
    <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
    <pathconvert property="run.classpath.without.build.classes.dir">
        <path path="${run.classpath}"/>
        <map from="${build.classes.dir.resolved}" to=""/>
    </pathconvert>
    <pathconvert pathsep=" " property="jar.classpath">
        <path path="${run.classpath.without.build.classes.dir}"/>
        <chainedmapper>
            <flattenmapper/>
            <globmapper from="*" to="lib/*"/>
        </chainedmapper>
    </pathconvert>
    <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
    <copylibs compress="${jar.compress}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
        <fileset dir="${build.classes.dir}"/>
        <manifest>
            <attribute name="Main-Class" value="${main.class}"/>
            <attribute name="Class-Path" value="${jar.classpath}"/>
        </manifest>
    </copylibs>
    <echo>To run this application from the command line without Ant, try:</echo>
    <property location="${dist.jar}" name="dist.jar.resolved"/>
    <echo>java -jar "${dist.jar.resolved}"</echo>
</target>

谢谢。

推荐答案

我找到了一种方法来实现修改build-impl.xml。

I found a way to acheive this modifying the build-impl.xml.

我改变了:

<attribute name="Class-Path" value="${jar.classpath}"/>

to:

<attribute name="Class-Path" value="${jar.classpath} /lib"/>

问题是netbeans会覆盖它,因为这个文件是自动生成的。

The problem is that netbeans will overwrite it since this file is automatically generated.

这篇关于如何在Netbeans的清单类路径中包含lib文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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