starting tomcat from jar file in ubuntu

痴心易碎 提交于 2019-12-11 00:57:01

问题


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..


回答1:


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.



来源:https://stackoverflow.com/questions/11600545/starting-tomcat-from-jar-file-in-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!