日期:2014-05-20  浏览次数:20848 次

可执行jar文件的问题
AntTestPro.jar包中
manifest.mf的内容如下:
Manifest-Version:   1.0
Ant-Version:   Apache   Ant   1.6.5
Created-By:   1.4.2_09-b05   (Sun   Microsystems   Inc.)
main-class:   myant.test.AntTest
Class-Path:   C:\eclipse\workspace\AntTestPro\build\lib\log4j.jar

有两个java文件:
package   myant.test;

import   org.apache.log4j.Logger;
import   org.apache.log4j.PropertyConfigurator;

public   class   AntTest   {

        private   static   Logger   logger   =   Logger.getLogger(AntTest.class.getName());

        /**
          *   main   method
          *  
          *   @param   args
          */
        public   static   void   main(String[]   args)   {

                PropertyConfigurator.configure( "Log4j.properties ");

                logger.info( "main   method   is   start. ");

                MyPrint   mp   =   new   MyPrint();

                mp.myPrint();

                logger.info( "main   method   is   end. ");
        }

}

package   myant.test;

import   org.apache.log4j.Logger;

public   class   MyPrint   {
       
        private   static   Logger   logger   =   Logger.getLogger(MyPrint.class.getName());
       
        /**
          *   myPrint   method
          *  
          *   <br> This   method   prints   a   String.
          *
          */
        public   void   myPrint()   {
                logger.info( "myPrint   method   is   start. ");
                System.out.println( "Hi,   This   is   Ant   Test! ");
                logger.info( "myPrint   method   is   end. ");
        }

}

但是用:
jar   -jar   AntTestPro.jar
命令报错:
C:\eclipse\workspace\AntTestPro> java   -jar   AntTestPro.jar
Exception   in   thread   "main "   java.lang.NoClassDefFoundError:   myant/test/AntTest
再线等,谢谢了

------解决方案--------------------
mf文件中去掉classpath,调用的时候附加所需要的类的jar文件到cp 试试
------解决方案--------------------
classpath裏加個.;呢?
------解决方案--------------------
参见
http://danmao.blogdriver.com/danmao/978761.html
在classpath处指定了你要用的jar应该就可以了
------解决方案--------------------