[英]Eclipse: Ant script to export User Library/Libraries for project
我是Java编程的新手。 我最初是从NetBeans开始的,但是根据朋友的建议,我已经搬到了Eclipse。
在NetBeans中,为项目预先编写的ant构建脚本将生成Project.jar文件,并将所有必需的库/ jar放在lib /文件夹中。
但是,在Eclipse中,似乎我需要编写自己的ant脚本。 我写了几行来生成jar文件:
<target name="compile"> <mkdir dir="${build.dir}"/> <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="jars" debug="on"/> </target>
如何编写命令将我的用户库中的所有jar复制到$ {build.dir} / lib /文件夹?
谢谢。
使用复制任务
像这样,使用适当的包含或排除模式
<copy todir="${build.dir}/lib/">
<fileset dir="src_dir">
<include name="**/*.jar"/>
</fileset>
</copy>
<copy todir="${build.dir}/lib/">
<fileset dir="src_dir" excludes="**/*.java"/>
</copy>
我建议使用ant4eclipse库进行基于ant的eclipse项目。 当你使用它时,你可以访问eclipse工作区/项目设置,并且可以在ant中迭代eclipse项目类路径。
请参阅下面的示例代码:
<path id="ant.classpath">
<fileset dir="${lib.dir}/ant4eclipse">
<include name="*.jar" />
</fileset>
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<taskdef resource="net/sf/ant4eclipse/antlib.xml" />
<targetPlatform
<target name="copy_jars">
<getEclipseClasspath workspace="${basedir}/.."
projectname="TestProject"
targetPlatformLocation="c:/eclipse"
property="classpath"
relative="false"
runtime="true"
pathseparator="#" />
<!-- iterate over all classpath entries -->
<foreach list="${classpath}" delimiter="#"
target="copy_jar_file" param="classpath.entry" />
</target>
<target name="copy_jar_file">
<!-- check if current is a .jar-file ... -->
<if>
<isfileselected file="${classpath.entry}">
<filename name="**/*.jar" />
</isfileselected>
<then>
<!-- copy the jar file to a destination directory -->
<copy file="${classpath.entry}" tofile="${dest.dir}"/>
</then>
</if>
</target>
如果要使用用户库,可以通过userlibraries命令进行定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.