免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3680 | 回复: 10
打印 上一主题 下一主题

我打成的包,执行时报错Exception in thread "main", [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-02-22 01:20 |只看该作者 |倒序浏览
我做了一个项目目录如下
--BuildPage
-----lib(这里面是我程序里要使用的包)
-----mod(这里面是我程序里要使用的一些模板文件)
-----src
     ┠-com
         ┠-sobo
              ┠--BuildPage
                     ┠--BuildPageMain.java
                     ┠--Init.java
                     ┠--Transact.java

我用ant编译并且打包,成功打成buildpage.jar包
build.xml文档如下

<?xml version="1.0" encoding="UTF-8" ?>;
<!--start of file-->;
<project name="BuildPage" default="init" basedir=".">;
<target name="init">;

<property name="src.dir" value="./src">;</property>;
<property name="lib.dir" value="./lib">;</property>;
<property name="mod.dir" value="./mod">;</property>;

<property name="build.src" value="./build">;</property>;
<property name="build.lib" value="${build.src}/lib">;</property>;
<property name="build.mod" value="${build.src}/mod">;</property>;
<property name="build.class" value="${build.src}/classes">;</property>;
   
<path id="classpath">;
    <fileset dir="${lib.dir}">;
        <include name="**/*.jar"/>;
    </fileset>;
</path>;

<mkdir dir="${build.src}"/>;
<mkdir dir="${build.class}"/>;
<mkdir dir="${build.mod}"/>;
<mkdir dir="${build.lib}"/>;

<copy todir="${build.src}">;
   <fileset dir="${src.dir}">;</fileset>;
</copy>;

<copy todir="${build.lib}">;
   <fileset dir="${lib.dir}">;</fileset>;
</copy>;

<copy todir="${build.mod}">;
   <fileset dir="${mod.dir}">;</fileset>;
</copy>;

</target>;

<target name="build" depends="init">;
<javac srcdir="${build.src}"
       destdir="${build.class}">;
       <classpath refid="classpath">;</classpath>;
</javac>;
</target>;

<target name="jar" depends="build">;
<jar destfile="buildpage.jar"
     basedir="${build.src}">;
<manifest>;
     <attribute name="Built-By" value="Sobo"/>;
     <attribute name="Main-Class" value="BuildPageMain"/>;
</manifest>;     
</jar>;
</target>;
</project>;
<!-- End of file -->;

但我在控制台下想执行这个包文件时(java -jar buildpage.jar)

Exception in thread "main" java.lang.NoClassDefFoundError: BuildPageMain

论坛徽章:
0
2 [报告]
发表于 2004-02-22 13:53 |只看该作者

我打成的包,执行时报错Exception in thread "main",

打包这个target是不是该这样呢

  1. <target name="jar" depends="build">;
  2. <jar destfile="buildpage.jar"
  3. basedir="${build.class}">;
  4. <manifest>;
  5. <attribute name="Built-By" value="Sobo"/>;
  6. <attribute name="Main-Class" value="BuildPageMain"/>;
  7. </manifest>;
  8. </jar>;
  9. </target>;
复制代码

另外你的那几个Java类是不是放在了 package中,如果是,Main-Class的值要包含包名,像这样packagename/BuildPageMain

能否把Jar文件内部的结构贴出来,用jar -tvf buildpage.jar

论坛徽章:
0
3 [报告]
发表于 2004-02-22 22:25 |只看该作者

我打成的包,执行时报错Exception in thread "main",

F:\JavaRun\BuildPage>;jar -tvf buildpage.jar
     0 Sat Feb 21 23:46:50 CST 2004 META-INF/
   150 Sat Feb 21 23:46:48 CST 2004 META-INF/MANIFEST.MF
     0 Sat Feb 21 23:01:22 CST 2004 classes/
     0 Sat Feb 21 23:01:22 CST 2004 classes/com/
     0 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/
     0 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/test/
     0 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/test/BuildPage/
     0 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/BuildPage/
     0 Sat Feb 21 23:01:22 CST 2004 mod/
     0 Sat Feb 21 23:01:22 CST 2004 lib/
     0 Sat Feb 21 23:01:22 CST 2004 com/
     0 Sat Feb 21 23:01:22 CST 2004 com/sobo/
     0 Sat Feb 21 23:01:22 CST 2004 com/sobo/test/
     0 Sat Feb 21 23:01:22 CST 2004 com/sobo/test/BuildPage/
     0 Sat Feb 21 23:01:22 CST 2004 com/sobo/BuildPage/
   368 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/test/BuildPage/WriteNewPageTest.class
   721 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/test/BuildPage/InitTest.class
   528 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/test/BuildPage/TransactTest.class
  1118 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/test/BuildPage/ConnectionFactoryTest.class
  1105 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/test/BuildPage/ReadModelPageTest.class
  1580 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/test/BuildPage/XMLReaderTest.class
  1553 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/BuildPage/ConnectionFactory.class
   722 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/BuildPage/ReadModelPage.class
   745 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/BuildPage/XMLReader.class
  1135 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/BuildPage/BuildPageMain.class
  2406 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/BuildPage/Transact.class
  2275 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/BuildPage/Init.class
   598 Sat Feb 21 23:01:22 CST 2004 classes/com/sobo/BuildPage/WriteNewPage.class
   135 Sat Feb 21 23:01:22 CST 2004 mod/template.htm
    19 Sat Feb 21 23:01:22 CST 2004 mod/invalidfile.txt
   575 Sat Feb 21 23:01:22 CST 2004 mod/init.xml
     5 Sat Feb 21 23:01:22 CST 2004 mod/test.txt
  8704 Sat Feb 21 23:01:22 CST 2004 mod/Thumbs.db
     0 Sat Feb 21 23:01:22 CST 2004 mod/news.html
23563 Sat Feb 21 23:01:22 CST 2004 lib/saxpath.jar
135368 Sat Feb 21 23:01:22 CST 2004 lib/jdom.jar
121070 Sat Feb 21 23:01:22 CST 2004 lib/junit.jar
212695 Sat Feb 21 23:01:22 CST 2004 lib/jtds-0.6.jar
191881 Sat Feb 21 23:01:22 CST 2004 lib/jaxen-full.jar
   722 Sat Feb 21 23:01:22 CST 2004 com/sobo/test/BuildPage/WriteNewPageTest.java
  1035 Sat Feb 21 23:01:22 CST 2004 com/sobo/test/BuildPage/InitTest.java
   862 Sat Feb 21 23:01:22 CST 2004 com/sobo/test/BuildPage/TransactTest.java
  1443 Sat Feb 21 23:01:22 CST 2004 com/sobo/test/BuildPage/ConnectionFactoryTest.java
  1430 Sat Feb 21 23:01:22 CST 2004 com/sobo/test/BuildPage/ReadModelPageTest.java
  2170 Sat Feb 21 23:01:22 CST 2004 com/sobo/test/BuildPage/XMLReaderTest.java
  1745 Sat Feb 21 23:01:22 CST 2004 com/sobo/BuildPage/ConnectionFactory.java
  1262 Sat Feb 21 23:01:22 CST 2004 com/sobo/BuildPage/BuildPageMain.java
   941 Sat Feb 21 23:01:22 CST 2004 com/sobo/BuildPage/ReadModelPage.java
  2590 Sat Feb 21 23:01:22 CST 2004 com/sobo/BuildPage/Transact.java
  3194 Sat Feb 21 23:01:22 CST 2004 com/sobo/BuildPage/Init.java
   806 Sat Feb 21 23:01:22 CST 2004 com/sobo/BuildPage/WriteNewPage.java
  1351 Sat Feb 21 23:01:22 CST 2004 com/sobo/BuildPage/XMLReader.java

论坛徽章:
0
4 [报告]
发表于 2004-02-22 22:30 |只看该作者

我打成的包,执行时报错Exception in thread "main",

原帖由 "wolfg" 发表:
像这样packagename/BuildPageMain


我这几个类都是放在package里的,如:
com.sobo.BuildPage.BuildPageMain

那么在这个build.xml里应该怎么写呢?

论坛徽章:
0
5 [报告]
发表于 2004-02-23 09:47 |只看该作者

我打成的包,执行时报错Exception in thread "main",

写成这样吧


  1. <?xml version="1.0" encoding="UTF-8" ?>;
  2. <!--start of file-->;
  3. <project name="BuildPage" default="init" basedir=".">;
  4. <target name="init">;

  5. <property name="src.dir" value="./src">;</property>;
  6. <property name="lib.dir" value="./lib">;</property>;
  7. <property name="mod.dir" value="./mod">;</property>;

  8. <property name="build.src" value="./build">;</property>;
  9. <property name="build.lib" value="${build.src}/lib">;</property>;
  10. <property name="build.mod" value="${build.src}/mod">;</property>;
  11. <property name="build.class" value="${build.src}/classes">;</property>;

  12. <path id="classpath">;
  13. <fileset dir="${lib.dir}">;
  14. <include name="**/*.jar"/>;
  15. </fileset>;
  16. </path>;

  17. <mkdir dir="${build.src}"/>;
  18. <mkdir dir="${build.class}"/>;
  19. <mkdir dir="${build.mod}"/>;
  20. <mkdir dir="${build.lib}"/>;

  21. <copy todir="${build.src}">;
  22. <fileset dir="${src.dir}">;</fileset>;
  23. </copy>;

  24. <copy todir="${build.lib}">;
  25. <fileset dir="${lib.dir}">;</fileset>;
  26. </copy>;

  27. <copy todir="${build.mod}">;
  28. <fileset dir="${mod.dir}">;</fileset>;
  29. </copy>;

  30. </target>;

  31. <target name="build" depends="init">;
  32. <javac srcdir="${build.src}"
  33. destdir="${build.class}">;
  34. <classpath refid="classpath">;</classpath>;
  35. </javac>;
  36. </target>;

  37. <target name="jar" depends="build">;
  38. <jar destfile="buildpage.jar"
  39. basedir="${build.class}">;
  40. <manifest>;
  41. <attribute name="Built-By" value="Sobo"/>;
  42. <attribute name="Main-Class" value="com.sobo.BuildPage.BuildPageMain"/>;
  43. </manifest>;
  44. </jar>;
  45. </target>;
  46. </project>;
  47. <!-- End of file -->;

复制代码


注意这里<jar destfile="buildpage.jar"
basedir="${build.class}">;

论坛徽章:
0
6 [报告]
发表于 2004-02-23 18:08 |只看该作者

我打成的包,执行时报错Exception in thread "main",

谢谢,试了一下,这个问题解决了,不过又出现新的问题了:

F:\JavaRun\BuildPage>;java -jar buildpage.jar
java.lang.NoClassDefFoundError: org/jdom/JDOMException
        at com.sobo.BuildPage.BuildPageMain.run(Unknown Source)

论坛徽章:
0
7 [报告]
发表于 2004-02-23 20:39 |只看该作者

我打成的包,执行时报错Exception in thread "main",

我现在的这段是这样的:


  1. <target name="build" depends="init">;
  2. <javac srcdir="${build.src}"
  3.        destdir="${build.class}">;
  4. <classpath refid="classpath">;</classpath>;
  5. </javac>;
  6. </target>;

  7. <target name="jar" depends="build">;
  8.   <jar destfile="buildpage.jar"
  9.        basedir="${build.class}">;
  10.      <fileset dir="${build.lib}">;
  11.           <include name="**/*.jar"/>;
  12.      </fileset>;
  13. <manifest>;
  14. <attribute name="Built-By" value="Sobo"/>;
  15. <attribute name="Main-Class" value="com.sobo.BuildPage.BuildPageMain"/>;
  16. </manifest>;
  17. </jar>;
  18. </target>;
复制代码

论坛徽章:
0
8 [报告]
发表于 2004-02-24 14:46 |只看该作者

我打成的包,执行时报错Exception in thread "main",

wolfg君兄,还在吗?帮帮我啊!

论坛徽章:
0
9 [报告]
发表于 2004-02-25 10:44 |只看该作者

我打成的包,执行时报错Exception in thread "main",

ok,搞定了,在<manifest>;中间加了一段代码就可以:
<attribute name="Class-Path" value="${build.lib}/jdom.jar"/>;

感谢 wolfg君兄!!

论坛徽章:
0
10 [报告]
发表于 2004-02-25 14:32 |只看该作者

我打成的包,执行时报错Exception in thread "main",

这两天上不了网
不必客气,你的回复也让我学到了很多东西
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP