非常急呀。。。怎么用ant 生成 jar 包

wangxiangbo127 2011-01-05 02:08:05
怎么用ant 生成 jar ?ant 我什么都不懂。我只要用它来生成一个jar包。源文件是一个 smslib-v3.5.0.zip。
ant 我也下载下来了,环境变量也配好了。apache-ant-1.8.2 目录下没有build.xml这个文件。我不知道 build.xml 这个文件要写在哪里,里面要配什么,还有怎么执行命令。。。?
请知道生成的高手,帮我解决下。。说详细点
我在网上实在是找不到办法了。搜的答案都他吗是一样的。。
...全文
541 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangxiangbo127 2011-01-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 leonlee985 的回复:]
不太明白你为什么要用ant 来打包,你要打个jar包的话,直接在shell里输入
jar -cvf <jarname>.jar <class-path>
eg.
jar -cvf HelloWorldBean.jar * //在当前路径下把所有文件打包到HelloWorldBean.jar里
ant 里的Task一般就是移动一些文件,生成目录,打包,等等。
[/Quote]
要打个jar包的话,直接在shell里输入
jar -cvf <jarname>.jar <class-path>
eg.
jar -cvf HelloWorldBean.jar * //在当前路径下把所有文件打包到HelloWorldBean.jar里。
这个shell 是什么 jarname 指什么?class-path 指什么?我要打包的文件写哪里?
wangxiangbo127 2011-01-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 chooseforget 的回复:]
我这个脚本是放在项目的根目录下的。所有用的是相对路径。
[/Quote]

请问写了脚本后。用什么执行,怎么执行?
qingyuan18 2011-01-05
  • 打赏
  • 举报
回复
你需要先学习ant的基本知识,如果你有linux/unix下编译的经验,把这个ant看成Java领域里的build程序即可
chooseforget 2011-01-05
  • 打赏
  • 举报
回复
我这个脚本是放在项目的根目录下的。所有用的是相对路径。
chooseforget 2011-01-05
  • 打赏
  • 举报
回复
我写过ant脚本。
build文件在哪里无所谓。关键是要把脚本里的路径写对。

你可以解压那个zip。看看里面是什么结构。如果想用eclipse打包的话,即使不是一个eclipse识别的工程我们也可以手动添加.setting文件夹、.project等文件让eclipse识别。

如果想用ant,那就要自己写一个ant脚本了。


<?xml version="1.0" encoding="UTF-8"?>
<project name="cservice" default="deploy" basedir=".">
<property name="appName" value="cs"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value=".build"/>
<property name="class.dir" value="${build.dir}/tempClasses"/>
<property name="build.jar.dir" value="${build.dir}/lib"/>
<property name="IFsrc.dir" value="../CService30/CsEjbIF/src" />
<property name="ftIFsrc.dir" value="../CService_FT/CsEjbIF_FT/src" />

<property name="lib.dir" value="web/WEB-INF/lib"/>
<property name="resin.lib.dir" value="lib_j2ee"/>

<property name="if.lib.dir" value="../CService30/CsEjbIF/lib"/>
<property name="ftif.lib.dir" value="../CService_FT/CsEjbIF_FT/lib"/>

<property name="webapps.dir" value="${build.dir}/webapps/cs"/>
<property name="webroot.dir" value="web"/>
<fileset dir="${lib.dir}" id="lib.file">
<include name="**/*.jar"></include>
</fileset>


<path id="IF.classpath">
<pathelement location="${class.dir}/if" />
<fileset dir="${if.lib.dir}" includes="*.jar" />
</path>
<path id="ftIF.classpath">
<pathelement location="${class.dir}/ftif" />
<fileset dir="${ftif.lib.dir}" includes="*.jar" />
</path>


<path id="common.classpath">
<pathelement location="${class.dir}/common"/>
<fileset refid="lib.file" />
<fileset dir="${resin.lib.dir}" includes="*.jar"/>
</path>
<path id="cservice.classpath">
<pathelement location="${class.dir}/cservice"/>
<fileset refid="lib.file" />
<fileset dir="${resin.lib.dir}" includes="*.jar"/>
</path>
<path id="sys.classpath">
<pathelement location="${class.dir}/sys"/>
<fileset refid="lib.file" />
<fileset dir="${resin.lib.dir}" includes="*.jar"/>
</path>
<path id="cs.classpath">
<pathelement location="${class.dir}/cs"/>
<fileset refid="lib.file" />
<fileset dir="${resin.lib.dir}" includes="*.jar"/>
</path>
<path id="secondIn.classpath">
<pathelement location="${class.dir}/secondIn"/>
<fileset refid="lib.file" />
<fileset dir="${resin.lib.dir}" includes="*.jar"/>
</path>
<target name="prepare">
<delete dir="${build.dir}" />
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.jar.dir}"/>
<mkdir dir="${webapps.dir}"/>
<mkdir dir="${class.dir}"/>
<mkdir dir="${class.dir}/if"/>
<mkdir dir="${class.dir}/ftif"/>
</target>

