Search code examples
javatomcatendorsed

Set endorsed directory in Tomcat6


I want to set the endorsed directory for Tomcat6 so it can use certain libraries instead of the default ones.

So, when I run this in a standalone application:

System.out.println(System.getProperty("java.endorsed.dirs"));

It prints:

/usr/lib/jvm/jdk1.6.0_45/jre/lib/endorsed

However, when I do it an application running in Tomcat, it prints a blank line.

I have tried to modify tomcat6.conf, with this (and restarting, of course):

JAVA_OPTS="-Djava.endorsed.dirs=/usr/share/tomcat6/endorsed -Djavax.sql.DataSource.Factory=org.apache.commons.dbcp.BasicDataSourceFactory -Djava.awt.headless=true -Xms1024m -Xmx1024m -XX:PermSize=1024m -XX:MaxPermSize=1024m"

But it still doesn't seem to know that property.

So, how can I tell Tomcat where the endorsed directory is located?


Solution

  • It seems that setting this option in tomcat6.conf:

    -Djava.endorsed.dirs=/usr/share/tomcat6/endorsed
    

    is not enough. It is required to create a variable called JAVA_ENDORSED_DIRS. So these two lines are needed in tomcat6.conf:

    JAVA_ENDORSED_DIRS="/usr/share/tomcat6/endorsed"
    JAVA_OPTS="-Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS [-Djava....]"
    

    Not really well documented issue, I think.