サーブレットで試してみのですがうまく動作しません

3,920 views
Skip to first unread message

makimura

unread,
Sep 17, 2009, 9:47:35 AM9/17/09
to excella
はじめまして牧村です。
Httpアクセスをトリガーに帳票を出力したいのですが、Javaサーブレットでexcellaが思うように動作せず困っています。(Javaはほとん
ど初めてです。)

具体的には以下のエラーになります。
java.lang.NoClassDefFoundError: Could not initialize class
org.bbreak.excella.reports.tag.SingleParamParser

org.bbreak.excella.reports.processor.ReportCreateHelper.createDefaultParsers
(ReportCreateHelper.java:77)
org.bbreak.excella.reports.processor.ReportProcessor.<init>
(ReportProcessor.java:91)
jp.tuyano.eclipsebook3.SampleServlet.doGet(SampleServlet.java:173)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)




______________________________
ReportProcessor reportProcessor = new ReportProcessor();

_______________________________


レポートプロセッサーをインスタンス化しようとすると
org.bbreak.excella.reports.tag.SingleParamParserが見つからなく
エラーになります。

excella-repots.1.0.jarをライブラリに指定してよみこんでいるので
SingleParamParserクラスだけ見つからないというのが理解できなくて困っています。




動作環境は
Tomcat 6.0.20
JDK 6u16
とどちらも最新の環境で試しています。

試したのはサンプルにあるものをそのままサーブレットで動くようにしたプログラムです。
下記のコードになります。




package jp.tuyano.eclipsebook3;

import java.io.*;

import javax.servlet.ServletException;
import javax.servlet.http.*;




import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;




import org.bbreak.excella.reports.exporter.ExcelExporter;
import org.bbreak.excella.reports.model.ReportBook;
import org.bbreak.excella.reports.model.ReportSheet;
import org.bbreak.excella.reports.processor.ReportProcessor;
import org.bbreak.excella.reports.tag.ImageParamParser;
import org.bbreak.excella.reports.tag.RowRepeatParamParser;
import org.bbreak.excella.reports.tag.SingleParamParser;










