Integrating JRun 4.0 with NetBeans IDE 4.1

Yesterday I came across an article by Drew Falkman called IDE Wars: Has NetBeans 4.1 Eclipsed Eclipse?. It is very cool, full of praise for NetBeans IDE 4.1, but in the third part of his story I read the following:

"NetBeans is tightly tied into either TomCat (5 or 5.5) and Sun's J2EE application server. I found no discernable way to integrate with JRun (which I use), and a quick search at their Web site turned up virtually no results or plug-ins or anything which could help me—or any other developer who has opted for a non-Sun backed J2EE application server. With all the great features in this IDE, this might be the Achilles heel."

Well, in previous blog entries, I've shown how JBoss and Tomcat 4 can be integrated with the IDE. Since Drew misses JRun integration in the IDE, let's work through it and see how easy it all is. Before going further, I came across something else (also by Drew Falkman): On this page there is a list of IDE's and how JRun can integrate with them. Interestingly, the Eclipse 2.01 story stretches across 13 pages (admittedly, many of them are filled with screenshots). There's got to be an easier way of doing things with Ant. And there is! So, here's all that needs to be done:

  1. Download and install JRun 4. If you're using JDK 1.5, make sure you also install the JRun 4 Updater 5. (I think the JDK 1.5 issue was fixed in Updater 4, but getting the very latest updater is probably a good idea anyway.)
  2. Integrate the JRun Launcher into the IDE by creating the following Ant target in the IDE's Source Editor (or anywhere else):

      <target name="ShowJRunLauncher">
        <exec executable="C:\\JRun4\\bin\\jrun"/>
      </target>
    Note: I added this target to the IDE-wide-targets Ant file that I've been building over the last few days (see previous blog entries). Then I added it as a shortcut to the new "External Servers" menu that I created in yesterday's blog entry:

  3. Click the JRun Launcher menu item and the following handy little tool appears:

  4. Select the default server (its port number is 8100), and click Start.

  5. In NetBeans IDE 4.1, create your application. (While working on this procedure, I created the free-form project that is shipped with the IDE and described in the second section of the Importing Existing Web Applications into NetBeans IDE 4.1 document.)
  6. Build your application to the JRun deployment folder, as shown below:

      <target name="-Compile-Classes-To-JRun" description="Compile classes to JRun">
    
        <mkdir dir="${build.dir.jrun}/WEB-INF/classes"/>
    
        <javac srcdir="${src.root}"
              destdir="${build.dir.jrun}/WEB-INF/classes"
                debug="${compile.debug}"
          deprecation="${compile.deprecation}"
             optimize="${compile.optimize}"/>
    
        <copy  todir="${build.dir.jrun}/WEB-INF/classes">
          <fileset dir="${src.root}" excludes="${build.classes.excludes.jrun}"/>
        </copy>
     
      </target>
      <target name="-Copy-Web-Files-To-JRun" description="Copy web files to JRun">
    
        <mkdir dir="${build.dir.jrun}/>
        
        <copy todir="${build.web.dir.jrun}">
          <fileset dir="${web.root}" excludes="${build.web.excludes.jrun}" />
        </copy>
     
      </target>
      <target name="aaa_Build-To-JRun" depends="-Compile-Classes-To-JRun,-Compile-Web-Files-To-JRun"/>
    

    (By the way, Ant targets that are prefaced with "-" cannot be run independently and are greyed-out in the Projects/Files windows. Personally, I preface the targets that I need most with aaa_ so that they end up at the top of the list in the Projects/Files windows.)

    Update: I've discovered a much more efficient way of doing this! Click here for details.

    These are the properties I used (the port.number.jrun property is used in the next target):

    #This property is the key to everything, because 
    #C:/JRun4/servers/default is the JRun default server's 
    #deployment directory and ant.project.name is the 
    #name of the project, as specified in the project.xml file 
    #when you create the project:
    
        build.dir.jrun=C:/JRun4/servers/default/${ant.project.name}
    
    #Where the Java sources and web files are built to, and what is 
    #excluded from it, within build.dir.jrun:
    
        build.classes.dir.jrun=${build.dir.jrun}/WEB-INF/classes
        build.classes.excludes.jrun=\*\*/\*.java,\*\*/\*.form
        build.web.dir.jrun=${build.dir.jrun}
        build.web.excludes.jrun=${build.classes.excludes.jrun}
    
    #Compilation options:
    
        compile.debug="true"
        compile.deprecation="false"
        compile.optimize="true"
    
    #Only these properties should ever need to be changed:
    
        port.number.jrun=8100
        src.root=path-to-my-src-folder
        web.root=path-to-my-web-folder

    Note: I added the targets to the project-specific-targets Ant file (and the properties to the related properties file) that I've been building over the last few days. This means I can import the targets into any new or existing web application. This also means I won't accidently delete them when I delete the project.

  7. Then simply deploy the application (we're using the port.number.jrun property defined above):

      <target name="aaa_Deploy-To-JRun" description="Deploy to JRun">
        <nbbrowse url="http://localhost:${port.number.jrun}/${ant.project.name}"/>
      </target>

    Note: Again, this Ant target is part of my project-specific-targets Ant file (see previous blog entries) so that I can re-use it in each project that needs it (and protect it from destruction).

  8. Finally, I can add contextual menus to each of my free-form IDE projects (not to standard IDE projects), so that I can right-click a project node and choose the target I need.

    (This is explained below in the blog entry "Customized Contextual Menu for Deploying from NetBeans IDE 4.1".)

This way, the JRun libraries are not included in my project, instead of that I've used Ant to access all the required executables, libraries, and files. This might be a disadvantage, I don't know. (Including the libraries shouldn't be difficult, for example, read How to setup a basic Struts project using NetBeans IDE 4.0.) The Integrating JRUN server with Eclipse 2.01 document goes on to explain how you can use JRun for debugging. Well, this is also possible from NetBeans IDE 4.1. What you need to do is the following, if you're using shared memory (for socket connections, the procedure is similar):

  1. Add this to java.args in JRun's jvm.config file:

    -Xdebug -Xrunjdwp:transport=dt_shmem,server=y,suspend=n

  2. Click the JRun Launcher menu item defined in the previous section, stop the default server and start it again. Using the change to the java.args setting, the default server now starts in debug mode. You should now see the following in the JRun Launcher window at the bottom of the IDE:

    Listening for transport dt_shmem at address: javadebug
    Starting Macromedia JRun 4.0 (Build 92909), default server

  3. In the IDE, choose Run > Attach Debugger. Choose the shared memory connector in the Connector field and make sure that you specify "javadebug" in the Name field.

So, unless I've misunderstood something, this is all that's needed to integrate JRun with NetBeans IDE 4.1. To me, the coolest parts of the whole integration are the following:

  • You can call the JRun Launcher from the IDE, by creating an Ant script and linking it as a shortcut to a menu item in the toolbar. The JRun Launcher is really nice (I haven't found anything similar in Tomcat or JBoss). By integrating it into the IDE, it's almost as if the JRun Launcher is part of the IDE, because it is just as accessable as any other IDE tool, like the Library Manager or Server Manager. And you can view its output in the JRun Launcher window in the IDE.
  • Ant integration makes it easy to build an application from the IDE (one click on a menu item or toolbar button, or via a keyboard shortcut) to JRun's deployment directory. Once the application is there, JRun automatically deploys it and you can access it via an Ant script that simply launches a browser and points to the JRun server's port number.

In short, Ant integration with NetBeans IDE 4.1 (and everything in this blog entry should be possible in NetBeans IDE 4.0 too) has yet again proved its usefulness...


Update 04/20/05:


Comments:

Netbeans, Jrun4 integration:

Alternately you can add your own task in your projects build.xml (see them below). Then you can set your run task in the project properties to execute the "run" target in the build file. After this key F6 will deploy you app and launch Jrun and you can see the output in the output window of netbeans.

You can also hook-up stopJrun task as a context menu in your project. (This is not very elegant, but it works. Not elegant because the context menu is displayed only in the Projects window and not the File window so to stop, you have to switch to Projects window, right-click on you project and choose to stop jrun).

Assumption 1: Jrun is intalled on c:\\Jrun4
Assumption 2: Your are trying to deploy you app in default server

<target name="deploy" depends="war">
<copy file="xyz.war" todir="c:/JRun4/servers/default" />
</target>

<target name="run" depends="deploy">
<exec executable="C:\\JRun4\\bin\\jrun">
<arg value="start" />
<arg value="default" />
</exec>
</target>

<target name="stopJrun" depends="deploy">
<exec executable="C:\\JRun4\\bin\\jrun">
<arg value="stop" />
<arg value="default" />
</exec>
</target>

Thanks
Jayakumar Padmanathan

Posted by Jay Padmanathan on May 09, 2006 at 01:29 AM PDT #

Hi, thanks for this tip Jay!

Posted by Geertjan on July 09, 2006 at 08:09 AM PDT #

Hi geertjan,

Please give clear view how to intergate the jrun 4 with netbeans 5.5.1.In netbeans IDE,the application and web server such that jrun and IIS not found default application and web server list.so please give assitant how to configure or intergate the jrun with netbeans IDE
Regards
Karthikeyan

Posted by karthikeyan on July 14, 2008 at 04:44 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
24
25
26
27
28
29
30
   
       
Today