Chinaunix首页 | 论坛 | 博客
  • 博客访问: 248922
  • 博文数量: 59
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 752
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-01 20:49
文章分类
文章存档

2011年(24)

2010年(12)

2009年(18)

2008年(5)

我的朋友

分类: Java

2011-01-02 11:06:27

最近用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类
阅读(23241) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-01-05 11:05:17

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com

chinaunix网友2011-01-05 11:05:17

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com