views:

1187

answers:

2

I've been working alone on a project for a long time and now another developer joined so I wanted to set up the project on his machine from SVN. We are both using very similar set-ups:

  • OS X Snow Leopard
  • Latest Eclipse WTP
  • m2eclipse Maven Plugin
  • Subversive SVN Plugin
  • Tomcat 6.0.24

The Spring version used is 2.5.6.

I set up the project on his machine using Eclipse's "Project from SVN" tool, essentially creating a 1:1 copy of the project. Maven took care of all dependencies without problems as far as I can tell, the project compiled without problems. The project structure is following the Maven standard for webapps with resources (like the applicationContext.xml) in src/main/resources, the project's code in src/main/java and all web-app related files in src/main/webapp and src/main/webapp/WEB-INF respectively.

The web.xml is configured to load the context like so:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Using the "Servers" tool of Eclipse I tried launching the application right from Eclipse, but it failed immediately with a FileNotFoundException when trying to load the applicationContext.xml.

Since the code checked out from SVN has been left untouched I guess the problem has to do with some parameter for the Maven plugin. Or that I forgot some important step to finalize the set-up. Has anybody encountered a similar issue or has an idea where I should start looking?

Thank you very much for you help!

+1  A: 

When launching the application with the servers plugin, it expects that your web folder contains everything needed. That's why you have to configure your project output folder (from the project build path options) to be src/main/webapp/WEB-INF/classes

Alternatively you can use the FileSync plugin to copy the files.

Btw, you didn't specify what are the options for the Servers plugin, and whether your project is a "Dynamic Web Project" (i.e. deployable) or not.

Bozho
I don't think that configuring the output folder to be `src/main/webapp/WEB-INF/classes` is a good idea. And FYI, a project with a packaging of type `war` will be recognized as a "Dynamic Web Project" by default if you have the m2eclipse WTP support (which is likely the case here).
Pascal Thivent
and will it be updated on-save? In my current configuration the output folder is default (target/classes), but I'm using FileSync so that the whole maven build isn't needed on a single change in the xml. Otherwise the maven build will be invoked, which is OK, but is a bit slower.
Bozho
I'm not saying it's a perfect solution but generating stuff in `src` is really not great IMO (won't be cleaned by `clean`). Generated stuff should go in `target`. And ultimately, the m2eclipse plugin should be improved :)
Pascal Thivent
Agreed about m2eclipse :) And also that src should be clean - that's why I'm using FileSync. But I've seen such configurations, and they worked (with proper svn:ignore of course)
Bozho
+2  A: 

The project structure is following the Maven standard for webapps with resources (like the applicationContext.xml) in src/main/resources, the project's code in src/main/java and all web-app related files in src/main/webapp and src/main/webapp/WEB-INF respectively.

This is correct and perfectly fine (as you want the applicationContext.xml to be on the tests class path).

It is not copied to WEB-INF/classes, but that's not the case in my own (functioning) project. Instead, the file is copied to target/classes as per Maven-standard.

It is copied to target/yourapp/WEB-INF/classes, but not by process-resources which is called by default by m2eclipse on resource changes (this goal copies/filters resources to target/classes). This happens during the package phase (or when invoking explicitly war:war, war:inplace or war:exploded). As explained in the usage page, the WAR Plugin is not responsible for compiling the java sources or copying the resources.

So I'd suggest to package the war before to run it on a Server. Maybe you can configure m2eclipse to do this automatically on resource changes (right-click on your project, then select Properties > Maven and add the appropriate war goal to the Goals to invoke on resource changes). Didn't try this though.

Pascal Thivent
Thank you very much, this fixed the problem. By doing this I also came across a permission issue on our Maven proxy, so that came as a nice bonus on top.
Lunikon