zoukankan      html  css  js  c++  java
  • 14.JAVA-jar命令使用

    介绍

    jar命令用来对*.class文件进行压缩,从而生成jar(archive)归档文件,避免文件过多.

    定义一个文件:

    package common.demo ;
    
    public class Test
    { 
             public static void main(String args[]){
                      System.out.println("Hello World");
             }
    }

    编译后,生成包.类,然后将这个common包进行压缩为jar文件.输入下面命令:

    jar –cvf my.jar common     //将common目录创建为一个jar文件
                                //c:创建   v:打印输出    f:指定的jar文件

    打印如下:

     

    当我们想往my.jar添加其它包的时候,输入:

    jar uf  my.jar  call           //往my.jar 里添加call包

    如果想解压jar包,则输入:

    jar -xvf my.jar 

    当我们想通过外部程序调用该路径的jar包时,则需要配置CLASSPATH,如果在命令行,则输入"SET CLASSPATH=当前路径;",或者在电脑——>属性——>高级——>环境变量——>系统变量里添加变量名CLASSPATH,并设置变量值(路径).

    设置好后,就可以在程序里直接通过"import common.demo ;"来使用jar文件里的包类了.

     

  • 相关阅读:
    【Rust】多种错误类型
    【Rust】Result别名
    【Rust】Option然后
    【Rust】可选和错误
    【Rust】Result问号
    【Rust】Option转换
    【Rust】Option展开
    【Rust】Result结果
    【Rust】Result提前返回
    jQuery过滤 安静点
  • 原文地址:https://www.cnblogs.com/lifexy/p/10865111.html
Copyright © 2011-2022 走看看