<target name="compile" depends="prepare" description="Compile All Java Source">

<javac srcdir="${IFsrc.dir}" destdir="${class.dir}/if" debug="true" encoding="utf-8">
<classpath refid="IF.classpath" />
</javac>
<jar jarfile="${build.jar.dir}/cs-if.jar" basedir="${class.dir}/if" includes="**" excludes="build.xml"/>


<javac srcdir="${ftIFsrc.dir}" destdir="${class.dir}/ftif" debug="true" encoding="utf-8">
<classpath refid="IF.classpath" />
</javac>
<jar jarfile="${build.jar.dir}/cs_ft-if.jar" basedir="${class.dir}/ftif" includes="**" excludes="build.xml"/>


<javac srcdir="${src.dir}/common" destdir="${class.dir}" debug="true">
<classpath refid="common.classpath"/>
</javac>
<javac srcdir="${src.dir}/sys" destdir="${class.dir}" debug="true">
<classpath refid="sys.classpath"/>
</javac>
<javac srcdir="${src.dir}/cservice" destdir="${class.dir}" debug="true">
<classpath refid="cservice.classpath"/>
</javac>
<javac srcdir="${src.dir}/cs" destdir="${class.dir}" debug="true">
<classpath refid="cs.classpath"/>
</javac>
<javac srcdir="${src.dir}/secondIn" destdir="${class.dir}" debug="true" encoding="utf-8">
<classpath refid="secondIn.classpath"/>
</javac>
</target>
<target name="deploy" depends="compile" description="Deploy">
<copy todir="${webapps.dir}">
<fileset dir="${webroot.dir}">
<include name="**/*.*"></include>
</fileset>
</copy>
<delete dir="${webapps.dir}/WEB-INF/classes"/>
<mkdir dir="${webapps.dir}/WEB-INF/classes"/>
<copy todir="${webapps.dir}/WEB-INF/classes">
<fileset dir="${src.dir}/config">
<include name="**/*.*"></include>
</fileset>
</copy>
<delete dir="${webapps.dir}/WEB-INF/tmp" />
<delete dir="${webapps.dir}/WEB-INF/work" />

<delete dir="${webapps.dir}/WEB-INF/lib"/>
<mkdir dir="${webapps.dir}/WEB-INF/lib"/>
<copy todir="${webapps.dir}/WEB-INF/lib">
<fileset dir="${lib.dir}" includes="*.jar"/>
<fileset dir="${build.jar.dir}" includes="*.jar"></fileset>
</copy>
<copy todir="${webapps.dir}/WEB-INF/classes">
<fileset dir="${class.dir}">
<include name="**/*.*"/>
</fileset>
</copy>

<delete dir="${class.dir}"/>

<copy todir="${build.dir}">
<fileset dir="${webapps.dir}"/>
</copy>


<delete dir="${build.dir}/WEB-INF/classes/if"/>
<delete dir="${build.dir}/WEB-INF/classes/ftif"/>
<delete dir="${build.jar.dir}"/>
<delete dir="${build.dir}/webapps"/>
</target>
</project>

这是我写过的一个build脚本。其中<jar jarfile>命令就是打jar包的。
leonlee985 2011-01-05
  • 打赏
  • 举报
回复
不太明白你为什么要用ant 来打包,你要打个jar包的话,直接在shell里输入
jar -cvf <jarname>.jar <class-path>
eg.
jar -cvf HelloWorldBean.jar * //在当前路径下把所有文件打包到HelloWorldBean.jar里
ant 里的Task一般就是移动一些文件,生成目录,打包,等等。
我在肖申克 2011-01-05
  • 打赏
  • 举报
回复
ant很麻烦的, 一个人领悟估计要花些时间
wangxiangbo127 2011-01-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ztglf521 的回复:]
不就是要把项目打成jar包么, 是普通的java项目吧, 直接用eclipse打成jar包
如果你的项目引用了第三方jar包, 那想把这个也打进你的jar包, 那你的eclipse得装个插件
你搜索下net.sf.fjep.fatjar_0.0.31装到eclipse下的插件包就好了
[/Quote]

smslib-v3.5.0.zip(是一个 开发收发短信的包。下载下来是个压缩文件。但项目中用必须要变成JAR包。解压出来我用eclipse 导入项目,是导入不进的,也就是说它不是一个项目。)eclipse下打包我也会。
我在肖申克 2011-01-05
  • 打赏
  • 举报
回复
不就是要把项目打成jar包么, 是普通的java项目吧, 直接用eclipse打成jar包
如果你的项目引用了第三方jar包, 那想把这个也打进你的jar包, 那你的eclipse得装个插件
你搜索下net.sf.fjep.fatjar_0.0.31装到eclipse下的插件包就好了

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