修改Tapestry3在{yourServlet}.application配置加载存在于classpath中的组件规范

2008年01月18日

修改Tapestry3在{yourServlet}.application配置加载存在于classpath中的组件规范
在Tapestry3中的{yourServlet}.application文件中不能加载配置在classpath中的jwc组件规范

<application name="yourApp" engine-class="org.apache.tapestry.engine.BaseEngine">
 <component-type type="MyComponent" specification-path="/com/yourApp/components/MyComponent.jwc"/>
</application>

这种写法按照常规的应该从classpath拿到组件的规范文件,但Tapestry3中出错拿不到规范文件
tapestry3分别有两个 org.apache.tapestry.IResourceLocation 的实现
org.apache.tapestry.resource.ClasspathResourceLocation
org.apache.tapestry.resource.ContextResourceLocation
分别加载classpath下的资源和webContext下的资源

解决办法
修改org.apache.tapestry.engine.Namespace类

    private IComponentSpecification locateComponentSpecification(String type)
    {
        String path = _specification.getComponentSpecificationPath(type);

        if (path == null)
            throw new ApplicationRuntimeException(
                Tapestry.format("Namespace.no-such-alias", type, getNamespaceId()));

        IResourceLocation location = getSpecificationLocation().getRelativeLocation(path);
        //hack
        if (location.getResourceURL() == null && path.startsWith("/"))
            location = new ClasspathResourceLocation(_specification.getResourceResolver(), path);
        //hack

        return _specificationSource.getComponentSpecification(location);
    }

增加该方法的hack的地方强制从classpath中查找资源

Caused by: java.lang.ClassNotFoundException: Class bytes found but defineClass()failed for:

2008年01月17日

Caused by: java.lang.ClassNotFoundException: Class bytes found but defineClass()failed for:

高版本JDK编译的class在低版本JDK下无法运行