原创文章,转载转载请注明地址:我的博客
1.关于读取目录的文件列表,将其作为变量加入Classpath。
先设置目录及文件
<fileset id="afileset" dir="${jar.dir}" includes="*.jar" />
<pathconvert property="result" refid="afileset" />
读取出来如下:
[echo] found : D:\workspace\EduService\build\work\server_lib\aopalliance.jar;D:\workspace\EduService\build\work\server_lib\aspectj-1.7.4.jar;D:\workspace\EduService\build\work\server_lib\aspectjweaver.jar;...省略
默认的分隔为;根据我的需要将其改为空格pathsep=” “(换行符为${line.separator})
<pathconvert property="result" refid="afileset" pathsep=" "/>
然后需要去除前缀D:\workspace\EduService\build\work\
<map from="${work.dir}${file.separator}" to=" " />
[echo] file.name: server_lib\aopalliance.jar server_lib\aspectj-1.7.4.jar server_lib\aspectjweaver.jar server_lib\bson4jackson-master-2.4.0.jar
…省略
到现在为止,已经基本满足需求了。
<target name="test">
<!-- ${line.separator}-->
<pathconvert property="file.list" pathsep=" ">
<map from="${work.dir}${file.separator}" to=" " />
<fileset dir="${jar.dir}">
<include name="*.jar" />
</fileset>
</pathconvert>
<echo message="file.name: ${file.list}" />
<loadresource property="file.name">
<string value="${file.list}" />
<filterchain>
<headfilter lines="-1" />
</filterchain>
</loadresource>
<echo message="file.name: ${file.name}" />
</target>
filterchain 是做过滤的如果是按行分隔的 使用lines过滤。
2.基本的操作,复制 移动 删除
…略
3.替换文本内容,虽然后来我发现替换classpath:../jdbc.properties 其实是错的,直接在Class-Path:. 前面加上点 就能找到在包之外和白之内的路径
<!-- 修改applicationContext.xml 文件内容 -->
<replace file="${compile.dir}/applicationContext.xml" token="classpath:jdbc.properties" value="classpath:../jdbc.properties">
</replace>
<replace file="${compile.dir}/applicationContext.xml" token="classpath:netty-server.properties" value="classpath:../netty-server.properties">
</replace>
不过一下还是有用的:
<!--
<replace file="${compile.dir}/jdbc.properties" token="log4j.appender.E.File = d:/log.log" value="log4j.appender.E.File = /tmp/log.log">
</replace>
<replace file="${compile.dir}/jdbc.properties" token="log4j.appender.E.File = d:/error.log" value="log4j.appender.E.File = /tmp/error.log">
</replace>
-->
4.编译和打包
定义一个变量,
<!--Class-Path -->
<pathconvert property="file.list" pathsep=" ">
<map from="${work.dir}${file.separator}" to=" " />
<fileset dir="${jar.dir}">
<include name="*.jar" />
</fileset>
</pathconvert>
<echo message="file.list: ${file.list}" />
先定义一个path
<!-- lib-classpath -->
<path id="lib-classpath">
<fileset dir="${jar.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<javac destdir="${compile.dir}" includeAntRuntime="no" debug="on" source="1.7" target="1.7">
<src path="${src.dir}" />
<classpath>
<path refid="lib-classpath" />
</classpath>
</javac>
<jar destfile="${work.dir}/server.jar">
<manifest>
<attribute name="Main-Class" value="com.yzs.service.eduService.server.ServerStart" />
<attribute name="Class-Path" value=". ${file.list}" />
</manifest>
<fileset dir="${compile.dir}" />
</jar>
原创文章,转载转载请注明地址:我的博客