将具有依赖性的Maven项目部署到在Eclipse中运行的Tomcat或Jboss [英] Deploying a Maven project with dependencies to Tomcat or Jboss running within Eclipse

查看:112
本文介绍了将具有依赖性的Maven项目部署到在Eclipse中运行的Tomcat或Jboss的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在eclipse中有几个相互依赖的Maven项目。其中一些在Spring库中有依赖(Spring core,Spring MVC等)。

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).

当我使用'mvn clean install'构建项目时,maven生成一个war文件并将其放在./target/文件夹中。然后,我可以将此war文件部署到任何正在运行的应用程序服务器上。我已经测试了Tomcat 7和Jboss 7.1.0上的war文件,它运行正常。

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.

如果我尝试直接从eclipse运行项目,我遇到了问题。我希望能够调试服务器代码,我知道这是可能的唯一方法是在eclipse中运行的appserver中运行项目。

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.

我在Eclipse上配置了Tomcat应用服务器。当我然后选择Maven项目并右键单击它并选择Run on Server时,项目将在正在运行的Tomcat实例上进行部署,但由于某种原因它会产生以下错误:

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)

我尝试了同样的方法,即在Jboss实例上运行项目Eclipse和它也抱怨它找不到几个库。它抱怨的大多数库都是Maven POM文件中称为依赖项的库。

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.

我怀疑当我将项目部署到Tomcat或Jboss(使用Jboss工具)时,不会部署依赖项,因此会出错。我是否需要任何其他配置来指示Eclipse部署所有依赖项?

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?

请注意,如果我手动部署war文件,它会起作用。如果我使用eclipse中的Run on Server选项部署它,它就无法工作。

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.

谢谢

推荐答案

我假设你有一个WEB-INF你项目中的某个文件夹。这是否有一个名为lib的子文件夹,其中包含项目所依赖的所有jar文件?

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?

如果没有,则应确保将它们复制到那里。您可以使用maven依赖插件执行此操作:

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>

如果你的位置是WEB -INF文件夹与上面的不一样,记得要更改它。
您还应配置clean插件以在清理时清空此目录。否则,如果删除依赖项,则jar文件仍将位于lib文件夹中。

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.

这篇关于将具有依赖性的Maven项目部署到在Eclipse中运行的Tomcat或Jboss的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