2

I have several Maven projects in eclipse that depends on each other. Some of these have dependencies in the Spring libraries (Spring core, Spring MVC etc).

When i build the project using 'mvn clean install', maven generates a war file and places it in the ./target/ folder. I can then take this war file and deploy it on any running application server. I have tested the war file on both Tomcat 7 and Jboss 7.1.0 and it works fine.

I have a problem though if i try and run the project directly from eclipse. I would like to be able to debug the server code and the only way i know that this is possible is to run the project in an appserver running within eclipse.

I configured the Tomcat application Server on Eclipse. When i then select the Maven project and right click on it and select 'Run on Server', the project deploys on the running Tomcat instance but for some reason it produces the following error:

12-May-2012 15:48:22 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:124)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4715)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1568)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1558)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    at java.lang.Thread.run(Thread.java:619)
12-May-2012 15:48:22 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)

I tried the same, i.e. run the project on a Jboss instance in Eclipse and it also complains that it cannot find several libraries. Most of the libraries it complains about are those referred to as dependencies in the Maven POM file.

I suspect that when i deploy the project to Tomcat or Jboss (Using Jboss tools), the dependencies are not being deployed hence the errors. Do i need any other configuration to instruct Eclipse to deploy all dependencies as well?

Note that if i deploy the war file manually it works. It just doesnt work if i deploy it using the 'Run on Server' option in eclipse.

Thanks

ziggy
  • 15,677
  • 67
  • 194
  • 287

1 Answers1

4

I assume that you have a WEB-INF folder in your project somewhere. Does this have a subfolder named lib that contains all the jars your project depends on?

If not, you should make sure that they are copied there. You can do this with the maven dependency plugin like this:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
    <execution>
        <phase>process-resources</phase>
        <goals>
            <goal>copy-dependencies</goal>
        </goals>
    </execution>
</executions>
<configuration>
    <outputDirectory>${project.basedir}/src/main/webapp/WEB-INF/lib</outputDirectory>
</configuration>

If the location of you WEB-INF-folder is not the same as above, remember to change it. You should also configure the clean plugin to empty this dir when you clean. Otherwise, if you remove dependencies, the jar-files will still be in the lib-folder.

Ludwig Magnusson
  • 13,964
  • 10
  • 38
  • 53
  • I do have a WEB-INF/lib folder in my application. The libraries get copied when i build the war file. I think what happens is that they dont get copied if i deploy the application directly from eclipse. – ziggy May 14 '12 at 10:01
  • Is this WEB-INF/li located under target or in your development structure? Does the jar-files get copied to both locations? I beliveve that they are only copied to target/_finalname_/WEB-INF/lib and perhaps eclipse does not use that folder when you fire the "Run on server" command. – Ludwig Magnusson May 14 '12 at 11:36
  • Yes they get copied from the Maven repository to target/myApp/WEB-INF/lib when i run 'mvn clean install' but they dont if i use the "Run on Server" command. – ziggy May 14 '12 at 12:17
  • What do you do before you press run on server? What maven commands have you executed? – Ludwig Magnusson May 14 '12 at 12:26
  • 1
    Before the "run on server" command, i would build the project by right clicking on the project and select "Run as " > "maven install". – ziggy May 14 '12 at 12:52
  • After that command, the jars are in /target/app/WEB-INF/lib, right? However, I don't beleive that your tomcat or jboss server is pointed to that folder but rather to your development folder and the jar files are not there. I think that if you add my "code" above to your pom and make sure that the value of _outputdirectory_ is correctly pointed to your development folder, you will be able to run locally. – Ludwig Magnusson May 14 '12 at 13:15