为什么我的罐子没有运转?

时间:2012-06-26 14:50:15

标签: java packaging executable-jar

我可以在jar文件之外运行我的程序,但我想部署它并将其作为jar运行。

此命令适用于运行.class文件:

java -classpath .;./libs/mail.jar;./libs/jcommon-1.0.16.jar;./libs/jfreechart-1.0.13.jar;./libs/jxl.jar;./libs/ojdbc5.jar gdsreports/ReportsDriver

这就是我打包jar文件的方式:

jar -cfvm GDSReports.jar GDSReports.mf gdsreports/* util/* libs/*

我的清单看起来像这样:

Manifest-Version: 1.0
Main-Class: gdsreports.ReportsDriver
Created-By: Me

这就是我运行jar的方式:

java -classpath .;./libs/mail.jar;./libs/jcommon-1.0.16.jar;./libs/jfreechart-1.0.13.jar;./libs/jxl.jar;./libs/ojdbc5.jar;./util;./gdsreports -jar GDSReports.jar

但是,运行我运行jar文件,它无法加载所有库。这是它吐出来的:

Error loading configuration file: config/reportConfig
Error loading configuration file: config/gdsIds
Exception in thread "main" java.lang.NoClassDefFoundError: jxl/write/WriteException
        at util.ReportConfig.setupReports(ReportConfig.java:197)
        at util.ReportConfig.setup(ReportConfig.java:65)
        at gdsreports.ReportsDriver.main(ReportsDriver.java:36)
Caused by: java.lang.ClassNotFoundException: jxl.write.WriteException
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 3 more

这是预期的输出:

Error loading configuration file: config/reportConfig
Error loading configuration file: config/gdsIds
-------------------------------------
Running TimingReport with parameters:
        Filename: Reports/06-26-2012/TimingRptZL_06-26-2012.xls
        Brand: ZL
        Using production database: false
-------------------------------------
-------------------------------------
Exception in thread "main" java.lang.NullPointerException
        at gdsreports.TimingReport.fillChartData(TimingReport.java:417)
        at gdsreports.TimingReport.fillReport(TimingReport.java:238)
        at gdsreports.TimingReport.run(TimingReport.java:131)
        at gdsreports.ReportsDriver.main(ReportsDriver.java:40)

我做错了什么?

1 个答案:

答案 0 :(得分:1)

使用-classpath参数时,将忽略CLASSPATH参数(以及-jar环境变量)。

如果jar文件依赖于其他库,则有两种选择:

  1. 使用Class-Path文件中的MANIFEST.MF标题来调出其他广告,或
  2. 打开其他罐子的包装,将它们放入罐子里。