From the command line
To run your private instance of Tomcat from the command line, you need to run the startup.sh
script within the private instance directory rather than the one in /usr/share/tomcat7
. So, in your case, you need to run:
~/my-tomcat-instance/bin/startup.sh
This should work out-of-the-box.
From Eclipse
To run from Eclipse you should also create your Server Runtime Environment using your ~/my-tomcat-instance/
directory instead of /usr/share/tomcat7/
.
However, getting this working is far harder than it should be. This is partly because Eclipse is a bit buggy, and partly because Eclipse doesn't distinguish between CATALINA_BASE
and CATALINA_HOME
.
Missing files
It turns out that the tomcat7-instance-create
script does not set up everything that Eclipse needs. This was reported as a bug that appears to have been fixed at some point for Tomcat 6, but for whatever reason the patch is not in the tomcat7-user
package. I've raised a new bug in the hope this will get fixed, but in the meantime, you need to run the following commands:
ln -s /usr/share/tomcat7/lib ~/my-tomcat-instance/lib
ln -s /usr/share/tomcat7/bin/bootstrap.jar ~/my-tomcat-instance/bin/bootstrap.jar
Then you need to grab a copy of catalina.policy
which is not distributed as part of the tomcat7-user
package and put it in the conf/
directory in your instance. You can get it from the code repository for the tomcat7
package:
curl http://bazaar.launchpad.net/\~ubuntu-branches/ubuntu/precise/tomcat7/precise/view/head:/conf/catalina.policy > ~/my-test-tomcat7-instance/conf/catalina.policy
New server bug
Whilst testing this, I also ran into another bug, which I solved by deleting these files:
{workspace-directory}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.server.core.prefs
{workspace-directory}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.server.tomcat.core.prefs
as per the accepted answer on Eclipse add Tomcat 7 blank server name. Obviously, only do this step if you need to.
See also Eclipse 4.2 (Juno) 'Cannot create a server using the selected type' in Tomcat 7 for getting this working using the tomcat7
package.
I believe your CATALINA_BASE is incorrect it runs out of the /var/lib/tomcat7 directory and CATALINA_HOME is proper in regards to how you have declared the variable. Add CATALINA_HOME and CATALINA_BASE to /etc/default/tomcat7 along with JAVA_HOME and JRE_HOME. That executable notifies the tomcat servlet of how the environment is set upon start up of the servlet.
It could also be considered to put them in /etc/profile and then export them in /etc/bash.bashrc (i.e. export CATALINA_HOME). This should only be done if and only if your site doesn't have user login or registration. With out exporting the variables they would still be declared locally.
To globally declare the variables an approach, if you are the admin (group 4, you might also want to think about moving syslog to group 37, purging rsyslog and just keep the daemon running for logs as well so you preserve mandatory access control) you could ponder creating a ~/.bash_completion or ~/.bash_expert file in your home directory where you have something like this:
# ~/.bash_expert in regards to servlet alias
if [ -f /etc/bash_completion.d/.tomservlet ]; then
. /etc/bash_completion.d/.tomservlet
fi
export CATALINA_HOME
export CATALINA_BASE
export JRE_HOME
export JAVA_HOME
Then create the .tomservlet file in /etc/bash_completion.d/.tomservlet and add the
following:
CATALINA_HOME=/usr/share/tomcat7
CATALINA_BASE=/var/lib/tomcat7
JAVA_HOME=/usr/lib/jvm/jdk1.7.0
JRE_HOME=$JAVA_HOME:/jre
Once that is completed add the following lines to ~/.bashrc
if [ -f "$HOME/.bash_expert" ];then
. "$HOME/.bash_expert"
fi
Then source the ~/.bashrc file as shown below:
:~$ source .bashrc
and that should take care of your problems, in a secure fashion no matter what type of client side interaction is taken place. (Don't hold me to that, you never know what martians are lurking in cyberspace, it can be a scary realm sometimes).
P.S. I previously was referring to the oracle-sun jdk7 or I guess its just Oracle Jdk7 so if you are using the Open Jdk replace it as necessary, if using the oracle go back into the /etc/init.d/tomcat file and change openjdk to your version where the script refers to "$OPENJDK". This also assumes you installed from the repositories.
Good luck, and may your tomcat purr!!
Best Answer
I suggest installing standalone Tomcat into
/usr/local
instead of using the one in/usr/share
directory.Then use
/usr/local/apache-tomcat7.0.52
.