Resin Plug-in for Eclipse

Caucho Resin is the application server used in the environment of my new employer. Thus, I had to adapt to a new development technology.

I came across this page in the Caucho Wiki. It explains the various ways of integrating Resin with your favourite IDE. It points to a great tutorial from Pritpal Dhaliwal.

However, what I really missed was a tighter integration into Eclipse WTP. After searching around a little bit I decided to write one myself based on the Eclipse WTP generic server definition support. Here it is. πŸ™‚

Disclaimer: Please excuse if there are some mistakes in the Resin configuration or the way I’m using Resin. I never used it before. Of course, the plug-in comes WITHOUT any warranty. Use it at your own risk!

Note: This plug-in needs some update for Resin 3.1. It only supports Resin 3.0. You can find the source code here.

Goals

  • Run Resin from Eclipse.
  • Deploy one (or more) applications on Resin.
  • Debug Servlets/Actions/Java classes using Eclipse Debugger.
  • Debug JSPs using Eclipse Debugger.
  • Integrated into Eclipse WTP.

Requirements

  • Java SDK (I used a Java 5 JRE for running Eclipse WTP and a 1.4.2 JDK for running Resin)
  • Resin 3.0 (I used Resin 3.0.23)
  • Eclipse 3.3 with Webtools 2.0 (aka. Eclipse Europa Release)
  • My plug-in from my update site
    • Note, the plug-in now requires Eclipse 3.3 with Webtools 2.0 (tested with Webtools 2.0RC0). The old version is still available here.
  • My recommended Resin configuration file (resin-wtp-development.conf)

Installation

  1. Install the Java. (I’ll assume D:\Java\jdk1.4.2\ in this tutorial.)
  2. Install Eclipse 3.3 with Webtools 2.0. (I’ll assume D:\Eclipse\ in this tutorial.)
  3. Install my plug-in from the update site (via Help -> Software Updates -> Find and Install...).
  4. Unzip Resin. (I’ll assume D:\Resin\resin-3.0.23\ in this tutorial.)
  5. Place my recommended Resin configuration into the Resin configuration directory. (I’ll assume D:\Resin\resin-3.0.23\conf\ in this tutorial.)

Configuration

  1. Start Eclipse by running D:\Eclipse\eclipse.exe and open a new, empty workspace (for example, D:\Development\resin-tutorial\).
  2. Close the Welcome page and go to Window – Preferences – Java – Installed JREs.
  3. Click on Add… to add a new JRE entry for the Sun JDK 1.4.2. In the new dialog click on Browse… and point to D:\Java\jdk1.4.2\, enter a name into JRE name (for example, Sun JDK 1.4.2).
    Add JDK 1.4.2
    Click OK to close the dialog.
  4. Check the added JDK entry to make it the default JDK for Eclipse and click OK to close the preferences dialog and apply the new settings.
  5. Now, go to Window – Preference – Server – Installed Runtimes. Click on Add… to add a new server runtime for Resin.
    Add New Runtime (Step 1)
    In the New Server Runtime wizard select Caucho – Resin v3.0 and click Next.
  6. On the next page select the Sun 1.4.2 JDK and click on Browse… and point to the Resin installation directory (D:\Resin\resin-3.0.23\).
    Add New Runtime (Step 2)
    Click Finish to close the wizard.
  7. Click OK to close the preferences dialog.

Step 1: Create a web project

  1. Go to Window – Open Perspective – Other…, select J2EE and click OK.
  2. Go to File – New – Project…, select Web – Dynamic Web Project and click Next.
  3. Enter a Project Name (for example, my-test-app), select the Target runtime Resin v3 and make sure that the checkbox Add project to an EAR is NOT checked.
    New Web Project (Step 1)
    Click on Next to proceed to the next page. On page two, make sure that the project facets Dynamic Web Module and Java are checked.
    New Web Project (Step 2)
    Click Next to proceed to page three. Accept the defaults as shown in the screenshot below (context root my-test-app, content directory WebContent and Java source directory src).
    New Web Project (Step 3)
    Click on Finish to close the wizard and let Eclipse create the project for you. There might be some popups asking you for accepting various license agreements. You must agree in order to continue.

