将项目 jar 部署到使用 Maven Cargo 插件启动的运行容器时出现问题
我在 Maven 项目中有一系列 Servlet 和 Servlet Filters,它们被打包到一个 jar 中,并且该 jar 旨在包含在一系列其他“主机”Web 应用程序的 /lib 目录中。这些 Servlet 并不意味着单独运行 - 并且不保证它们自己的战争(它不是独立的 Web 应用程序)。
在我的 src/test/java 目录中,我有一些模拟对象,它们松散地模仿这些“主机”应用程序。
我在集成测试阶段使用 Cargo 来启动 tomcat 的实例,但我很难让 tomcat 在 src/test/java 中使用我的模拟“主机”servlet。
有推荐的方法吗?我需要先从 src/test/java 中的源代码构建一个 war 吗?
另外,在启动容器之前,我需要将实际项目的 jar 移动到 WEB-INF/lib 。我曾考虑过使用maven assembly插件来做到这一点?有没有办法只使用货物配置选项来做到这一点?
非常感谢您的任何意见。
I have a series of Servlets and Servlet Filters in a maven project that are packaged into a jar and that jar is meant to be included in the /lib directory of a series of other "host" web applications. These Servlets are not meant to be run alone - and do not warrant their own war (it is not a stand-alone web app).
In my src/test/java directory I have some Mock objects that loosely mimic these "host" applications.
I am using cargo during my integration-test phase to start up an instance of tomcat, but I am having a hard time getting tomcat to use my mock "host" servlets in src/test/java.
Is there a recommended way to do this? Do I need to build a war from the sources in src/test/java first?
Also, I will need to move my actual project's jar to WEB-INF/lib before starting the container. I had considered using the maven assembly plugin to do this? Is there a way to do this with just cargo configuration options?
Thank you so much for any input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,你必须为此构建一个 WAR。
Cargo 部署容器可以理解的内容,即 WAR 或 EAR 文件,但不是 JAR 文件。
Yes, you must build a WAR for this.
Cargo deploys what the container understands, and that is either WAR or EAR files, but not JAR files.
我最终做的是在预集成测试阶段使用 maven-war-plugin 来构建战争。
然后,我使用 maven-dependency-plugin 将一些所需的依赖项复制到 war 构建位置。
然后我将货物指向那个新的战争地点进行集成测试。
这样,当我执行 mvn package 时,我会得到一个包含我想要打包的所有类的 jar,并且当我运行 mvn Integration-test 时,我会得到一个货物作为测试工具启动的战争。效果很好。
感谢您查看我的问题。
What I ended up doing was using the maven-war-plugin on the pre-integration-test phase to build a war.
I then used the maven-dependency-plugin to copy some needed dependencies to the war build location.
And then I pointed cargo at that new war location for the integration tests.
That way when I do mvn package, I get a jar with all of the classes that I want packaged, and when I run mvn integration-test I get a war that cargo starts up as a test harness. It worked out pretty well.
Thank you for looking at my question.