How to include directory structure in an ant jar f

2019-01-18 05:05发布

I am a bit of an ant newbie, and I'm having trouble making a jar correctly. As an example, say I want to make a jar with my StringUtil class. Using the following ant directive, I can create the jar, but the problem is that the directory structure is lost. It simply puts StringUtil.class in the base directory of the jar. How can I correct this ant directive so that StringUtil.class is inside the com/test directory in the jar?

<jar destfile="myjar.jar" >
  <fileset file="${build}/com/test/StringUtil.class"/>
</jar>

Thanks!

标签: ant jar
1条回答
迷人小祖宗
2楼-- · 2019-01-18 05:44

You need to tell Ant to build the jar from the base directory, then tell it to include only the desired file. Like so:

<jar destfile="myjar.jar" >
  <fileset dir="${build}" includes="com/test/StringUtil.class"/>
</jar>

Here's the doc for <fileset> tags.

查看更多
登录 后发表回答