我建立了一个新的webapp Maven项目,并想用Jetty的Maven插件进行测试.所以我发出了控制台命令:mvn jetty:run
pluginGroup
在Maven的设置文件中定义后,我再次运行命令.不幸的是,它失败了,因为我使用了以下提到的插件版本之一:
为什么有2个基于Maven的插件来实现相同的功能 - 运行Jetty?他们为什么要带来这么多的混乱?
或者善意地向我解释他们之间的差异.
我正在使用Eclipse和Maven并使用Maven jetty插件运行我的应用程序.
我发现Maven每次执行jetty时都坚持要重新编译我的文件,这有点令人恼火:run.它是次优的,因为文件已经由Eclipse编译(我正在编写具有(相对)慢编译器的Scala).
我正在使用配置文件,并运行mvn jetty:在我的'development'配置文件下运行.
我想做的是:
配置jetty插件,以便在开发配置文件下运行时跳过编译阶段.
我查看了maven生命周期文档,但没有找到有关'skip.compile'标志或配置参数的任何信息.
我也尝试过配置Maven这样做是徒劳的假设,它会在maven-jetty-plugin启动时停止重新编译.
我错了,它没用.但我所想的是,也许Scala编译器就是问题所在.也许它忽略了编译的东西.
开发maven-compiler-plugin default-testCompile test-compile default-compile compile 1.6 1.6 false org.mortbay.jetty jetty-maven-plugin 7.2.2.v20101205 true development
更新:
我将尝试专门禁用scala编译
我有一个需要解析属性占位符的XML文件(urlrewrite.xml).我启用了Maven过滤来实现这一目标.这适用于组装的WAR文件.
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
Run Code Online (Sandbox Code Playgroud)
问题是尝试使用maven-jetty-plugin(Maven Jetty插件)在开发模式下运行应用程序,如maven jetty:run.
有问题的文件urlrewrite.xml位于src/main/resources目录中,因此应该(并且确实)最终在/ WEB-INF/classes(或maven jetty:run的目标/类)中.
URLRewriteFilter配置指定配置文件的位置,如下所示:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confPath</param-name>
<param-value>/WEB-INF/classes/urlrewrite.xml</param-value>
</init-param>
</filter>
Run Code Online (Sandbox Code Playgroud)
这将在部署时工作.但是,使用jetty maven插件,URLRewrite将因NullPointerException而死亡,因为它使用了context.getResourceAsString("/ WEB-INF/classes/urlrewrite.xml")来加载配置文件.Jetty为此返回null,因为从工作区运行应用程序时,它将/ WEB-INF/classes/...解析为src/main/webapp/WEB-INF/.... 该文件不存在,因为WAR尚未组装.它应该从target/classes/urlrewrite.xml中提取资源.
如果这对你来说是模糊的,那么你可能无法回答这个问题,因为我怀疑你需要成为Jetty大师来找出一个解决方法(提示:这是一个挑战!).
有没有人知道这方面的方法?我也尝试过以下变通方法:
总之,maven-jetty-plugin需要将文件置于src/main/resources/webapp/insert路径和文件名下,以便可用于maven jetty:run命令...
谢谢你的帮助......
真诚的,劳埃德力
我正在尝试使用JSF和Weld CDI配置Jetty.按照本手册后,我偶然发现了以下堆栈跟踪:
Caused by: java.lang.IllegalStateException: Singleton not set for STATIC_INSTANCE => []
at org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider$RegistrySingleton.get(RegistrySingletonProvider.java:28)
at org.jboss.weld.Container.instance(Container.java:55)
at org.jboss.weld.SimpleCDI.<init>(SimpleCDI.java:77)
at org.jboss.weld.environment.WeldProvider$EnvironmentCDI.<init>(WeldProvider.java:45)
at org.jboss.weld.environment.WeldProvider.getCDI(WeldProvider.java:61)
at javax.enterprise.inject.spi.CDI.current(CDI.java:60)
at org.jboss.weld.servlet.WeldInitialListener.contextInitialized(WeldInitialListener.java:94)
at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.contextInitialized(ForwardingServletListener.java:34)
at org.jboss.weld.environment.servlet.EnhancedListener.onStartup(EnhancedListener.java:65)
at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:140)
at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart(ServletContainerInitializersStarter.java:63)
... 50 more
Run Code Online (Sandbox Code Playgroud)
有人看到这里出了什么问题吗?
在我的Web应用程序开始加载之前,启动Jetty会有很长的延迟(8秒)
13:50:10 [INFO] jetty-9.4.5.v20170502
13:50:18 [INFO] Scanning elapsed time=146ms
Run Code Online (Sandbox Code Playgroud)
启用调试日志记录后,有两个有趣的步骤
提取依赖战争应用程序,毕竟需要时间(3s)
10:03:13 [DEBUG] Extracting entry = null from jar file:[..]/application-1.0.war
10:03:16 [DEBUG] Unpacked overlay: jar:file:[..]/application-1.0.war!/ to file:[..]
Run Code Online (Sandbox Code Playgroud)和以下4s延迟:
10:03:16 [DEBUG] Service loaders found in 0ms
10:03:20 [DEBUG] loaded interface javax.servlet.ServletContainerInitializer
Run Code Online (Sandbox Code Playgroud)如何调试或影响导致4s以上延迟的原因?
的pom.xml
<dependency>
<groupId>com.company</groupId>
<artifactId>application</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
[...]
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.5.v20170502</version>
<configuration>
<webApp>
<webInfIncludeJarPattern>empty</webInfIncludeJarPattern>
<containerIncludeJarPattern>empty</containerIncludeJarPattern>
</webApp>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
web.xml中
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.app.AnnotationConfig</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> …
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的webapp项目,maven和jetty一直运作良好,直到现在.但现在我需要使用JNDI设置MySQL连接池,因为数据库连接总是超时.
首先,这是我的pom.xml的相关内容:
<modelVersion>4.0.0</modelVersion>
...
<packaging>war</packaging>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty-version>8.1.0.v20120127</jetty-version>
</properties>
<dependencies>
...
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.20</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-version}</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-version}</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
...
</build>
Run Code Online (Sandbox Code Playgroud)
现在我在/ src/main/webapp/WEB-INF文件夹中创建了一个jetty-env.xml,其中包含以下内容:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<New id="project-db" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/db</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="url">jdbc:mysql://www.example.com:3306/mydb</Set>
<Set name="username">dbuser</Set>
<Set name="password">dbpass</Set>
</New>
</Arg>
</New>
</Configure>
Run Code Online (Sandbox Code Playgroud)
但问题是,我甚至无法测试此连接是否有效,因为jetty-maven-plugin无法启动目标
mvn jetty:run
Run Code Online (Sandbox Code Playgroud)
出现以下错误:
WARN:oejw.WebAppContext:Failed startup of context o.m.j.p.JettyWebAppContext
{/,file:/D:/documents/programmierung/workspace/battleships-trunk/src/main/webapp/}
,file:/D:/documents/programmierung/workspace/battleships-trunk/src/main/webapp/
java.lang.IllegalArgumentException: Object of class
'org.mortbay.jetty.plugin.JettyWebAppContext' is not of type
'org.eclipse.jetty.webapp.WebAppContext'. …
Run Code Online (Sandbox Code Playgroud) 关于这个主题有很多可用的信息,但我无法在Jetty 9中使用它.我发现的最新方法是:Jetty Maven插件忽略了自定义webdefault.xml
我从maven资源库中提取了webdefault.xml.然后,我设置useFileMappedBuffer
来false
并把它放在我的项目作为内jetty-maven-plugin-webdefault.xml
.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.0.M4</version>
<configuration>
<webAppConfig>
<defaultsDescriptor>src/main/resources/jetty-maven-plugin-webdefault.xml<</defaultsDescriptor>
</webAppConfig>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当我执行时jetty:run
,我看到我的webdefault.xml被引用:
[INFO] Web defaults = src/main/resources/jetty-maven-plugin-webdefault.xml
Run Code Online (Sandbox Code Playgroud)
但我仍然在Windows中使用文件锁定问题(使用IntelliJ IDEA 11).有谁知道解决方案?
我正在使用Maven Jetty插件,有没有办法防止服务器启动或关闭(例如使用maven-jetty-plugin)如果任何bean失败?
这是一个例子:
2013-04-22 11:43:59.327:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.m.p.JettyWebAppContext@9a681a{/,file:/opt/bamboo/bamboo-home/xml-data/build-dir/APA-BC-JETTYAPA/src/main/webapp/,STARTING}{file:/opt/bamboo/bamboo-home/xml-data/build-dir/APA-BC-JETTYAPA/src/main/webapp/}
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/classes/applicationContext.xml]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'staticDataService' for bean class [com.etermax.common.service.StaticDataService] conflicts with existing, non-compatible bean definition of same name and class [com.etermax.bingo.api.service.BingoStaticDataService]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:778)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:425)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:770)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:275) …
Run Code Online (Sandbox Code Playgroud) 我在内部使用OpenEJB运行Jetty(来自Maven).问题是它们通过JNDI上下文冲突.Stephen Connolly在一段时间前解决了这个问题.该解决方案看起来相当过时(它适用于Jetty 6.x,而我使用Jetty 7.x)并不是很清楚.有人可以解释是否可以一起运行Jetty和OpenEJB?很高兴看到一个例子.
我正在使用多模块maven项目开发Java Web应用程序.项目设置如下:
pom.xml
主要的maven项目,包括以下模块:
persistence:
实体类和DAObusiness:
服务定义和实施webapp:
Apache wicket Web应用程序依赖关系层次结构如下:webapp
取决于business
,取决于persistence
.
我也使用Jetty Maven插件mvn -pl webapp jetty:run
在主目录内部使用本地运行Web应用程序pom.xml
.在开发应用程序时,在进行代码更改时,我希望jetty服务器重新启动并自动重新加载修改后的代码文件.当我修改里面的文件也能正常工作webapp
的模块,但不工作,当我修改的另一个模块中的一个文件,这样persistence
或business
.
Maven Jetty插件的内部配置webapp/pom.xml
如下:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.2.v20140723</version>
<configuration>
<reload>automatic</reload>
<scanIntervalSeconds>1</scanIntervalSeconds>
<webApp>
<extraClasspath>../business/target/classes/;../persistence/target/classes/</extraClasspath>
</webApp>
<scanTargets>
<scanTarget>../business/target/classes</scanTarget>
<scanTarget>../persistence/target/classes</scanTarget>
</scanTargets>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我按照这个答案的说明.该<scanTarget>
标签做工精细,因为当我修改中的文件被码头重新启动business
或persistence
.但是,<extraClasspath>
由于修改后的文件未被jetty加载,因此无效.链接的答案使用<webAppConfig>
标记.但是,我正在使用插件文档中<webApp>
指定的标记(我也尝试了旧标记,这导致了相同的结果).<webAppConfig>
我的问题是:如何为多模块项目配置Jetty Maven插件,以便从其他模块重新加载修改过的文件?
jetty ×9
maven ×6
java ×3
cdi ×1
filtering ×1
jndi ×1
jrebel ×1
maven-module ×1
maven-plugin ×1
mysql ×1
openejb ×1
spring ×1
spring-mvc ×1
weld ×1