You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Alknaion <al...@alknaion.sk> on 2003/06/15 16:33:36 UTC

NoClassDefFoundError (error500) ... with external package (file Listings)

For better recognition 

Anna 

########################### test.jsp ##############################

<%@ page language="java" %>
<%@ page import="java.util.*, java.io.*, java.net.*, java.text.*,
java.lang.*, java.util.jar.*, headline.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>
<%
            String szPath = "<removedpath>\\MyJsp\\WEB-INF\\plugins";

		FileClassLoader c = new FileClassLoader(szPath);
		c.load("Hmmm", true);
%>
	

</body>
</html>

############################ MyInter.java #########################

package headline;

public interface MyInter {
	public void Test();
}
########################### FileClassLoader #######################


package headline;

import java.io.*;

public class FileClassLoader extends ClassLoader {

	private String basePath;

	public FileClassLoader(String basePath) {
		this.basePath = basePath;
	}

	public Class load(String typeName, boolean resolveIt) throws
ClassNotFoundException {

		Class result = findLoadedClass(typeName);

		if (result != null) {
			return result;
		}

		byte typeData[] = getTypeFromBasePath(typeName);
		if (typeData == null) {
			throw new ClassNotFoundException();
		}

		result = defineClass(typeName, typeData, 0,
		        typeData.length);

		if (result == null) {
			throw new ClassFormatError();
		}

		if (resolveIt) {
			resolveClass(result);
		}

		return result;
	}

	private byte[] getTypeFromBasePath(String typeName) {

		FileInputStream fis;
		String fileName = basePath + File.separatorChar
		        + typeName.replace('.', File.separatorChar)
		        + ".class";

		try {
			fis = new FileInputStream(fileName);
		} catch (FileNotFoundException e) {
			return null;
		}

		BufferedInputStream bis =
		        new BufferedInputStream(fis);
		ByteArrayOutputStream out =
		        new ByteArrayOutputStream();

		try {
			int c = bis.read();
			while (c != -1) {
				out.write(c);
				c = bis.read();
			}
		} catch (IOException e) {
			return null;
		}
		return out.toByteArray();
	}
}
############################ Hmmm.java ############################

import headline.*;

public class Hmmm implements MyInter{
	public void Test(){

	}

}



######################## file listing ##########################
-- MyJsp
  |
   -- test.jsp 
  |
   -- WEB-INF
      |
       --  classes
      |  |
      |   -- headline
      |     |
      |      -- FileClassLoader.class
      |     |
      |      -- MyInter.class
      |   
       -- plugins 
         | 
          -- Hmmm.class









---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org