Reputation: 41
I use the version 2.4.2 of SiteMesh with Spring
<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
<version>2.4.2</version>
</dependency>
I deploy my application with the name myApp.war and everything works properly. I need to deploy the application myapp##versionApp.war name and this name gives problems.
The error is
Cannot construct Factory : com.opensymphony.module.sitemesh.factory.DefaultFactory: com.opensymphony.module.sitemesh.factory.FactoryException: Could not read config file : /WEB-INF/sitemesh.xml: java.io.FileNotFoundException:
I have found that exists in the WEB-INF / directory / file the sitemesh.xml.
Can you help me?
Upvotes: 4
Views: 2117
Reputation: 1
Changing the context-param, param-value in WEB-INF works for me. I know this is not a perfect solution, but i have tried a lot of things and nothing except this works.
<context-param>
<param-name>sitemesh.configfile</param-name>
<param-value>/opt/tomcat/xxx/yyy/zzz/WEB-INF/sitemesh.xml</param-value>
*xxx/yyy/zzz is my three level context, the war file is like this xxx#yyy#zzz#app-name.war
Upvotes: 0
Reputation: 61
DefaultFactory.java uses the Deprecate File.toURL() API. there is a problem reading sitemesh.xml file.
Please update your sitemesh version to sitemesh:2.5-atlassian-11
sitemesh:2.5-atlassian-11 Bugfix commit
Upvotes: 0
Reputation: 365
I had the same issue in version 2.3 while upgrading Tomcat version from 7 to 9 for our legacy application.
Problem was these two lines on DefaultFactory class.
this.configFileName = config.getServletContext().getInitParameter("sitemesh.configfile");
.
.
.
.
is = this.configFile.toURL().openStream();
By defining configFileName on web.xml file as a context-param, filename problem can be solved.
<context-param>
<param-name>sitemesh.configfile</param-name>
<param-value>/WEB-INF/sitemesh.xml</param-value>
</context-param>
Deprecated method usage on config file stream causes a problem. To solve this issue custom factory class should be written. You can directly copy the defaultFactory and replace this line
is = this.configFile.toURL().openStream();
with this
is = new FileInputStream(this.configFile);
This change will solve the input stream issue.
My adding environment entry you can add your custom class to sitemesh. This lines should be placed to web.xml file
<env-entry>
<env-entry-name>sitemesh.factory</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>your.custom.factory.SitemeshFactory</env-entry-value>
</env-entry>
Upvotes: 0
Reputation: 87
We had the same in version 2.4
The DefaultFactory will try to use the ServletContext().getRealPath(), but eventually tries to read from contexPath. This is an error i think.
To get around this you'll have to create a Factory of your own and set it in your web.xml env
Copy the DefaultFactory for the code
public class MyFactory extends com.opensymphony.module.sitemesh.factory.BaseFactory {
public MyFactory () {
// Do stuff
// delete every thing that sets the config path or simply set
String configFile = null;
// Do stuff
}
// Do other stuff
}
Your web.xml will look like so
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<env-entry>
<env-entry-name>sitemesh.factory</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>my.sitemesh.MyFactory</env-entry-value>
</env-entry>
Upvotes: 2