简体   繁体   中英

Using Tomcat 7 on Ubuntu 12.10 — How To?

I am a newbie to Ubuntu 12.10 and moved to it from Windows.

In Windows I have configured the environment variable to include servlet-api.jar in the CLASSPATH variable so I do not have to type -cp <path to servlet-api.jar> every time I compile.

For normal Java programs, I have set the JAVA_HOME using:
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386" >> ~/.bashrc
With that solved, I need to set the CLASSPATH but do not know how to.

Please help on that!
Also I read on some forums that I should change the CLASSPATH manually each time I compile because changing the CLASSPATH may upset other applications.

Next, I tried this command to start Tomcat
service tomcat7 start but I got an error :
You need root privileges to run this script I do not know why. Help me solve that!

And if within the scope, please tell me how the directory structure of tomcat in Windows differs from that in Ubuntu.

Misc

I used sudo apt-get install tomcat7 to get Tomcat 7.

You don't say whether you're using an Ubuntu Tomcat package or a standalone Tomcat installation.

For a standalone Tomcat, you will be starting and stopping it using the scripts in its bin directory: startup.sh and shutdown.sh . In that case, Tomcat will use the environment variable values set at the time of invocation. When doing this, you can set the environment variables prior to running these commands.

The same is true for the Tomcat 6 or Tomcat 7 that Ubuntu distributes as packages. These neatly separate the $CATALINA_HOME directory (where the Tomcat 7 distribution is supposed to be) from the $CATALINA_BASE directory (where all of the changes and additions for a particular Tomcat instance are supposed to be. For the tomcat7 package, the first directory is /usr/share/tomcat7 , while the second is /var/lib/tomcat7 . You can find startup.sh and shutdown.sh in /usr/share/tomcat7/bin and of course you can use them.

However, if you use the Tomcat provided with Ubuntu, you're probably going to want to run it just like any other standard system service, and the packages support this: eg in the case of tomcat7 , you can just use

sudo service tomcat7 status
sudo service tomcat7 start
sudo service tomcat7 stop
sudo service tomcat7 restart

just like you can for any system service, and it uses the same mechanism as other system services do:

  • the shell script /etc/init.d/tomcat7 is used to start and stop Tomcat 7
  • /etc/default/tomcat7 is its configuration file, allowing a few parameters to be set

Using this method, you cannot specify additional environment variables for Tomcat to use by setting them in your shell or in /etc/default/tomcat7 ; they will not be passed to Tomcat.

However, there is a second method to set environment variables: if you set them in the shell script /var/lib/tomcat7/bin/setenv.sh (or, if you must, /usr/share/tomcat7/bin/setenv.sh ), they will be picked up and passed to Tomcat. This method always works.

Finally, Tomcat offers finer control than just using a $CLASSPATH when it comes to specifying additional classes or JARs to be loaded on startup: in its conf/catalina.properties configuration file, you can set the common.loader , server.loader and shared.loader to a list of directories and/or JAR files to be loaded in additional to the standard ones.

All it means is that you should do that as a superuser - which translates to administrator in windows so you should try something like sudo service tomcat7 start

Try export CLASSPATH=/usr/share/tomcat7/lib/servlet-api.jar:/usr/share/tomcat7/lib/jsp-api.jar - This will depend on where your tomcat installation in located.

You can get more here

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM