Skip to Main Content

Java APIs

Apache Tomcat 7.0.4 can't recognize the classpath for .jar files

AppuNov 19 2010
Hiii Everybody,

I have a weird problem. I am trying to develop a simple application where I am trying to pass an excel file name as an argument to a method and the method creates a copy of the specified file. I have used jxl.jar for excel file manipulation. During this I have faced two problems.......

1) I tried to compile the file CopyExcel.java in the command prompt(windows), sometimes the file is not compiled and the error shown indicates that it can't recognize the package jxl. But if I close the command prompt window and open it again.... I could compile the CopyExcel.java succesfully with no error.

2) Even if I have compiled the CopyExcell.java file successfully, whenever I am tryiyng to call a method copyMain() inside it, browser shows....
description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: Servlet execution threw an exception


root cause 

java.lang.NoClassDefFoundError: jxl/Workbook
	CopyExcel.copy(CopyExcel.java:39)
	CopyExcel.copyMain(CopyExcel.java:81)
	ServicePage.processRequest(ServicePage.java:28)
	ServicePage.doPost(ServicePage.java:73)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause 

java.lang.ClassNotFoundException: jxl.Workbook
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1672)
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1517)
	java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	CopyExcel.copy(CopyExcel.java:39)
	CopyExcel.copyMain(CopyExcel.java:81)
	ServicePage.processRequest(ServicePage.java:28)
	ServicePage.doPost(ServicePage.java:73)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.4 logs.


--------------------------------------------------------------------------------
The code for CopyExcel.java is as folows.............
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.File;
import java.io.IOException;

import jxl.Cell;
//import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.WritableWorkbook;

public class CopyExcel {

	private String inputFile;

	public void setInputFile(String inputFile) {
		this.inputFile = inputFile;
	}

	public void copy() throws IOException  {
		File inputWorkbook = new File(inputFile);
		Workbook w;
                try{
                    System.out.println("Before w= Workbook.getWorkbook(inputWorkbook);  ");
		w= Workbook.getWorkbook(inputWorkbook);
                 System.out.println("After w= Workbook.getWorkbook(inputWorkbook);  ");
		WritableWorkbook copy=Workbook.createWorkbook(new File("CopyPan.xls"), w);
                copy.write();
                copy.close();
                
                }catch(Exception e){}

/*		try {
			w = Workbook.getWorkbook(inputWorkbook);
			// Get the first sheet
			Sheet sheet = w.getSheet(0);
			// Loop over first 10 column and lines

			
				for (int i = 1; i < 6; i++) {
					Cell cell = sheet.getCell(0, i);
					//CellType type = cell.getType();
					//if (cell.getType() == CellType.LABEL) {
						//System.out.println("I got a label "
							//	+ cell.getContents());
					//}

					//if (cell.getType() == CellType.NUMBER) {
						//System.out.println("I got a number "
								//+ cell.getContents());
                                                System.out.println(cell.getContents());
					//}

				}
			
		} catch (BiffException e) {
			e.printStackTrace();
		}

*/
	}

	public static  String copyMain(String args) throws IOException {
		String str=args;
		CopyExcel test = new CopyExcel();
		test.setInputFile(args);
		test.copy();
                return "Success";
	}

}
I have set the "CLASSPATH" environment variables in "user variables for administrator" as follows,
.;%SYSTEM%;C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.4\bin;C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.4\lib\servlet-api.jar;C:\Program Files\Java\jdk1.6.0_11\lib\jxl-2.6.jar
Also I have tried editing the startup MS-dos batch file as folows....
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_11
set CLASSPATH=.;%SYSTEM%;C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.4\bin;C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.4\lib\servlet-api.jar;C:\Program Files\Java\jdk1.6.0_11\lib\jxl-2.6.jar

@echo off


rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses thi..........
But the problem remained...........


Plz. help me.

Thank u in advance for any help.
Post Details
Locked on Dec 17 2010
Added on Nov 19 2010
0 comments
836 views