Deploying Dependent Projects to Tomcat via WTP

2k views Asked by At

We are currently using MyEclipse to deploy our projects to Tomcat during development. We would like to dump MyEclipse and switch to WTP. I am using Eclipse 3.7.

Our project layout has a 'web' project and a 'modules' project.

I would like to be able to have each project have its own ivy file declaring its dependencies using IvyDE to create an Eclipse Library of those jars depended upon and have those jars deployed to WEB-INF/lib and the classes from each project deployed to WEB-INF/classes.

I have tried declaring the 'modules' project as a "Utility Module" and the jars from its ivy.xml file as as a part of the Deployment Assembly to WEB-INF/lib and then adding the 'modules' projects to the Deployment Assembly of the 'web' project but what I get is a jar called 'modules.jar' in the WEB-INF/lib of the 'web' project that has the jars for the 'modules' project in its (i.e. modules.jar) WEB-INF/lib directory.

Is it possible to get WTP to deploy from the application structure I have to the deployment layout I want or would I have to reorganize my two projects into one? If so, how would I do it?

2

There are 2 answers

1
oers On

I don't know if this will help, I don't understand your question fully.

You can tell ivyDe to download all jars to a specific directory.

  1. check the "Do retrieve ..." Box
  2. put the relative Path to your WEB-INF/lib into the retrieve pattern like:

    resources/WEB-INF/lib/[artifact]-[type]-[revision].[ext]

enter image description here

0
Eric Milles On

I believe we have a similar configuration to what you are trying to set up. Be sure you have "Resolve dependencies in workspace" checked in the Preferences > Ivy > Classpath pane.

With the setup below, when adding WarProject to Tomcat, you should see a [+] link on the WarProject node and expanding it should show the JarProject node. When publishing, you should see JarProject.jar and any jars defined in it's ivy.xml added to wtpwebapps/WarProject/WEB-INF/lib in Tomcat's publish directory, which for me is in .metadata/.plugins/org.eclipse.wst.server.core/tmp0 under my workspace directory.

Jar project's .settings/org.eclipse.wst.common.project.facet.core.xml:

<faceted-project>
  <fixed facet="jst.java" />
  <fixed facet="jst.utility" />
  <installed facet="jst.java" version="1.6" />
  <installed facet="jst.utility" version="1.0" />
</faceted-project>

Jar project's .settings/org.eclipse.wst.common.component:

<project-modules id="moduleCoreId" project-version="1.5.0">
  <wb-module deploy-name="JarProject">
    <wb-resource deploy-path="/" source-path="/src" />
    <wb-resource deploy-path="/" source-path="/resources" />
  </wb-module>
</project-modules>

Jar project's ivy.xml:

<ivy-module
    version="2.0"
    xmlns:m="http://ant.apache.org/ivy/maven"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
  <info module="JarProject" organisation="org.whatever" revision="${revision}" />
  <configurations>
      <conf name="local" visibility="private"
        description="Artifacts necessary for local development and testing" />
      <conf name="master" />
      <conf name="sources" />
  </configurations>
  <publications>
      <artifact ext="pom" type="pom" />
      <artifact ext="jar" type="jar" conf="master" />
      <artifact ext="jar" type="source" conf="sources" m:classifier="sources" />
  </publications>

  <dependencies defaultconfmapping="*->master(default),runtime()">
    <dependency org="org.jdom" name="jdom" rev="1.0" conf="master" />
    <dependency org="junit" name="junit-dep" rev="4.9" conf="local" />
  </dependencies>
</ivy-module>

War project's .settings/org.eclipse.wst.common.project.facet.core.xml:

<faceted-project>
  <fixed facet="jst.java" />
  <fixed facet="jst.web" />
  <installed facet="jst.java" version="1.6" />
  <installed facet="jst.web" version="2.5" />
  <runtime name="Apache Tomcat v6.0" />

War project's .settings/org.eclipse.wst.common.component:

<project-modules id="moduleCoreId" project-version="1.5.0">
  <wb-module deploy-name="WarProject">
    <property name="context-root" value="WarProject" />
    <wb-resource deploy-path="/" source-path="/WebContent" />
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src" />
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/resources" />
  </wb-module>
</project-modules>

War project's .classpath:

<classpath>
  <classpathentry kind="output" path="bin" />
  <classpathentry kind="src" path="src" />
  <classpathentry kind="src" path="resources" />
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
    <attributes>
      <attribute name="owner.project.facets" value="jst.java" />
    </attributes>
  </classpathentry>
  <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0">
    <attributes>
      <attribute name="owner.project.facets" value="jst.web" />
    </attributes>
  </classpathentry>
  <classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?ivyXmlPath=ivy.xml&amp;confs=local&amp;ivySettingsPath=%24%7Bworkspace_loc%3AWarProject%2Fivysettings.xml%7D&amp;loadSettingsOnDemand=false&amp;propertyFiles=" />
  <classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?ivyXmlPath=ivy.xml&amp;confs=master&amp;ivySettingsPath=%24%7Bworkspace_loc%3AWarProject%2Fivysettings.xml%7D&amp;loadSettingsOnDemand=false&amp;propertyFiles=">
    <attributes>
      <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib" />
    </attributes>
  </classpathentry>
  <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container" />
</classpath>

War project's ivy.xml:

<ivy-module
    version="2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
  <info module="WarProject" organisation="org.whatever" revision="${revision}" />
  <configurations>
    <conf name="local" visibility="private"
      description="Artifacts necessary for local development and testing" />
    <conf name="master" />
  </configurations>

  <dependencies defaultconfmapping="*->master(default),runtime()">
    <dependency org="org.whatever" name="JarProject" rev="latest.integration" changing="true" conf="master" />
    <!-- and other dependencies of the war project -->
  </dependencies>
</ivy-module>

I also found it possible to omit the org.eclipse.jst.component.dependency attribute in the classpath entry for the Ivy classpath container and instead add it to the org.eclipse.wst.common.component file like this:

<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/con/org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?ivyXmlPath=ivy.xml&amp;confs=master&amp;ivySettingsPath=%24%7Bworkspace_loc%3AWarProject%2Fivysettings.xml%7D&amp;loadSettingsOnDemand=false&amp;propertyFiles=">
  <dependency-type>consumes</dependency-type>
</dependent-module>

But under this alternative, the deployed webapp was not updating very nicely if I changed the ivy.xml and ran resolve. Also, any changes to the URL parameters to Ivy needed to be kept in sync with the two files or there would be nothing contributed to the deployment assembly.

No idea how to set all this up through the UI...