我的 java 应用程序使用的库需要在类路径中查找文件 (log4j.xml)。我使用 netbeans 来管理我的项目,但我找不到包含 lib/ 文件夹的方法。
Netbeans 自动在应用程序 jar 中创建一个 MANIFEST.MF 文件,并创建一个名为 lib/ 的文件夹,其中包含所有依赖项。此清单指定了覆盖命令行上提供的任何 -cp 参数的 Class-Path 属性。我可以在 netbeans 的库面板中选择任意文件夹,但它会在清单的类路径中创建一个子文件夹。我想要 lib/ 文件夹中的所有依赖项和 log4j.xml 文件。
希望可以在 IDE 中执行此操作。我包含了一个自动生成的 build-impl.xml 文件的片段。
<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>
谢谢。