我在JBoss 5到7.1.1迁移期间遇到了多个问题。其中一个是Tapestry根本不工作。
这个错误的唯一“有用”标志是,每当我尝试访问我的Web应用程序(EAR中捆绑的WAR)并在浏览器中显示“Not Found”时,服务器就会响应404。
即使在将每个LOG4J输出转换为DEBUG之后,服务器日志也根本没有提供有用的信息。
我尝试升级不同的依赖项,改变战争结构以符合Tapestry规范等。
我注意到我的应用程序使用ClasspathURLConverter
相应的位于这里:https://wiki.apache.org/tapestry/HowToRunTapestry5OnJBoss5
但是转换器在JBoss 7上运行不正常
这个问题的解决方案确实是在Tapestry寻找页面,组件等时糟糕的URL转换(我必须深入挖掘tapestry源代码并一直调试它)。
所以我试着深入研究VFS系统和URL转换。我找到了5个具有相同代码的链接供转换器使用(例如.http://www.voidcn.com/article/p-mpuwwlxm-eh.html)。这个实现的问题是我的JAR直接位于{myEar}/lib/
文件夹中。我修改了代码,但导致路径指向文件系统中爆炸但空的jar。
然后我在这里找到了另一个解决方案:https://developer.jboss.org/thread/172599 - 更简单和有效。
所以这是最终的解决方案:
app module.Java:
public static void contributeServiceOverride(MappedConfiguration<Class, Object> configuration) {
configuration.add(ClasspathURLConverter.class, new MyClasspathURLConverterImpl());
}
my classpath URL converter imp了.Java:
public URL convert(URL url) {
if (url != null && url.getProtocol().startsWith("vfs")) {
try {
return getRealFilePath(url.getPath());
} catch (Exception e) {
log.error(e.getCause());
}
}
return url;
}
private URL getRealFilePath(String urlString) throws IOException {
VirtualFile vFile = VFS.getChild(urlString);
URL physicalUrl = VFSUtils.getPhysicalURI(vFile).toURL();
String physicalUrlStr = physicalUrl.toString();
if (physicalUrlStr.contains(".jar")) {
int jarIdx = physicalUrlStr.indexOf(".jar");
String part1 = physicalUrlStr.substring(0, jarIdx + 4);
String part2 = physicalUrlStr.substring(jarIdx + 4);
String jarName = part1.substring(part1.lastIndexOf("/") + 1, jarIdx + 4);
String dir = part1 + part2.substring(0, part2.indexOf("/"));
String jarLocation = dir + "/" + jarName;
String packageName = part2.substring(part2.indexOf("/"));
if (packageName.startsWith("/contents")) {
packageName = packageName.substring(9);
}
String result = "jar:" + jarLocation + "!" + packageName;
physicalUrl = new URL(result);
}
return physicalUrl;
}
pom.hml
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-vfs</artifactId>
<version>3.2.14.Final</version>
<scope>provided</scope>
</dependency>