资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 编程开发 >
Advertisement
文章正文

今天一位老兄回的贴,觉得不错. _编程

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   
  • 雇用dbunit来维持你的数据环境稳定  
  • 如何在web上实现等待提示。  
  • 穷人的通用OLAP方案I  
  • 让PHP支持大型项目-构建JSP、PHP与JAVA融为一体的开发环境  
  • Tiger系列四:Annotation第二部分:定制Annotation  
  • 集成测试Strtus+Spring+Hibernate  
  • Java中通过代理服务器(proxy)访问网络  
  • 在RIA大潮里湿了一下身--Flex  
  • Mini Java编译器(一)——任务概述  
  • java程序,保存csdn blog的文章  
  • 页面导航:

    正文内容:

    先打开命令提示符(win2000或在运行筐里执行cmd命令,win98为dos提示符),输入jar –help,然后回车(如果你盘上已经有了jdk1.1或以上版本),看到什么:

    用法:jar {ctxu}[vfm0mi] [jar-文件] [manifest-文件] [-c 目录] 文件名 ...

    选项:

    -c 创建新的存档
    -t 列出存档内容的列表
    -x 展开存档中的命名的(或所有的〕文件
    -u 更新已存在的存档
    -v 生成详细输出到标准输出上
    -f 指定存档文件名
    -m 包含来自标明文件的标明信息
    -0 只存储方式;未用zip压缩格式
    -m 不产生所有项的清单(manifest〕文件
    -i 为指定的jar文件产生索引信息
    -c 改变到指定的目录,并且包含下列文件:

    如果一个文件名是一个目录,它将被递归处理。

    清单(manifest〕文件名和存档文件名都需要被指定,按m 和 f标志指定的相同顺序。

    示例1:将两个class文件存档到一个名为 classes.jar 的存档文件中:
    jar cvf classes.jar foo.class bar.class

    示例2:用一个存在的清单(manifest)文件 mymanifest 将 foo/ 目录下的所有文件存档到一个名为 classes.jar 的存档文件中:
    jar cvfm classes.jar mymanifest -c foo/ .

    来个小例子试试看:
    我们只有一个helloworld,如下:

    public class helloworld{
    public static void main(string[] args){
    system.out.println(“hi, hello world!”);
    }
    }

     

    我将这个java文件存到c盘跟目录下,ok,接下来,

    在先前打开的命令提示符下(跳转到c盘提示符下),我们输入javac helloworld.java,然后继续输入:jar cvf hello.jar helloworld.class,回车后去你的c盘看看,多了什么,没错 hello.jar 。

    基本的步骤我们现在都知道了,你可以自己去尝试一下随着jar后面的参数的不同,结果有什么变化。

    紧接着我们看看如何运行我们的jar包。

    在进入正题之前,你要先打开我们刚刚做好的jar包看看,多了什么呢,meta-inf目录?再看看里面是什么,还有一个manifest.mf文件是不是?用文本编辑器(我这里是ultraedit)打开它看看:
    manifest-version: 1.0
    created-by: 1.4.2 (sun microsystems inc.)

    就是这样。这里我们对它进行修改,加一句:main-class: helloworld (在第三行)。这个就是我们之前写的那个类,也就是我们的入口类。也即,
    manifest-version: 1.0
    created-by: 1.4.2 (sun microsystems inc.)
    main-class: helloworld

    接下来,我们在命令提示符里执行:
    jar umf manifest.mf app.jar

    这样我们使用了我们自己的manifest.mf文件对原来默认的进行了更新。你不妨可以再进去看看是不是添上了main-class: helloworld这一句。

    ok,这个最后的一步了,来验证我们做的一切,在命令提示符中输入:
    java -jar hello.jar(执行)

    出现了什么,――hi, hello world!
    我们再来看看jar文件在tomcat中发布,注意:在tomcat中我们就不能再用jar这种格式,而改war格式,它是专门用于web应用的,其实整个过程下来基本上和jar是类似的:

    先准备我们要打包的资源。

    找到存放tomcat的webapps目录,进到其中,新建一个文件夹,这里命名为hello,再进去新建web-inf文件夹,再进去新建classes文件夹,此时我们也将我们唯一的servlet,helloworld.java放到这里,在与classes目录同级下建立一文件web.xml。ok,目前我们初步建立了一个简单的web应用。

    在命令提示符下进到先前创制的hello目录下,执行 jar cvf hello.war * ,我们便得到hello.war。将它拷贝至webapps目录下,ok,来看最后一步,打开tomcat的目录conf中的server.xml,加入:
    reloadable="true"/>
    大功告成!运行它,启动tomcat,后在浏览器中输入http://localhost:8080/hello/helloworld,有了吗?

    好了,就这么多,希望对你有点帮助。


    补充:
    ############

    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---dont 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.


    很简单 看了都会明白的  接帖吧老兄



     

     
    热门推荐笔记本: IBM笔记本
    相关文章:
    webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
    ©2007 popbb.net All Rights Reserved