Tomcat 7 - where do I set 'system properties'?

88,323

Solution 1

You can set any of the system properties in

apache-tomcat-7.0.33\conf\catalina.properties

file. Adding your entry in this file should resolve your problem.

E.g.

environment=local

Solution 2

You can set system properties in Tomcat by creating a setenv.sh file in /bin directory. I did the following to set the system properties.

export JAVA_OPTS="-Dmyprojectvar.subname=value -Danothervariable=value -Danother.variable=value"

Remember:

There is no space between the export JAVA_OPTS and =. Also: the symbol & is different, use ..

Now, run your catalina.sh to start tomcat.

Solution 3

You can set these system properties in command line that starts Tomcat. For example, you can have file setenv.bat (on setenv.sh if you are on linux) in Tomcats bin folder with following content:

set "CATALINA_OPTS=%CATALINA_OPTS% -Dfile.encoding=UTF8 -Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=true -Duser.timezone=GMT -Xmx1024m -XX:MaxPermSize=256m"

This file is preferred way of setting properties for Tomcat.

Now, FWD_SLASH_IS_SEPARATOR is by default set to false. If you set STRICT_SERVLET_COMPLIANCE to true, the value of FWD_SLASH_IS_SEPARATOR will be also set to true (and values of some other properties). However, you can set it explicitly to false, e.g. using the following in your setenv file is fine:

-Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=true
-Dorg.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR=false

This is also what I suggest when someone sets STRICT_SERVLET_COMPLIANCE to true, to always disable the FWD_SLASH_IS_SEPARATOR. Otherwise, the cookie Path value will be sent quoted (e.g. "\") and all browsers as of today, except Opera, do not recognize this and would e.g. fail to track the session.

Solution 4

THE SOLUTION:

sessionCookiePathUsesTrailingSlash="false"

We actually figured out how to solve this. It was a Tomcat 7 setting we needed to set. We placed it in server.xml, under the tag as follows:

<Context path="/test" reloadable="true" docBase="c:\webapp\test" 
workDir="c:\webapp\test" sessionCookiePathUsesTrailingSlash="false"/>

When we were debugging the problem and looking at the cookies path we noticed it was putting a \ backslash after the webapp name, so for our test webapp it was setting the path to /test/ instead of /test. This caused a bunch of problems.

Has anyone else had to deal with this setting in Tomcat 7? Or have a similar problem?

Solution 5

If you are trying to set variables for a server running in eclipse:

  1. Select Run > Run Configurations
  2. Make sure your server is selected
  3. Select Environment Tab
  4. Click 'New' to add a new variable
Share:
88,323
LuckY07
Author by

LuckY07

Updated on July 19, 2020

Comments

  • LuckY07
    LuckY07 almost 4 years

    My webapp is having an issue since upgrading to Tomcat 7. My session will go null after I login and try to do anything (submitting a request). I've read that setting the following may help:

    org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR=false
    

    Does anyone know where to set this? Should this be set in web.xml, context.xml or somewhere else?

    The other thing I want to check is the following:

    org.apache.catalina.STRICT_SERVLET_COMPLIANCE