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

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

问题描述

我在 Eclipse 中有几个相互依赖的 Maven 项目.其中一些依赖于 Spring 库(Spring 核心、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 中运行的应用程序服务器中运行该项目.

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 项目并右键单击它并选择在服务器上运行"时,该项目部署在正在运行的 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)

我尝试了相同的方法,即在 Eclipse 中的 Jboss 实例上运行该项目,但它也抱怨找不到多个库.它抱怨的大多数库都是在 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 中的在服务器上运行"选项部署它,它就不起作用.

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 的子文件夹,其中包含您的项目所依赖的所有 jars?

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天全站免登陆