我用的是带月食的猫。
根据tomcat的文件:
从web应用程序、类或资源加载的角度来看,按以下顺序查看:
因此,当加载类时,tomcat将在WEB-INF/classes之前查找WEB-INF/lib.而且我们可以在WEB/lib中覆盖jar文件中的一些类,tomcat将选择覆盖的类。
但是现在,如果我通过检查“服务模块而没有外部发布”来更改tomcat服务器选项,那么重写的类就不会再加载了。
是否有任何解决方案,使这再次工作,但我仍然希望tomcat服务模块,而不发布。
编辑:
我发现了一些可能有用的东西,在这个文件夹f:\eclipse_projects.metadata.plugins\org.eclipse.wst.server.core\tmp0\conf中有一个server.xml,它包含这样的内容:
<Resources className="org.eclipse.jst.server.tomcat.loader.WtpDirContext"
extraResourcePaths=""
virtualClasspath="F:\eclipse_projects\ALS7C3\bin"/>
<Loader className="org.eclipse.jst.server.tomcat.loader.WtpWebappLoader"
useSystemClassLoaderAsParent="false"
virtualClasspath="F:\eclipse_projects\ALS7C3\bin"/>当运行tomcat选项“服务模块而不发布”选中时,eclipse将使用它自己的loader.This加载器包含在一个jar文件中,当您在eclipse中启动tomcat时,这个文件将被复制到loader.This中。以下是**org.eclipse.jst.server.tomcat.loader.WtpDirContext源代码的一部分
public Object lookup(String name) throws NamingException {
if (name.startsWith("/WEB-INF/") && name.endsWith(".tld")) {
String tldName = name.substring(name.lastIndexOf("/") + 1);
if (virtualMappings != null && virtualMappings.containsKey(tldName)) {
return new FileResource(virtualMappings.get(tldName));
}
} else if (tagfileMappings != null && name.startsWith("/META-INF/tags")
&& (name.endsWith(".tag") || name.endsWith(".tagx"))) {
// already loaded tag file
return new FileResource(tagfileMappings.get(name));
}
Object retSuper;
NamingException superEx;
try {
retSuper = super.lookup(name);
return retSuper;
} catch (NamingException ex) {
retSuper = null;
superEx = ex;
}
if (mappedResourcePaths != null) {
// Perform lookup using the extra resource paths
for (Map.Entry<String, List<String>> mapping : mappedResourcePaths.entrySet()) {
String path = mapping.getKey();
List<String> dirList = mapping.getValue();
if (name.equals(path)) {
for (String resourcesDir : dirList) {
File f = new File(resourcesDir);
if (f.exists() && f.canRead()) {
if (f.isFile()) {
return new FileResource(f);
}
else {
// TODO Handle directory
}
}
}
}
path += "/";
if (name.startsWith(path)) {
String res = name.substring(path.length());
for (String resourcesDir : dirList) {
File f = new File (resourcesDir + "/" + res);
if (f.exists() && f.canRead()) {
if (f.isFile()) {
return new FileResource(f);
}
else {
// TODO Handle directory
}
}
}
}
}
}
throw superEx;
}如果它首先处理jsp标记库,然后调用super.lookup,(如果在super.lookup,中找不到),那么它将尝试在virtualClasspath中加载资源,在我的示例中,它是eclipse输出类文件在不发布的情况下服务模块时的位置。
因此,我想,如果我可以覆盖org.eclipse.jst.server.tomcat.loader.WtpDirContext,的查找方法,那么我可以得到我想要的东西,但是这个jar文件包含在org.eclipse.jst.server.tomcat.core.jar,中,它们都是签名的。
我不知道如何覆盖这样一个jar文件。
有人能帮忙吗?
发布于 2015-04-20 20:21:11
下面是我在eclipse/tomcat中使用热部署的方法:
如果您更改了配置文件,可以尝试使用新的tomcat。
发布于 2016-05-21 11:43:12
覆盖这些类的解决方案是修改工作区项目中的Servers\???-config\catalina.properties。
common.loader=${catalina.base}/lib,${catalina.base}/lib/*..jar,${catalina.home}/lib,${catalina.home}/lib/*..jar
属性common.loader是Tomcat公共ClassLoader的类路径设置。
Webtools插件将org.eclipse.jst.server.tomcat.core.jar复制到${catalina.base}/lib。您可以覆盖这些类并用新路径替换${catalina.base}/lib,${catalina.base}/lib/*.jar。
https://stackoverflow.com/questions/19675931
复制相似问题