由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Help!: tomcat classloading problem
相关主题
Re: Help!: tomcat classloading problem请教一个有关 inner class 的问题
com.sun.tools.javac.Main 问题Java中如何动态生成对象
[合集] How to get all classes under a package?java深度历险 阅读笔记 zt
JSP How to Invoke the Specific version of Xerces-J[转载] servlet调用sql 访问oracle的问题
classpath 和 lib/ext 的区别?Re: [转载] Questions on failover & Hot dep
问个eclipse装jar的入门问题A very Stupid Question
如何获得类定义的public methods?请问protected的使用
get full class name问个问题啊. JDK/JRE
相关话题的讨论汇总
话题: class话题: shared话题: inf话题: tomcat话题: web
进入Java版参与讨论
1 (共1页)
s*********n
发帖数: 38
1
I have a class A, which calls class B.
If I put A in web-inf/, and B in shared/, it will work well.
But now I put A in shared/, and B in web-inf, it doesn't work and give me an
"ClassNotFoundException".
The way A call B is like this:
Class A{
...
Class clas = Class.forName(B);
record = (Record)clas.newInstance();
...
}
How can I solve this problem? I do want to keep the class A in shared/.
Thanks!
s*********n
发帖数: 38
2
I read the java doc, and found that there is another method:
public static Class forName(String name,
boolean initialize,
ClassLoader loader)
throws ClassNotFoundException
I guess the problem is that in Tomcat, the web-inf\ and shared\ are using
different classloaders. What I have done above, by default, uses the
classloader of "shared", so that it could not find the class in "web-inf".
I am looking for the way to obtai

【在 s*********n 的大作中提到】
: I have a class A, which calls class B.
: If I put A in web-inf/, and B in shared/, it will work well.
: But now I put A in shared/, and B in web-inf, it doesn't work and give me an
: "ClassNotFoundException".
: The way A call B is like this:
: Class A{
: ...
: Class clas = Class.forName(B);
: record = (Record)clas.newInstance();
: ...

c**g
发帖数: 274
3
I don't think Class in shared can access class in web-inf.

【在 s*********n 的大作中提到】
: I have a class A, which calls class B.
: If I put A in web-inf/, and B in shared/, it will work well.
: But now I put A in shared/, and B in web-inf, it doesn't work and give me an
: "ClassNotFoundException".
: The way A call B is like this:
: Class A{
: ...
: Class clas = Class.forName(B);
: record = (Record)clas.newInstance();
: ...

s*********n
发帖数: 38
4
I have found the solution.
FYI:
use Thread.currentThread().getContextClassLoader() to obtain the classloader
of "web app". Then use this classloader to invoke Class.forName(B, true,
contextClassloader).
done.
but I am still thinking about my another proposal: instruct the "system"
classloader to load classes on the CLASSPATH.
any idea?

an

【在 c**g 的大作中提到】
: I don't think Class in shared can access class in web-inf.
c**g
发帖数: 274
5
Of course you can progmaticly load any class which is accessable
via the file system/network. Why don't you just pack class in the web-inf
and put the jar to shared. Or you can add that web-inf to the global
classpath of tomcat, somewhere in conf/web.xml.

【在 s*********n 的大作中提到】
: I have found the solution.
: FYI:
: use Thread.currentThread().getContextClassLoader() to obtain the classloader
: of "web app". Then use this classloader to invoke Class.forName(B, true,
: contextClassloader).
: done.
: but I am still thinking about my another proposal: instruct the "system"
: classloader to load classes on the CLASSPATH.
: any idea?
:

m******t
发帖数: 2416
6

With all the repect, that last piece of advice was just bad, bad, bad. 8-)

【在 c**g 的大作中提到】
: Of course you can progmaticly load any class which is accessable
: via the file system/network. Why don't you just pack class in the web-inf
: and put the jar to shared. Or you can add that web-inf to the global
: classpath of tomcat, somewhere in conf/web.xml.

xt
发帖数: 17532
7

I agree. Making a local resource global is one of the worst things you
can do with classpaths.

【在 m******t 的大作中提到】
:
: With all the repect, that last piece of advice was just bad, bad, bad. 8-)

c**g
发帖数: 274
8
hey guys, I was just trying to be nice.

【在 xt 的大作中提到】
:
: I agree. Making a local resource global is one of the worst things you
: can do with classpaths.

1 (共1页)
进入Java版参与讨论
相关主题
问个问题啊. JDK/JREclasspath 和 lib/ext 的区别?
如何让servlet调用的一些class reload/reinitiate?问个eclipse装jar的入门问题
OutofMemoryError: Java Heap Space如何获得类定义的public methods?
问个java logger的问题get full class name
Re: Help!: tomcat classloading problem请教一个有关 inner class 的问题
com.sun.tools.javac.Main 问题Java中如何动态生成对象
[合集] How to get all classes under a package?java深度历险 阅读笔记 zt
JSP How to Invoke the Specific version of Xerces-J[转载] servlet调用sql 访问oracle的问题
相关话题的讨论汇总
话题: class话题: shared话题: inf话题: tomcat话题: web