java main classpath_命令行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:\lgj\java\code\javaapplication5\JavaLibrary1.jar D:\lgj\java\code\javaapplication5\Main.java

运行:java -classpath D:\lgj\java\code\javaapplication5\JavaLibrary1.jar;D:\lgj\java\code javaapplication5.Main

运行时的D:\lgj\java\code 是必须的,否则找不到javaapplication5.Main类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值