You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Dietrich Schulten <sc...@escalon.de> on 2005/10/18 00:54:07 UTC

[M2] Eclipse WTP Web app libraries

Hi,

how does the m2 eclipse plugin determine the path where it looks for web
app libraries when used for dynamic web projects?

I have the problem that eclipse complains about a missing
WEB-INF/classes classes folder, which seems to come from a "Web app
library [artifact]" containing a my-webapp/WEB-INF/classes source path
with a marker saying "(missing)".

Usually the web app libraries are used to add jars to a deployment which
are automatically used for building, as well. The web app libraries are
manipulated by copying jars to WEB-INF/lib.
The my-webapp/WEB-INF/classes source entry seems to make no sense here,
I would expect src/main/webapp/WEB-INF/lib.

Can anyone explain how m2 would insert jars into the web project so that
they end up in the .deployables folder in such a way that they can be
used for debugging right away?

I would expect the eclipse plugin to add jars meant for deployment to
WEB-INF/lib, and to create the appropriate classpath entry. In a war the
jars should certainly be in ./lib, not in ./classes.

I run m2 eclipse:eclipse with the following pom.xml

<project>
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.mycompany.app</groupId>
	<artifactId>my-webapp</artifactId>
	<packaging>war</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>Maven Webapp Archetype</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<finalName>my-webapp</finalName>
		<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-eclipse-plugin</artifactId>
			<configuration>
				<buildcommands>				
<java.lang.String>org.eclipse.wst.common.modulecore.ComponentStructuralBuilder</java.lang.String>
<java.lang.String>org.eclipse.jdt.core.javabuilder</java.lang.String>
<java.lang.String>org.eclipse.wst.validation.validationbuilder</java.lang.String>
<java.lang.String>org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver</java.lang.String>
<java.lang.String>org.eclipse.wst.common.modulecore.DependencyGraphBuilder</java.lang.String>
				</buildcommands>
				<classpathContainers>
<java.lang.String>org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache
Tomcat v5.0</java.lang.String>
<java.lang.String>org.eclipse.jst.j2ee.internal.web.container/artifact</java.lang.String>
				</classpathContainers>
				<projectnatures>
<java.lang.String>org.eclipse.jem.workbench.JavaEMFNature</java.lang.String>
<java.lang.String>org.eclipse.jdt.core.javanature</java.lang.String>
<java.lang.String>org.eclipse.wst.common.modulecore.ModuleCoreNature</java.lang.String>
				</projectnatures>
			</configuration>	
			</plugin>
		</plugins>
	</build>
</project>

What I get is:

<classpath>
	<classpathentry output=".deployables/my-webapp/WEB-INF/classes"
kind="src" path="src/main/java"/>
	<classpathentry output=".deployables/my-webapp/WEB-INF/classes"
kind="src" path="src/main/resources"/>
	<classpathentry sourcepath="JRE_SRC" kind="var" rootpath="JRE_SRCROOT"
path="JRE_LIB"/>
	<classpathentry kind="var"
path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
	<classpathentry kind="con"
path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache
Tomcat v5.0"/>
	<classpathentry kind="con"
path="org.eclipse.jst.j2ee.internal.web.container/artifact"/>
	<classpathentry kind="output" path="target/classes"/>
</classpath>

and the .wtpmodules
<project-modules id="moduleCoreId">
  <wb-module deploy-name="my-webapp">
    <module-type module-type-id="jst.web">
      <version>2.4</version>
      <property name="context-root" value="my-webapp"/>
    </module-type>
    <wb-resource deploy-path="/" source-path="/src/main/webapp"/>
    <wb-resource deploy-path="/WEB-INF/classes"
source-path="src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes"
source-path="src/main/resources"/>
  </wb-module>
</project-modules>

Regards,
Dietrich


Re: [M2] Eclipse WTP Web app libraries

Posted by Stephen Duncan <st...@gmail.com>.
To get your jar files from target/my-webapp/WEB-INF/lib to
src/main/webapp/WEB-INF/lib (and therefore it should go to
.deployables), you can run: mvn war:inplace

-Stephen

On 10/21/05, Dietrich Schulten <sc...@escalon.de> wrote:
> I've made some progress, see below:
>
> Dietrich Schulten schrieb:
> > Hi Fabrizio,
> >
> > thank you for your quick reply. Comments inline.
> >
> > Fabrizio Giustina schrieb:
> >
> >>On 10/18/05, Dietrich Schulten <sc...@escalon.de> wrote:
> >>
> >>
> >>>how does the m2 eclipse plugin determine the path where it looks for web
> >>>app libraries when used for dynamic web projects?
>
> I added an additional deploy-path to the .classpath and Eclipse copies
> the WEB-INF/lib jars from target/WEB-INF/lib to .deployables:
>
> <wb-resource deploy-path="/WEB-INF/lib"
> source-path="/target/my-webapp/WEB-INF/lib"/>
>
> This seems to be exactly what is desirable:
> Eclipse uses target/WEB-INF/lib for .deployables/WEB-INF/lib, and builds
> src/main/java to .deployables/WEB-INF/classes.
>
> One problem remains: You must make sure that Maven does not provide
> project dependencies in target.
>
> Do you agree that this would be a good solution? If so, I could try to
> provide a patch for the plugin.
>
> > I assumed, some magic might replace the artifactId for artifact. M2
> > newbie question: Is it possible to refer to the artifactId, as if it
> > were a variable, in the pom.xml?
>
> ${artifactId} does it
>
> Regards
> Dietrich
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


--
Stephen Duncan Jr
www.stephenduncanjr.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [M2] Eclipse WTP Web app libraries

