本文摘自:http://lerluc.iteye.com/blog/560972
struts convention plugin to scan jar files for actions
StrutsEclipseRESTSpringAnt
i intended to pack my action classes in jar file and utilize the convention plugin to initialize them. i did it following this instruction.
the plugin didn't recognize my jar file. >_<
with the source code of convention plugin, i traced to org.apache.struts2.convention.PackageBasedActionConfigBuilder
Java代码
private UrlSet buildUrlSet() throws IOException {
ClassLoaderInterface classLoaderInterface = getClassLoaderInterface();
UrlSet urlSet = new UrlSet(classLoaderInterface, this.fileProtocols);
//...
//removed the rest of codes
}
private UrlSet buildUrlSet() throws IOException {
ClassLoaderInterface classLoaderInterface = getClassLoaderInterface();
UrlSet urlSet = new UrlSet(classLoaderInterface, this.fileProtocols);
//...
//removed the rest of codes
}
i found my jar in the classLoaderInterface but the urlSet didn't recognize it. let's dig deeper. it's a class in xwork. the xwork 2.1.6 release is not updated on the official site. here is the address.
com.opensymphony.xwork2.util.finder.UrlSet
Java代码
private static List<URL> getUrls(ClassLoaderInterface classLoader) throws IOException {
List<URL> list = new ArrayList<URL>();
//find jars
ArrayList<URL> urls = Collections.list(classLoader.getResources("META-INF"));
//...
//removed the rest of codes
}
private static List<URL> getUrls(ClassLoaderInterface classLoader) throws IOException {
List<URL> list = new ArrayList<URL>();
//find jars
ArrayList<URL> urls = Collections.list(classLoader.getResources("META-INF"));
//...
//removed the rest of codes
}
classLoader.getResources("META-INF") - this is how xwork finds jar files. spring does it with the same approach and luckily someone(Ingo Düppe) from their side gave us a heads-up on the META-INF.
http://jira.springframework.org/browse/SPR-1670
引用
Please be careful with this approach. Not all jar files do have a META-INF directory entry even when files exists like META-INF/manifest.mf. For instance jars build with eclipse do not contain a META-INF directory entry so this approach will not find these jars.
thanks Ingo! you save my day.
turns out that my jar was built with eclipse export tool and had no directory entry of the META-INF folder. i packed it again with ant task then the plugin found it.
struts convention plugin to scan jar files for actions
StrutsEclipseRESTSpringAnt
i intended to pack my action classes in jar file and utilize the convention plugin to initialize them. i did it following this instruction.
the plugin didn't recognize my jar file. >_<
with the source code of convention plugin, i traced to org.apache.struts2.convention.PackageBasedActionConfigBuilder
Java代码
private UrlSet buildUrlSet() throws IOException {
ClassLoaderInterface classLoaderInterface = getClassLoaderInterface();
UrlSet urlSet = new UrlSet(classLoaderInterface, this.fileProtocols);
//...
//removed the rest of codes
}
private UrlSet buildUrlSet() throws IOException {
ClassLoaderInterface classLoaderInterface = getClassLoaderInterface();
UrlSet urlSet = new UrlSet(classLoaderInterface, this.fileProtocols);
//...
//removed the rest of codes
}
i found my jar in the classLoaderInterface but the urlSet didn't recognize it. let's dig deeper. it's a class in xwork. the xwork 2.1.6 release is not updated on the official site. here is the address.
com.opensymphony.xwork2.util.finder.UrlSet
Java代码
private static List<URL> getUrls(ClassLoaderInterface classLoader) throws IOException {
List<URL> list = new ArrayList<URL>();
//find jars
ArrayList<URL> urls = Collections.list(classLoader.getResources("META-INF"));
//...
//removed the rest of codes
}
private static List<URL> getUrls(ClassLoaderInterface classLoader) throws IOException {
List<URL> list = new ArrayList<URL>();
//find jars
ArrayList<URL> urls = Collections.list(classLoader.getResources("META-INF"));
//...
//removed the rest of codes
}
classLoader.getResources("META-INF") - this is how xwork finds jar files. spring does it with the same approach and luckily someone(Ingo Düppe) from their side gave us a heads-up on the META-INF.
http://jira.springframework.org/browse/SPR-1670
引用
Please be careful with this approach. Not all jar files do have a META-INF directory entry even when files exists like META-INF/manifest.mf. For instance jars build with eclipse do not contain a META-INF directory entry so this approach will not find these jars.
thanks Ingo! you save my day.
turns out that my jar was built with eclipse export tool and had no directory entry of the META-INF folder. i packed it again with ant task then the plugin found it.
遇到使用Struts Convention Plugin扫描Eclipse构建的Jar文件中的Action类时未被识别的问题,深入分析原因发现是使用的xwork2.1.6版本未更新至官方站点,进而提供解决方法,通过重新打包Jar文件并使用Ant任务,使得Plugin成功识别Jar文件。
1472

被折叠的 条评论
为什么被折叠?