/**
*
*

*/
public class SampleServlet extends HttpServlet {

/**
*
*/
private static final long serialVersionUID = 1L;

// ※新たに追記したメソッド
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,IOException {
response.setContentType("text/html;charset=Shift_JIS");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h3>s3ffsf</h3>");
out.println("</body></html>");



//
// 読み込むテンプレートファイルのパス(拡張子含)
// 出力先のファイルパス(拡張子はExpoterによって自動的に付与されるため、不要。)
// 出力ファイルフォーマット(ConvertConfigurationの配列)
// を指定し、ReportBookインスタンスを生成します。
//
String templateFileName = "請求書テンプレート.xls";
URL templateFileUrl = SampleServlet.class.getResource
( templateFileName);
String templateFilePath = URLDecoder.decode
( templateFileUrl.getPath(), "UTF-8");

// TODO: 出力先のディレクトリ、及びファイル名(拡張子不要)を指定してください。
String outputFileName = "請求書サンプル";
String outputFileDir = "C:/reports_output/";
String outputFilePath = outputFileDir.concat( outputFileName);
ReportBook outputBook = new ReportBook( templateFilePath,
outputFilePath, ExcelExporter.FORMAT_TYPE);

//
// テンプレートファイル内のシート名と出力シート名を指定し、
// ReportSheetインスタンスを生成して、ReportBookに追加します。
//
ReportSheet outputSheet = new ReportSheet( "請求書");
outputBook.addReportSheet( outputSheet);









//
// 置換パラメータをReportSheetオブジェクトに追加します。
// (反復置換のパラメータには配列を渡します。)
//
Calendar calendar = Calendar.getInstance();
outputSheet.addParam( SingleParamParser.DEFAULT_TAG, "請求日付",
calendar.getTime());

outputSheet.addParam( SingleParamParser.DEFAULT_TAG, "顧客名称",
"○○商事 様");



//SampleServletに変更

URL imageFileUrl = SampleServlet.class.getResource( "ロゴ.jpg");
String imageFilePath = URLDecoder.decode( imageFileUrl.getPath
(), "UTF-8");
outputSheet.addParam( ImageParamParser.DEFAULT_TAG, "会社ロゴ",
imageFilePath);



out.println(templateFilePath);



outputSheet.addParam( SingleParamParser.DEFAULT_TAG, "差出人住所1",
"〒100-0000");
outputSheet.addParam( SingleParamParser.DEFAULT_TAG, "差出人住所2",
"東京都○○区○○○○ ×××ー×××");
outputSheet.addParam( SingleParamParser.DEFAULT_TAG, "差出人住所3",
"×××ビル 9F");

List<String> productNameList = new ArrayList<String>();
productNameList.add( "商品A");
productNameList.add( "商品B");
productNameList.add( "商品C");
outputSheet.addParam( RowRepeatParamParser.DEFAULT_TAG, "商品名",
productNameList.toArray());


List<BigDecimal> unitPriceList = new ArrayList<BigDecimal>();
unitPriceList.add( new BigDecimal( 10000));
unitPriceList.add( new BigDecimal( 9000));
unitPriceList.add( new BigDecimal( 7000));
outputSheet.addParam( RowRepeatParamParser.DEFAULT_TAG, "単価",
unitPriceList.toArray());

List<Integer> quantityList = new ArrayList<Integer>();
quantityList.add( new Integer( 4));
quantityList.add( new Integer( 5));
quantityList.add( new Integer( 6));
outputSheet.addParam( RowRepeatParamParser.DEFAULT_TAG, "数量",
quantityList.toArray());

List<BigDecimal> priceList = new ArrayList<BigDecimal>();
priceList.add( new BigDecimal( 40000));
priceList.add( new BigDecimal( 45000));
priceList.add( new BigDecimal( 42000));
outputSheet.addParam( RowRepeatParamParser.DEFAULT_TAG, "金額",
priceList.toArray());

BigDecimal subTotal = BigDecimal.ZERO;
for ( BigDecimal price : priceList) {
subTotal = subTotal.add( price);
}
outputSheet.addParam( SingleParamParser.DEFAULT_TAG, "小計",
subTotal);

BigDecimal discount = new BigDecimal( 10000);
outputSheet.addParam( SingleParamParser.DEFAULT_TAG, "値引",
discount);

BigDecimal taxRate = new BigDecimal( 0.05);
BigDecimal taxCharge = subTotal.multiply( taxRate).setScale
( 0, RoundingMode.DOWN);
outputSheet.addParam( SingleParamParser.DEFAULT_TAG, "税額",
taxCharge);

BigDecimal total = subTotal.add( taxCharge).subtract
( discount);
outputSheet.addParam( SingleParamParser.DEFAULT_TAG, "合計",
total);

//
// ReportProcessorインスタンスを生成し、
// ReportBookを元にレポート処理を実行します。
//

//↓ここから下でエラー
ReportProcessor reportProcessor = new ReportProcessor();
reportProcessor.process( outputBook);


}

}


ReportProcessor reportProcessor = new ReportProcessor();
の前までは動作するのですがReportProcessor()のインスタンスを作成しよう
とするとSingleParamParserが見つからないと怒られてしまいます。

この件について解決方法をご存じの方がいればご教示願います。

よろしくお願いいたします。





横井@bbreak

unread,
Sep 17, 2009, 12:39:33 PM9/17/09
to excella
はじめまして。横井と言います。

java.lang.NoClassDefFoundErrorが出ているので、プログラムではなく
環境(CLASSPATH)の問題だと思います。

Tomcatであれば、tomcatのlibかアプリケーションのWEB-INF/lib
にjarファイルを置く必要があります。

以上、よろしくお願いします。

On 9月17日, 午後10:47, makimura <high52...@gmail.com> wrote:
> はじめまして牧村です。
> Httpアクセスをトリガーに帳票を出力したいのですが、Javaサーブレットでexcellaが思うように動作せず困っています。(Javaはほとん
> ど初めてです。)
>
> 具体的には以下のエラーになります。
> java.lang.NoClassDefFoundError: Could not initialize class
> org.bbreak.excella.reports.tag.SingleParamParser
>
> org.bbreak.excella.reports.processor.ReportCreateHelper.createDefaultParser-s

makimura

unread,
Sep 20, 2009, 11:47:32 AM9/20/09
to excella
ご回答いただきありがとうございます。
横井さんのおっしゃるとおり環境の問題でした。
poiのライブラリがもともとはいっていた古いものと重複
していたためにエラーとなっていました。古いものを取り除い
たら治りました。
Reply all
Reply to author
Forward
0 new messages