Cai*_*der 7 java eclipse tomcat
我正在使用带有eclipse的tomcat.
根据tomcat的文档:
从Web应用程序的角度来看,类或资源加载在以下存储库中查找,顺序如下:
因此,在加载类时,tomcat将在WEB-INF/lib之前查找WEB-INF/classes.我们可以在WEB-INF/lib中覆盖jar文件中的某些类,tomcat将覆盖被覆盖的类.
但是现在如果我通过选中"使用out publish服务模块"来更改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"/>
Run Code Online (Sandbox Code Playgroud)
这似乎与运行Tomcat的选项时,"服务模块,而出版"检查时,Eclipse会用它自己的loader.This程序包含在其中将被复制到一个jar文件F:\ eclipse_projects\.metadata.plugins\org.eclipse.当你在eclipse中启动tomcat时,wst.server.core\tmp0\lib**.以下是**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;
}
Run Code Online (Sandbox Code Playgroud)
看来,如果它会先处理然后JSP标签库调用super.lookup,如果不能找到super.lookup,它会尝试在virtualClasspath加载资源,"F:\ eclipse_projects\ALS7C3\BIN"在我的例子,它是在没有发布的情况下提供模块时eclipse输出类文件的位置.
所以,我想,我能得到我想要的东西,如果我可以覆盖查找的方法org.eclipse.jst.server.tomcat.loader.WtpDirContext,但是这个jar文件包含在org.eclipse.jst.server.tomcat. core.jar,两者都签了.
我不知道如何覆盖这样的jar文件.
任何人都可以帮忙吗?
小智 0
以下是我使用 eclipse/tomcat 进行热部署的方法:
如果您更改了配置文件,也许可以尝试使用新的 tomcat。
| 归档时间: |
|
| 查看次数: |
2186 次 |
| 最近记录: |