命令行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.
*/
* 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");
}
*
* @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.
*/
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication5;
import liguojun.*;
import liguojun.*;
/**
*
* @author Administrator
*/
public class Main {
*
* @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();
}
}
下面是相应的命令行:
* @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类