zoukankan      html  css  js  c++  java
  • 命令行java -classpath 的使用

    最近用Neatbeans 6.9.1做开发,发现在Neatbeans环境中运行没问题,但在命令行中不能正常运行,百度了一下原来需要加上classpath命令,但发现仍不能 正常运行,最终经过我的多次试验,原来使用classpath时覆盖了原来的classpath,直接导致找不到原有的主类。
     
    /*该类打包成JavaLibrary1.jar,我用Netbeans直接生成的jar文件*/
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package liguojun;
    /**
     *
     * @author Administrator
     */
    public class Dragon {
        int length=100;
        int age =100;
        public Dragon(int alength, int aage){
            length = alength;
            age = aage;
        }
        public void fly(){
            System.out.println(this+"   flying");
        }
    }
    /*该类使用JavaLibrary1.jar中的Dragon 类。*/
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package javaapplication5;
    import liguojun.*;
    /**
     *
     * @author Administrator
     */
    public class Main {
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            Dragon dragon=new Dragon(100,20);
            dragon.fly();       
        }
    }
    下面是相应的命令行:
    编译:javac -classpath D:lgjjavacodejavaapplication5JavaLibrary1.jar D:lgjjavacodejavaapplication5Main.java
    运行:java -classpath D:lgjjavacodejavaapplication5JavaLibrary1.jar;D:lgjjavacode javaapplication5.Main
      

    运行时的D:lgjjavacode 是必须的,否则找不到javaapplication5.Main类

  • 相关阅读:
    Linux之RPM 软件包管理
    软件开发模型之优缺点
    软件开发模型之迭代模型
    软件工程之软件开发模型类型
    软件开发模型之边做边改模型
    软件开发模型之螺旋模型
    软件开发模型之快速原型模型
    软件工程之软件开发模型介绍和选择
    卡内基的沟通原则
    软件开发模型之增量模型
  • 原文地址:https://www.cnblogs.com/waycool/p/5812894.html
Copyright © 2011-2022 走看看