我可以在 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)
我究竟做错了什么?