Apache ant 清单类路径?
我有一个 java 项目的标准项目布局:
project /
src /
source_file_1.java
...
source_file_N.java
build /
classes /
source_file_X.class
...
jar /
MyJar.jar
lib /
SomeLibrary.jar
SomeOtherLibrary.jar
据我所知,我正在使用 Ant 正确构建项目。 我需要在清单文件中设置类路径属性,以便我的类可以使用所需的库。
以下来自 build.xml 的相关信息
<target name="compile" depends="init">
<javac srcdir="src" destdir="build\classes">
<classpath id="classpath">
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="jar" depends="compile">
<jar destfile="build\jar\MyJar.jar" basedir="build\classes" >
<manifest>
<attribute name="Built-By" value="${user.name}" />
</manifest>
</jar>
</target>
任何朝着正确方向的推动都会受到赞赏。 谢谢
I have a standard project layout for a java project:
project /
src /
source_file_1.java
...
source_file_N.java
build /
classes /
source_file_X.class
...
jar /
MyJar.jar
lib /
SomeLibrary.jar
SomeOtherLibrary.jar
As far as I can tell, I am building the project correctly with Ant. I need to set the class-path attribute in the Manifest file so my classes can use the required libraries.
The following relevant information from build.xml
<target name="compile" depends="init">
<javac srcdir="src" destdir="build\classes">
<classpath id="classpath">
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="jar" depends="compile">
<jar destfile="build\jar\MyJar.jar" basedir="build\classes" >
<manifest>
<attribute name="Built-By" value="${user.name}" />
</manifest>
</jar>
</target>
Any push in the right direction is appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设库从编译到执行 jar 文件的过程中没有更改位置,您可以在编译目标之外创建一个指向类路径的路径元素,如下所示:
然后您可以在 javac 任务中使用创建的路径来代替当前的类路径。
然后,您可以使用该路径来设置清单类路径。
manifestclasspath 生成一个格式正确的类路径,用于清单文件,该文件必须在 72 个字符后换行。 如果不使用manifestclasspath 任务,包含许多jar 文件或长路径的长类路径可能无法正常工作。
Assuming the libraries do not change location from compiling to executing the jar file, you could create a path element to your classpath outside of the compile target like so:
Then you can use the created path inside your javac task in place of your current classpath.
You can then use the path to set a manifestclasspath.
The manifestclasspath generates a properly formatted classpath for use in manifest file which must be wrapped after 72 characters. Long classpaths that contain many jar files or long paths may not work correctly without using the manifestclasspath task.
查看 NetBeans 生成的构建文件,我在
-do-jar-with-libraries
任务中找到了以下代码段:因此,换句话说,您似乎只需要向清单中添加另一个属性即可你已经有的任务。
另请参阅清单任务文档。
Looking at my NetBeans-generated build file, I found this snippet in the
-do-jar-with-libraries
task:So in other words, it looks like you just need to add another attribute to the manifest task that you already have.
See also the Manifest Task documentation.