所以MongoDB是在27017運行和我的集合名稱爲測試。GeneratePDF與JasperReport的圖書館和MongoDB
try {
// - Connection to base
String mongoURI = "mongodb://localhost:27017/test";
MongoDbConnection connection = null;
Map<String, Object> parameters = new HashMap<String, Object>();
try {
line35 connection = new MongoDbConnection(mongoURI, null, null);
parameters.put(MongoDbDataSource.CONNECTION, connection);
JasperDesign jasperDesign = JRXmlLoader.load("/home/gocoffee.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
File jasperFile;
jasperFile = new File("/home/MongoDbReport.jasper");
JasperCompileManager.compileReportToFile("/home/gocoffee.jrxml", "MongoDbReport.jasper");
JasperFillManager.fillReportToFile("/home/MongoDbReport.jasper", parameters);
JasperExportManager.exportReportToPdfFile("/home/MongoDbReport.jrprint");
}
而且我有這樣的錯誤,我不明白爲什麼:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.jaspersoft.mongodb.MongoDbConnection.<init>(MongoDbConnection.java:62)
at Generate.main(Generate.java:35)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
的MongoURI似乎罰款,我想我沒有我同意任何登錄名或密碼
這不是一個mongo問題 - 例外是在jasper中,它看起來像一個簡單的類加載問題,因爲jasper正在尋找log4j - 你是否安裝了log4j並且在系統類路徑中? – 2012-02-20 11:54:47
不,我沒有安裝log4j我甚至不知道它是什麼但我即將安裝它 – Louis 2012-02-20 18:38:02