user523956
user523956

Reputation: 521

starting tomcat from jar file in ubuntu

I am using tomcat for the first time. I have downloaded and unzipped tomcat 7.0.28. I am able to start and shutdown it form the command prompt by ./startup.sh and ./shutdown.sh. So far it works fine. I can see tomcat homepage and examples also in the browser.

But what I want is to profile tomcat server with java profiler. For that I want to run it from jar file. Something like java -jar tomcat_allrequiredclasses.jar. Is there any way I can start tomcat server like this ? I tried to run jar files of tomcat residing in bin directory but gave me classNotdefined exception(just to try i did that).

Thank you..

Upvotes: 2

Views: 1739

Answers (1)

Christopher Schultz
Christopher Schultz

Reputation: 20862

Tomcat needs a lot of system properties and things like that to be set at JVM launch, so the script is necessary unless you are going to use "embedded Tomcat" and write your own launch driver using Tomcat's embedded driver.

I think that's overkill for just attaching a profiler. Most profilers come with a JVM "agent" that you can configure to attach on JVM launch using the -agentpath command-line option. This is how I attach YourKit Java Profiler, for example:

CATALINA_OPTS="-agentpath:/path/to/yourkit/libyjpagent.so=${yourkit.options}"
$CATALINA_HOME/bin/startup.sh

This will launch Tomcat in the usual way, but include the JVM profiler agent so you can then attach to it afterward.

Update to include OP's example

You want to do this:

$ export CATALINA_OPTS="-javaagent:lib/jborat-agent.jar -Xss256m -Xms256m  \ -Dch.usi.dag.jborat.exclusionList="conf/exclusion.lst" \ -Dch.usi.dag.jp2.dumpers="ch.usi.dag.jp2.dump.xml.XmlDumper" \ -Xbootclasspath/p:./lib/Thread_JP2.jar:lib/jborat-runtime.jar:lib/jp2-runtime.ja‌​r"
$ $CATALINA_HOME/bin/startup.sh

I encourage you to use complete paths whenever possible (e.g. don't use lib/jborat-agent.jar -- add the full path).

Note that by using the -Xss256M, you are setting the thread stack size to 256M and not the heap size. I suspect you meant to use -Xmx256M to set the maximum size of the heap.

Upvotes: 1

Related Questions