Step 2: Create a simple JSP

  1. In the Project Explorer (in the J2EE perspective) expand the Dynamic Web Projects item right click on our project my-test-app and select New – JSP.
  2. In the New JavaServer Page wizard enter a file name (index.jsp) and select my-test-app/WebContent as the parent folder.
    New JavaServer Page (Step 1)
    Click Next to proceed to the next page and select a template for the JSP.
    New JavaServer Page (Step 2)
    Click on Finish to let the wizard create the JSP for you.
  3. You may now enter some really simply JSP code into the body tag of the generated JSP. I’ll use < %="Cool Technology."%> in this tutorial.

Step 3: Have a break

Writing this tutorial takes longer than I thought. Time for get some fresh coffee. :mrgreen:

So far, we configured a server runtime and created a web project with a simple JSP file. The project was associated with the created Resin v3 server runtime.

A server runtime defines the basic runtime enviornment of the server. For developers, the most easiest important benefit might be the generated classpath container. It automatically contributes all default Resin 3.0 JARs to the classpath of your project. See the following screenshot for details.

Project Overview

You may noticed that the server runtime doesn’t care about server specific parameters such as deployment directory, server address, etc. Eclipse WTP seperated this information into server instances. In the next step we’ll now create a server instance where our project is automatically deployed to. We will then start this server instance to preview our JSP.

Step 4: Run the JSP

  1. Right click inside the JSP editor and select Run As – Run on Server.
    Run on Server
  2. The Run on Server wizard starts with the Define a New Server page because we haven’t defined a server instance yet and the project is not bound to any server instance. Select the server type Caucho – Resin v3.0 and our created Resin v3.0 server runtime. It’s also useful to check the Set server as project default option because we are not going to develop & run this project on multiple server instances.
    New Server Instance (Step 1)
    Click Next to proceed.
  3. On the next page different parameters need be defined. These parameters will be used for deploying the web application and starting the Resin server. They are passed to the command line when starting Resin and that’s why you should use my sample Resin configuration in this tutorial.The configuration uses the parameter submitted via the command line and sets the deployment directory and the port automatically.
    The advantage of this approach is that you don’t have to edit the configuration if you want another port or a different deployment directory (for example, when developing multiple branches of the same application in different workspaces). Of cource, you can adapt the configuration to you needs.The following screenshot shows the values I entered into the page.
    New Server Instance (Step 2)
    No surprise. πŸ˜‰ Actually, these are the ones I suggested in this tutorial. Fine. Click Next to proceed to the last page.
  4. On the last page we configure which projects should be deployed on this server instance. Just make sure that our project my-test-app is listed on the right side under Configured projects.
    New Server Instance (Step 3)
    Now click on Finish and a lot magic will happen. πŸ™‚

Eclipse will now deploy our project to the server instance and start the server instance. Eclipse will also open the JSP its embedded browser (which is actually an Internet Explorer on my platform). BTW, if there is a warning from your desktop firewall software you should allow the open port request. Otherwise you won’t see anything in the browser. πŸ˜‰

The result should look similar to the following screenshot.

The Result

Step 5: Stopping the server

Unfortunately, you need to stop the server with a little workaround. I couldn’t figure out how to stop a running Resin instance from within a Java application or from the command line. If you now how to do this please tell me.

  1. Switch to the Console view and select the console of the running Resin v3 instance. Use the Terminate button to stop the server. If the Console view is not visible it can be opend with Window – Show View – Other… – Basic – Console.
    Stop Server

Done

We are now done with this little tutorial. Any feedback is welcome. Please use my blog’s comment feature for this. If you are interested in the development of this plug-in you should have a look at bug 130733.

Happy coding!

Changelog

  • 2007-05-22
    • Published plug-in on my update site.
    • Changed requirements and added note about Webtools 2.0
    • Updated tutorial for Eclipse Europa

