the corner office

a blog, by Colin Pretorius

« Too much traffic | Main | Long weekend and bookishness »

# Profiling Jetty

A for-posterity post. I've been doing some homework with Java profilers the past few days. One problem I had was getting a profiler (any damned profiler) to play nice with Jetty. I normally launch Jetty using MyEclipse which has every feature under the sun except profiler support. The other best-known (free) way to kick-start a Jetty server from Eclipse seems to be to use JettyLauncher. JettyLauncher used to have a 'profiler' edition that allowed one to use it in conjunction with Eclipse Profiler (which I first came across a little over a year ago). I learned, only after a lot of mucking around, that the profiler version got dropped a while back. I had no luck getting the older versions to work, with "Failed to load main Class: PluginRunner.class" error messages, or something like that.

Since JettyLauncher creates a new Run... option thingummy watchamacall (r-o-t-w for short), (and other app-launcher plug-ins are variations on the same theme), it gets a big tricky to link it to a profiler since profilers generally specify their own r-o-t-w's and never the twain shall meet unless one of the two sides has specifically catered for the joyous union. The Tomcats and JBosses and Resins of the world generally have the joyous-union support, but Jetty's a little less lucky. As a side note, I'm sure it's all quite doable via remote profiling anyway, but local profiling seems a lot easier and preferable in many cases.

The trick I eventually used for Eclipse Profiler (and YourKit), was to kick-start Jetty as a normal Java app. It's not that hard, really, and the Jetty tutorial has all the code you need to do it. I simply wrapped the tutorial code into a class, like so:

public class MyJettyLauncher
{
public static void main (String[] args) {
try {
Server server = new Server();
SocketListener listener = new SocketListener();
listener.setPort(8080);
server.addListener(listener);
server.addWebApplication("/","./webapps/myapp/");
server.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Then I did this:
  1. Created a new Eclipse project
  2. linked all the .jar files in the Jetty's lib and ext directories into the project's build path.
  3. created a class with the above code.
  4. edited the web app context and directory arguments.
  5. Set up a new r-o-t-w thingy and enabled profiling on the app server, which is now just a plain old Java app.
... as easy as that. The Jetty tutorial also has help for working with xml config files and whatnot, but the above worked fine for my purposes.

File under: java : {2005.06.03 21:54}

Comments:

1. Eelco (2005.06.26 - 18:08) #

If you are interested in having support for Eclipse profiler you're welcome to work on it. It is just too much work for me now to support it.

I use YourKit and JettyLauncher for profiling myself, and it works like a charm. Just append the VM argument in the 'Arguments' tab of your launcher and you are ready to go. You would have a line like '-Djetty.home="C:\jetty-5.1.3" -agentlib:yjpagent'.

Btw, I also used Eclipse's Haydes projects a bit, and that seems to work well with JL too. I just like YourKit better.

Eelco

2. Kate (2005.06.30 - 21:45) #

Can you elaborate on points 4 & 5...

Steps 1 - 3, are pretty straight forward, but the rest, for a newbe, is not clear.

Thanks

3. Colin (2005.07.07 - 20:57) #

A bit belated...

@Eelco - thanks for the tip, and the offer. I think my days with Jetty are limited though - and this snippet of code has pretty much suited my needs for now :)

@Kate - the two arguments I was referring to were in the line 'server.addWebApplication("/","./webapps/myapp/");' The first argument is the app context - ie. the part of the URL that gets you to the web app, so the argument above would mean that you access the app directly off of the root context on the server (eg. www.mysite.com/) - normally you'd specify something like '/myapp', so you'd access the application at www.mysite.com/myapp. The application directory is where your application is actually deployed on the file system - and that would usually be in the webapps directory inside the server's home directory (on windows, probably something like c:\jetty-x.xx\webapps\, where the x.xx is the version of jetty you've installed).

Point 5 is just me being obscure - all you need to do is right-click on the class in Eclipse, choose Run > Java application (or Run > Run... to set up more options), and off you go.

Add a comment

Your name (mandatory):

Your email:
Your email address is not displayed
Your home page:

Comment (sorry, no HTML):

Remember details?
Yes No

meta

-home-
about
contact
disclaimer
articles
code
tech blog

style: [?]
[plain.dark.blue]

Categories

java
linux
music
notes/domino
personal
politiek
studies
techie
thee_blog
world

RSS Feeds

rssfeed all posts
rssfeed all cmts
rssfeed tech posts
rssfeed tech cmts

Archives

2012.02
2012.01
2011.12
2011.11
2011.10
2011.09
2011.08
2011.07
2011.06
2011.05
2011.04
2011.03
2011.02
2011.01
2010.12
2010.11
2010.10
2010.09
2010.08
2010.07
2010.06
2010.05
2010.04
2010.03
2010.02
2010.01
2009.12
2009.11
2009.10
2009.09
2009.08
2009.07
2009.06
2009.05
2009.04
2009.03
2009.02
2009.01
2008.12
2008.11
2008.10
2008.09
2008.08
2008.07
2008.06
2008.05
2008.04
2008.03
2008.02
2008.01
2007.12
2007.11
2007.10
2007.09
2007.08
2007.07
2007.06
2007.05
2007.04
2007.03
2007.02
2007.01
2006.12
2006.11
2006.10
2006.09
2006.08
2006.07
2006.06
2006.05
2006.04
2006.03
2006.02
2006.01
2005.12
2005.11
2005.10
2005.09
2005.08
2005.07
2005.06
2005.05
2005.04
2005.03
2005.02
2005.01
2004.12
2004.11
2004.10
2004.09
2004.08
2004.07
2004.06
2004.05
2004.04
2004.03
2004.02
2004.01
2003.12
2003.11
2003.10
2003.09
2003.08
2003.07
2003.06

© Colin Pretorius