Posted by Dietrich Schulten <sc...@escalon.de>.
I've made some progress, see below:

Dietrich Schulten schrieb:
> Hi Fabrizio,
> 
> thank you for your quick reply. Comments inline.
> 
> Fabrizio Giustina schrieb:
> 
>>On 10/18/05, Dietrich Schulten <sc...@escalon.de> wrote:
>>
>>
>>>how does the m2 eclipse plugin determine the path where it looks for web
>>>app libraries when used for dynamic web projects?

I added an additional deploy-path to the .classpath and Eclipse copies
the WEB-INF/lib jars from target/WEB-INF/lib to .deployables:

<wb-resource deploy-path="/WEB-INF/lib"
source-path="/target/my-webapp/WEB-INF/lib"/>

This seems to be exactly what is desirable:
Eclipse uses target/WEB-INF/lib for .deployables/WEB-INF/lib, and builds
src/main/java to .deployables/WEB-INF/classes.

One problem remains: You must make sure that Maven does not provide
project dependencies in target.

Do you agree that this would be a good solution? If so, I could try to
provide a patch for the plugin.

> I assumed, some magic might replace the artifactId for artifact. M2
> newbie question: Is it possible to refer to the artifactId, as if it
> were a variable, in the pom.xml?

${artifactId} does it

Regards
Dietrich


Re: [M2] Eclipse WTP Web app libraries

Posted by Dietrich Schulten <sc...@escalon.de>.
Hi Fabrizio,

thank you for your quick reply. Comments inline.

Fabrizio Giustina schrieb:
> On 10/18/05, Dietrich Schulten <sc...@escalon.de> wrote:
> 
>>how does the m2 eclipse plugin determine the path where it looks for web
>>app libraries when used for dynamic web projects?

> if you run m2 eclipse
> from a parent project and some of these dependencies are in the list
> of compiled modules they will be added as a module dependencies
> instead of jars.

I added springframework 1.2.5 as dependency.
m2 retrieves the jar and puts it to
ws\my-webapp\target\my-webapp\WEB-INF\lib
It also makes it to the m2-built war from there.

Eclipse is informed about the jar by adding
M2_REPO/springframework/spring/1.2.5/spring-1.2.5.jar
to .classpath

So this works almost as I hoped.

However, eclipse does not understand that it should add this lib from
the target folder to .deployables, from where Eclipse debugs the
application using Eclipse's tomcat integration.
Rather Eclipse seems to expect the lib in the
src\main\webapp\WEB-INF\lib folder. I manually copied it there, and
Eclipse automatically inserted spring.1.2.5.jar into the web apps
library and .deployables.

That would mean I have to manually copy everything from
target/my-webapp/WEB-INF/lib to src/main/webapp/WEB-INF/lib
Probably this is not how it is meant to be:

How can I provide external jars for a parent project, so that they
"appear in the list of compiled modules and are added as module
dependencies", as you said above? I created a parent pom.xml and used m2
eclipse:eclipse from the parent folder. I also updated the child pom.xml
files to have a parent element that points back to the parent.

My parent pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <version>1.0-SNAPSHOT</version>
  <artifactId>app</artifactId>
  <packaging>pom</packaging>
  <modules>
    <module>my-app</module>
    <module>my-webapp</module>
  </modules>
</project>

Also missing is the project dependency from my-webapp to my-app, Eclipse
does not get the dependency yet.


>>I have the problem that eclipse complains about a missing
>>WEB-INF/classes classes folder, which seems to come from a "Web app
>>library [artifact]" containing a my-webapp/WEB-INF/classes source path
>>with a marker saying "(missing)".

This disappeared after I selected my-webapp instead of artifact in
Eclipse. So I have to enter the artifactId in the pom.xml like so:

<java.lang.String>
org.eclipse.jst.j2ee.internal.web.container/my-webapp
</java.lang.String>

instead of

<java.lang.String>
org.eclipse.jst.j2ee.internal.web.container/artifact
</java.lang.String>

I assumed, some magic might replace the artifactId for artifact. M2
newbie question: Is it possible to refer to the artifactId, as if it
were a variable, in the pom.xml?

Thank you for all your hard work. Do you have a HOWTO already? Maybe I
could write one if I get all this to work.

Regards,
Dietrich


Re: [M2] Eclipse WTP Web app libraries

Posted by Fabrizio Giustina <fg...@gmail.com>.
On 10/18/05, Dietrich Schulten <sc...@escalon.de> wrote:
> how does the m2 eclipse plugin determine the path where it looks for web
> app libraries when used for dynamic web projects?

all the jar dependencies of a web project are added as "var"
dependencies and fetched from the local m2 repo. if you run m2 eclipse
from a parent project and some of these dependencies are in the list
of compiled modules they will be added as a module dependencies
instead of jars.

> I have the problem that eclipse complains about a missing
> WEB-INF/classes classes folder, which seems to come from a "Web app
> library [artifact]" containing a my-webapp/WEB-INF/classes source path
> with a marker saying "(missing)".

This seems to be a problem with the eclipse server container classpath
entry: it always assumes you have classes in your webapp and it
reports this error if the classes folder doesn't exist (or if it has
not been created yet)


> Can anyone explain how m2 would insert jars into the web project so that
> they end up in the .deployables folder in such a way that they can be
> used for debugging right away?

Looking at your sample .project you don't have any dependency defined
in pom.xml (except for a test only dependency which is not included in
the war)... the plugin will not copy jars already in
src/main/webapp/WEB-INF/lib, these dependencies must be added "in the
maven way" to pom.xml


fabrizio

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org