17 thoughts on “Resin Plug-in for Eclipse

  1. The link to the Caucho website seems dead or like it has changed?

    As far as I know Resin, there is no EJB container in it. How many other Java Enterprise servers have you seen, that WTP (1.0 or above) successfully launch and deploy to when using ALL of Java EE (including EJB) ??

    I so far got very good results with Sun’s Glassfish, but any other App Server including EJB or similar EE technologies failed to deploy those modules (thus the entire EE deployment failed, too ;-/)
    When limited to JSP or similar Web technologies only (such as in your post) it worked fine for pretty much all of them (Tomcat, Geronimo or JonAS, have not tried JBoss 4 yet)

  2. Which link are you talking about? I tried the wiki link and the download link. They work both for me.

    And yes, the deployment support is limited to web projects. I only played with WTP and Tomcat before because I didn’t need to care about all this EJB make it enterpise and make it complicated stuff.

    At my former employer we didn’t have such problems because EJBs were generate from Rose models and didn’t need a special deployment. The application server was kind of simplified. :mrgreen: Then we realized that EJB sucks and doesn’t give us the advantages we need and our persistence guru wrote an OR mapper that was more performant and more stable than the EJB or JDO stuff that was available at that time.

    Another great benefit of an OR mapper is that you just need a Servlet/JSP engine to run in. No need for heavy memory eating enterpise software. πŸ˜‰

  3. Hi gunnar

    We use resin 2.1.4 and 3.0.7, which differs and require different jar’s, I suppose. Have you given a try with those versions?

  4. Hi gunnar

    There isn’t the selection of Caucho – Resin v3 in the New Server Runtime wizard , Would you tell me how can i go through with the steps of configuration?

  5. Hi Daniel,

    You need to make sure that the plug-in is installed properly. Got to Help – About Eclipse SDK – Plug-in Details and verify that the Plug-in is listed there.

    If it doesn’t appear in this list you should check the Eclipse log file for any error message regarding the installation/activation of this plug-in. You may also try to remove the directories <eclipse>/configuration/org.eclipse.update, <eclipse>/configuration/org.eclipse.osgi and <eclipse>/configuration/org.eclipse.core.runtime before starting Eclipse.

    Cu, Gunnar

  6. Hi gunnar,

    There is problem when i run a JSP, the error message show as follows:

    500 Servlet Exception

    Resin can’t execute the compiler `javac’. This usually means that the compiler is not in the operating system’s
    PATH or the compiler is incorrectly specified in the configuration. You may need to add the full path to .

    Would you tell me how can i go through with this problem? ( I use JDK1.5, Have you given a try with this
    versions? )

  7. Hi gunnar,

    When i given a try with 1.4.2 JDK for running Resin, it works for me. But there is another problem arise, the error message show as follows:

    500 Servlet Exception

    E:\resin\webapps\GZJD\WEB-INF\work\_jsp\_martyr__jsp.java:10: cannot access com.caucho.jsp.JavaPage
    bad class file: lib\resin.jar(com/caucho/jsp/JavaPage.class) class file has wrong version 48.0, should be 47.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.

    public class _martyr__jsp extends com.caucho.jsp.JavaPage{
    ^
    1 error

    What’s the meaning of “class file has wrong version 48.0, should be 47.0” ? Have you met this problem?

  8. Hi!

    That looks weird. The error message says that the class file was generated by a newer compiler in a newer format and cannot be loaded by the selected JDK. I haven’t seen this problem before.
    The first problem however happend to me if I did not use a JDK but a JRE to launch Resin and if Resin was configured to use the default compiler.

    Can you look at the configuration? It should work if you use the javac compiler and make sure that it’s available in the environment path.

    Cu, Gunnar

  9. In running the JSP the Error comes “No Launchable artifacts could be found in selection”

  10. Hi Gunnar,
    I thought of a way that you could stop the server with the command line (and could be referenced in Java). Its not the nicest but it should work.

    If you install the server as a service and then just stop and start it using “net start|stop”. Unfortunately I don’t know enough about developing Eclipse plugins to do it.

  11. Thanks for the comments. Actually I already found a way and I’m currently testing it. It seems to work. πŸ™‚ It works like the official way.

    I needed to open a socket when starting Resin where it cans connect to. As soon as I close this socket Resin automatically shuts down.

    What I’m currently trying is to find a better way of publishing only incremental changes and without going the way through the war file. This incremental publishing should happen automatically in the background on save.

    There are a few issues to solve here. First I want to create a Resin configuration automatically. Then there are some WTP issues… 😐 We’ll see.

  12. When adding the Resin runtime I get “Missing classpath entry C:\resin-3.0.19\lib\saaj.jar”. πŸ™ The file is not present in my Resin install. How come?

    Sidenote: It is not possible to add comments in this blog when browsing with referer-headers disabled. It’s not wise to require an optional part of the http spec. πŸ˜‰

  13. Unfortunately, the Jars are hard wired in the server descriptor. I agree it would be better to reduce it to the minimum jars. Just create an empty Jar file with that name as a workaround.

    Re Sidenote: This keeps my blog spam free and my moderation work very, very low. πŸ™‚

  14. Had the same problems with the server definition when using 3.0.20 (and 3.0.21). I edited the plugin and fixed the jars in the server-descriptor. Had some other issues to.

    Ofcourse I’m willing to share the updated version. Have sended a version to Gunnar.

Comments are closed.