Search code examples
tomcatconfigurationjvmmyfaces

Tomcat (Development) fails to start after adding UTF8 support in application and setting needed JVM options


I am failing to get Tomcat 7.0.27 to start. This is not a ServerFault question as this is my development server. I am using IntelliJ IDEA and my application ran no errors prior to adding a Filter to my application. This filter is not the cause of the issue as I am using it successfully on my production server where IDEA compiles, packages and runs it without problems that inhibit me from developing. What's my issue then?

I noticed a minor error that bubbled from Tomcat. It doesn't log into log files but reads:

Unable to use direct char[] access of java.lang.String
java.lang.NoSuchFieldException: count
    at java.lang.Class.getDeclaredField(Class.java:1899)
    at org.apache.myfaces.shared.util.StringCharArrayAccessor.<clinit>(StringCharArrayAccessor.java:63)
    at org.apache.myfaces.shared.util.StreamCharBuffer.readAsString(StreamCharBuffer.java:605)
    at org.apache.myfaces.shared.util.StreamCharBuffer.toString(StreamCharBuffer.java:631)
    at org.apache.myfaces.shared.renderkit.html.HtmlResponseWriterImpl.writeScriptContent(HtmlResponseWriterImpl.java:484)
    at org.apache.myfaces.shared.renderkit.html.HtmlResponseWriterImpl.endElement(HtmlResponseWriterImpl.java:416)
    at org.apache.myfaces.view.facelets.compiler.EndElementInstruction.write(EndElementInstruction.java:38)
    at org.apache.myfaces.view.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:46)
    at org.apache.myfaces.view.facelets.compiler.UILeaf.encodeAll(UILeaf.java:505)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:764)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:764)
    at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1900)
    at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:285)
    at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:115)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:241)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:199)
    at org.apache.myfaces.webapp.MyFacesServlet.service(MyFacesServlet.java:112)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.buhaugane.web.filters.CharsFilter.doFilter(CharsFilter.java:38)
    at ...

I suspect from looking online that I need to add some params for VM to tomcat catalina.bat Specifically one that tells it to reqquest the JVM to run with utf-8(I am using Windows 8 by the way) I can rule The Filter I use as the sole cause for this irritation as removeing it fixes everything The only thing the filter does is modify the HTTP request with a UTF-8 value loaded when it is initialized by the container: request.setCharacterEncoding(encoding); and when I tried adding the following to the file Tomcat would not start, complaining that the variable I gave contains invalid values. It is written exactly as is. I would like assistance to resolve this issue so that my development environment mimics production. Any assistance is appreciated.

The variable I use is configured:

set JAVA_OPTS=%JAVA_OPTS% ^
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager ^
-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties ^
-Xms128m -Xmx256m ^
=-Dfile.encoding=UTF-8

In short, I would like to eliminate all errors that could cause future issues and I believe that telling Tomcat to use UTF-8 JVM will assist me. Is there a visible error with the value I posted?


Solution

  • The problem is with your myfaces version. I had the same issue and could fix it by upgrading to the latest myfaces version. In particular I updated the following two jar files:

    • myfaces-api.jar (to version 2.1.10, I was using 2.1.6 before)
    • myfaces-impl.jar (to version 2.1.10, I was using 2.1.6 before)

    The error happend here: org.apache.myfaces.shared.util.StringCharArrayAccessor.<clinit>(StringCharArrayAccessor.java:63)

    This was working fine with Java 6 but isn't with Java 7. I guess the count field has been removed from the Java 7 implementation. Fortunatly the myfaces team already fixed that issue. Just update your jar-files (see above).