facebook

ResourceLink for Web Mod on Tomcat? [Closed/Walkthrough]

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #209806 Reply

    Brice Ruth
    Member

    I’m trying to use MyEclipse to deploy a project that I previously created outside of MyEclipse (trying to bring it “into the fold”). Previously, the project has been deployed using Ant’s Tomcat/Catalina deploy tasks, which take a context file and use it to deploy the application.

    The Context for this application specifies a data source (connection to DB2 iSeries database). Now, my understanding has been that MyEclipse doesn’t support defining the data source in the context when deploying … so, I’ve defined the data source in Tomcat itself (using the admin tool) – which binds the data source to a JNDI name. That JNDI name then needs to be linked to the application context using a ‘ResourceLink’ property (typically in context.xml) – and then within the web.xml, a resource-ref is defined for the JNDI data source referenced in the ResourceLink.

    Now – I’m not seeing any way to do this elegantly with MyEclipse. I’m deploying to Tomcat 5.0.25. The reason I need to automate this is to simplify and hide the details from the rest of the development team.

    I thought that deploying as a packaged WAR might cause Tomcat to pick up the context.xml in the META-INF directory (a new feature in tomcat 5.x) – but MyEclipse pretty much crashes when it tries to deploy this application as a packaged WAR, since its pretty big (over 100MB, zipped). It only finishes writing about 75% of the .WAR file before it errors out with a blank error dialog. Nevermind that it takes forever to package up all that – so it wouldn’t really be an option anyway.

    Ugh … I’m trying to get all our applications under MyEclipse, but the deployment capabilities of MyEclipse just aren’t mature enough, it seems.

    Respectfully,
    Brice Ruth

    #210064 Reply

    Scott Anderson
    Participant

    Brice,

    I thought that deploying as a packaged WAR might cause Tomcat to pick up the context.xml in the META-INF directory (a new feature in tomcat 5.x) – but MyEclipse pretty much crashes when it tries to deploy this application as a packaged WAR, since its pretty big (over 100MB, zipped).

    Actually, we’ve deployed applications larger than this. The issue might simply be an OutOfMemory exception or something. Are you running Eclipse with addition vm arguments to increase the heap size? How about starting eclipse.exe like: eclipse.exe -vmargs -Xms256M -Xmx512M. Also, we’d be able to diagnose the issue a little better if you’d posted the information we request in the Posting Guidelines thread at the top of the forum. Can you do that and also include any entries that have been written to the log file at <workspace>/.metadata/.log.

    Also, for large deployments, we really recommend using our exploded deployment option. That way, once the initial deployment has completed the deployment is kept in sync on a file-by-file basis, thus avoiding any large deployments from that point forward. It really makes large project deployments work much better. Simply deploy as exploded archive, start Tomcat, and you should be good to go.

    #210089 Reply

    Brice Ruth
    Member

    @support-scott wrote:

    Also, for large deployments, we really recommend using our exploded deployment option. That way, once the initial deployment has completed the deployment is kept in sync on a file-by-file basis, thus avoiding any large deployments from that point forward. It really makes large project deployments work much better. Simply deploy as exploded archive, start Tomcat, and you should be good to go.

    As I wrote in my post, I would love to deploy as an exploded archive … this is what we were doing with the Ant deployments. However, I cannot get the web application to access a JNDI defined data source. If you can provide guidance on this, I would be most appreciative.

    I will also attempt to gather the information requested.

    #210107 Reply

    Riyad Kalla
    Member

    bdruth,
    To get JNDI contexts in Tomcat 5 working do the following:
    1) Define it using the administrator, like you did, which will create a new xml file under Tomcat 5/conf/Catalina/localhost for you.

    That’s it… don’t reference it in your web.xml file, don’t reference it in a resource link, don’t do anything. Just start writing code to use it:

    
    try
    {
        dataSource = (DataSource) (new InitialContext()).lookup("java:comp/env/jdbc/whatever");
    }
    catch (NamingException e)
    {
        e.printStackTrace();
    }
    

    Where “whatever” is your context name. I’ve done this 100 times on Tomcat 4.1 and 5.0 and it works. When I first started using Tomcat with Tomcat 4.0 I remember reading those damned docs talking about defining this, and that, and this and that… then by accident I only defined the context and started trying used it, and it worked fine ever since.

    #210108 Reply

    Riyad Kalla
    Member

    Hey also, if you create this new context and set it up correctly, you not only need to save changes in the administrator, you need to Commit Changes, this will write out the new file and make it persist across Tomcat restarts. Now you can deploy your app however you want with MyEclipse and it will work fine.

    #210116 Reply

    Brice Ruth
    Member

    @support-rkalla wrote:

    Hey also, if you create this new context and set it up correctly, you not only need to save changes in the administrator, you need to Commit Changes, this will write out the new file and make it persist across Tomcat restarts. Now you can deploy your app however you want with MyEclipse and it will work fine.

    Right, I did commit the changes (second time around … didn’t notice that button the first time).

    Here’s the catch … the application uses iBatis, which looks for the data source by defining it like so:

    <sql-map-config>
        <datasource name="webpdb" factory-class="com.ibatis.db.sqlmap.datasource.JndiDataSourceFactory" default="true">
            <property name="DBInitialContext" value="java:comp/env"/>
            <property name="DBLookup" value="/jdbc/webpdb"/>
        </datasource>
        <sql-map resource="com/fiskars/wpi/ibatis/Product.xml"/>
    </sql-map-config>
    

    In my mind, this is looking at the same place as what you’ve just provided Java code for … but, it isn’t working as far as I can tell. Argh!!!

    My data source in the administrator is defined as ‘jdbc/webpdb’ … I wonder if there’s any way to figure out if Tomcat is running into errors creating the data source, binding its JNDI name or something to that effect … I’ll go down that road and see where it takes me. In the meantime ..

    Any ideas? The iBatis DAO/Framework can be seen here: http://www.ibatis.com/

    #210120 Reply

    Riyad Kalla
    Member

    That is frustrating… I don’t know how iBatis works, but you are right, you might need the web.xml entries for it, I have no idea.

    This has got to be a common question though, don’t they have forums or mailing list?

    #210123 Reply

    Brice Ruth
    Member

    @support-rkalla wrote:

    That is frustrating… I don’t know how iBatis works, but you are right, you might need the web.xml entries for it, I have no idea.

    This has got to be a common question though, don’t they have forums or mailing list?

    Indeed, they do. I guess I need to ask how I can get iBatis to work with a data source defined in the Tomcat administration tool, vs. defining it in the web.xml file.

    I’m not sure that having 15 different ways to do the same thing is a good idea in this case. Argh again!

    #210130 Reply

    Riyad Kalla
    Member

    I’m not sure that having 15 different ways to do the same thing is a good idea in this case. Argh again!

    Haha, I know the feeling.

    #210138 Reply

    Brice Ruth
    Member

    OK, so the short answer, is this: defining a <resource-ref> in web.xml and defining a <ResourceLink> in the web-application’s Context, is necessary to create a JNDI link between the application’s Context, and the Global Context that is created by Tomcat (and where the DataSource defined through the administrator lives).

    I don’t actually see any way around this …

    On a somewhat separate note, what activities in MyEclipse will cause the web-application to be reloaded in Tomcat? I noticed that if I save web.xml, it automatically reloads, but if I save a resource file (a config XML fille for iBatis) which lives in src/com/fiskars/wpi/ibatis, this does not prompt the application context to reload (even though it should) … ?!

    Here are the details (for those coming after me and having questions on this):

      1. Define a DataSource in the Tomcat Administrator tool with a reasonable name (say jdbc/myGlobalDS).
      2. Define a <resource-ref> entry in your web.xml file, that looks like this:

          <resource-ref>
              <res-ref-name>
                  jdbc/myGlobalDS
              </res-ref-name>
              <res-type>
                  javax.sql.DataSource
              </res-type>
              <res-auth>
                  Container
              </res-auth>
          </resource-ref>
      

      3. Then deploy your application with MyEclipse as an exploded deployment (our goal here)
      4. Find the context XML file that is created (typically under TOMCAT_HOME/conf/Catalina/localhost) – it will be named the same as the path your application is available under (my app is available under /opc, so the file is called opc.xml)
      5. Open this file, and add a <ResourceLink> directive, like so:

      <ResourceLink
          name="jdbc/myLocalDS"
          global="jdbc/myGlobalDS"
          type="javax.sql.DataSource"/>
      

      6. Save this file – if Tomcat is running, it will automatically reload your context when you save the file.

      This will make a DataSource available to your application under the JNDI path ‘java:comp/env/jdbc/myLocalDS’.

    p.s. You can, of course, use the same name for your Global DataSource as your Local DataSource … it makes no difference, I just used different names in this example to highlight the possibility.

    #210142 Reply

    Scott Anderson
    Participant

    On a somewhat separate note, what activities in MyEclipse will cause the web-application to be reloaded in Tomcat?

    A full application reload is triggered by a web.xml modification. This is a “Tomcat thing”, not a MyEclipse thing. We never request a reload; Tomcat just does it when it detects the modification. Quite handy really so that whenever you want to request a reload, just make an insignificant change to web.xml.

    That said, JSP files will be updated upon modification and Java source will be hotswapped into memory provided you’re running JDK 1.4.1+ and haven’t gone past the limits of what the Sun JPDA spec includes with your modificaitons.

    Also, thanks for the excellent Tomcat tutorial. 🙂

    #210144 Reply

    Riyad Kalla
    Member

    Also if you want to reload your app, just keep the Tomcat Manager open in another browser window and use it to reload the app.

    And yes, thank you very much for the Tomcat HOWTO, I am sure it will be very helpful to others.

    #210152 Reply

    Brice Ruth
    Member

    For completeness:

    What operating system and version are you running?

    Windows XP Pro, SP1

    What Eclipse version and build id are you using? (Help > About Eclipse Platform)

    3.0.0; 200405290105

    – Was Eclipse freshly installed for MyEclipse?

    Yes

    – If not, was it upgraded to its current version using the update manager?
    – Are any other external plugins installed?

    No

    – How many plugins in the <eclipse>/plugins directory are like org.eclipse.pde.*

    6

    What MyEclipse version are you using? (Help > About Eclipse Platform > Features)

    3.7.101

    What JDK version are you using to run Eclipse? (java -version)

    1.4.2_03-b02

    What JDK version are you using to launch your application server?

    1.4.2_03-b02

    What application server are you using?

    Tomcat 5.0.25

Viewing 13 posts - 1 through 13 (of 13 total)
Reply To: ResourceLink for Web Mod on Tomcat? [Closed/Walkthrough]

You must be logged in to post in the forum log in