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:
- Created a new Eclipse project
- linked all the .jar files in the Jetty's
lib and ext directories into the project's build path.
- created a class with the above code.
- edited the web app context and directory arguments.
- 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 (3)