读书人

封装发布【转】

发布时间: 2013-01-28 11:49:56 作者: rapoo

打包发布【转】
<!DOCTYPE web-app PUBLIC
? '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
? 'http://java.sun.com/j2ee/dtds/web-app_2_3.dtd'>
<web-app>
? <servlet>
??? <servlet-name>hello</servlet-name>
??? <servlet-class>HelloWorld</servlet-class>
? </servlet>
? <servlet-mapping>
?<servlet-name>hello</servlet-name>
?<url-pattern>/HelloWorld</url-pattern>
? </servlet-mapping>
</web-app>
开始压缩,形成war档:
在命令提示符下进到先前创制的hello目录下,执行 jar? cvf? hello.war? * ,我们便得到hello.war。将它拷贝至webapps目录下,ok,来看最后一步,打开tomcat的目录conf中的server.xml,加入:
? <Context path="/hello" docBase="hello.war" debug="0"
??? reloadable="true"/>
大功告成!运行它,启动tomcat,后在浏览器中输入http://localhost:8080/hello/HelloWorld,有了吗?
最后,如果你想用ant来完成以上的打包活动,下面就告诉你:
对于jar来说。在build.xml中,
?<target name="jar">
? <jar destfile="${app_home}/hello.jar">
?? <fileset dir="${dest}" includes="**"/>
????? <!--fileset dir="${dest}" includes="**/action.properties"/-->
??? </jar>
?</target>

对于war,
<war warfile="hello.war" webxml="./WEB-INF/web.xml">
??? <fileset dir="html"/>
??? <lib dir="lib/">
??????? <exclude name="oracle*.jar"/>
??? </lib>
??? <classes dir="build/servlets">
???????? <include name="**/*.class"/>
? </classes>
</war>
好了,就这么多,希望对你有点帮助。:)
我上传了上面打过的两个包,hello.jar和hello.war。 『 点击下载 』
?『 点击下载 』
第一rar文件对应的是hello.jar,下载后将其名改为hello.jar
第二rar文件对应hello.war,下载后改为hello.war。
这是由于上传不了jar格式和war格式的文件,你只好照我上面说的去做了 :)

补充:
############
jar基本操作:
############
1. 创建jar文件
? jar cf jar-file input-file(s)
c---want to Create a JAR file.
f---want the output to go to a file rather than to stdout.
eg: 1)jar cf myjar.jar query_maintain_insert.htm
??? 2)jar cvf myjar.jar query_maintain_insert.htm
????? v---Produces verbose(详细的) output.
??? 3)jar cvf myjar.jar query_maintain_insert.htm mydirectory
??? 4)jar cv0f myjar.jar query_maintain_insert.htm mydirectory
????? 0---don't want the JAR file to be compressed.
??? 5)jar cmf MANIFEST.MF myjar.jar yahh.txt
????? m---Used to include manifest information from an existing manifest file.
??? 6)jar cMf MANIFEST.MF myjar.jar yahh.txt
????? M---the default manifest file should not be produced.
??? 7)jar cvf myjar.jar *
????? *---create all contents in current directory.
2. 察看jar文件
? jar tf jar-file
t---want to view the Table of contents of the JAR file.
eg: 1)jar vft yahh.jar
????? v---Produces verbose(详细的) output.
3. 提取jar文件
? jar xf jar-file [archived-file(s)]
x---want to extract files from the JAR archive.
eg: 1)jar xf yahh.jar yahh.txt(仅提取文件yahh.txt)
??? 2)jar xf yahh.jar alex/yahhalex.txt(仅提取目录alex下的文件yahhalex.txt)
??? 3)jar xf yahh.jar(提取该jar包中的所有文件或目录)
4. 修改Manifest文件
? jar cmf manifest-addition jar-file input-file(s)
m---Used to include manifest information from an existing manifest file.
5. 更新jar文件
? jar uf jar-file input-file(s)
u---want to update an existing JAR file.

读书人网 >软件架构设计

热点推荐