我有一个包含多个模块的项目.
其中两个生成war文件.
一个war文件是一个REST应用程序,它提供了一些资源.
Other war文件是一个与REST后端通信的Angular JS Web应用程序(仅限静态内容).
出于演示目的,我想非常轻松地部署两个war文件 mvn jetty:run
出于开发目的,我想从我的IDE(例如Eclipse Servers View)部署它们.
当我通过启动服务器并将war文件复制到部署文件夹手动在单个Jetty服务器(v9.0.7.v20131107)上进行部署时,一切都会出现.
当mvn jetty:run两个war文件启动jetty时,部署了,但不知何时REST资源没有部署.
我正在使用Jersey 2.手动部署时,我收到一条日志消息
Nov 14, 2013 10:44:37 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.4 2013-10-24 18:25:49...
但是,在开始时未显示此消息mvn jetty:run.所以我认为泽西岛没有踢球.
对于依赖注入我使用spring.
这是/pom.xml中的父pom,带有jetty-maven-plugin配置
<project ...>
...
<build>
<plugins>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.7.v20131107</version>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>module1/target/module1-${project-version}.war</war>
<contextPath>/module1</contextPath>
</contextHandler>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>module2/target/module2-${project.version}.war</war>
<contextPath>/module2/contextPath>
</contextHandler>
</contextHandlers>
</configuration>
</plugins>
</build>
...
</project>
Run Code Online (Sandbox Code Playgroud)
这是module1(REST模块)的pom
<parent>
...
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>module1</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<springVersion>3.1.4.RELEASE</springversion>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.4</version>
</dependency>
<!-- Dependencies to internal modules -->
...
<!-- Depenencies to internal modules END -->
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
这是module1的web.xml
<web-app ...
version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
Run Code Online (Sandbox Code Playgroud)
这是module1的applicationContext.xml
<beans ...>
<context:annotation-config/>
<context:component-scan base-package="com.stackoverflow.zip"/>
<aop:aspectj-autoproxy/>
</beans>
Run Code Online (Sandbox Code Playgroud)
这是module1的Module1Application类
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
@ApplicationPath("/rest")
public class Module1Application extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(Resource1.class);
classes.add(Resource2.class);
classes.add(MultiPartFeature.class);
return classes;
}
}
Run Code Online (Sandbox Code Playgroud)
这是module2的pom(AngularJS应用程序) 非常轻:)
<project ...>
<parent>
...
</parent>
...
<modelVersion>4.0.0</modelVersion>
<artifactId>module2</artifactId>
<packaging>war</packaging>
</project>
Run Code Online (Sandbox Code Playgroud)
你知道为什么Jersey应用程序在运行mvn jetty:run时没有实例化,而是在手动运行时?
我感谢对此主题的任何意见.
亲切的问候 - 拉链
您的 javax.servlet 版本2.5位于 pom.xml 中,但3.0位于 web.xml 中。尝试将其升级到3.0pom.xml 中。IDE 是否有可能为您提供 servlet 3.0?
另外,由于 Jetty 提供了 javax.servlet 容器,请尝试将 Servlet Api 放入pom.xml. 像这样的东西:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<!-- http://stackoverflow.com/a/15601606 http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope -->
<!-- This allows us to compile the application locally but does not include the jar in the package step -->
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
您可能想<load-on-startup>1</load-on-startup>向您的web.xml. 查看http://tutorials.jenkov.com/java-servlets/web-xml.html#load-on-startup
整个教程就很不错了
免责声明:我不熟悉 Spring 依赖项如何帮助您的应用程序自行引导。您始终可以尝试删除对单独分支的依赖关系,并在运行时将它们添加回来
| 归档时间: |
|
| 查看次数: |
1500 次 |
| 最近记录: |