2017-02-22 50 views
0

我用碼頭,Maven的插件具有以下配置:碼頭預警與Maven插件「沒有上下文resourceBase或戰爭集」

<plugin> 
    <groupId>org.eclipse.jetty</groupId> 
    <artifactId>jetty-maven-plugin</artifactId> 
    <version>9.4.1.v20170120</version> 
    <configuration> 
     <jettyConfig>${basedir}/src/main/webapp/WEB-INF/development.jetty-config.xml</jettyConfig> 
     <contextHandlers> 
      <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext"> 
       <contextPath>/</contextPath> 
      </contextHandler> 
     </contextHandlers> 
     <reload>manual</reload> 
     <scanIntervalSeconds>0</scanIntervalSeconds> 
     <webApp> 
      <contextPath>/</contextPath> 
     </webApp> 
    </configuration> 
    <dependencies> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>${mysql.version}</version> 
     </dependency> 
    </dependencies> 
</plugin> 

文件development.jetty-config.xml有以下內容:

<?xml version="1.0"?> 
<Configure class="org.eclipse.jetty.maven.plugin.JettyWebAppContext"> 
    <Set name="resourceBase">./src/main/webapp</Set> 
    <Set name="contextPath">/</Set> 
    <Set name="war"><Property name="jetty.home" default="." />./src/main/webapp</Set> 

    <New id="proj1DS" class="org.eclipse.jetty.plus.jndi.Resource"> 
     <Arg></Arg> 
     <Arg>jdbc/proj1</Arg> 
     <Arg> 
      <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"> 
       <Set name="Url">jdbc:mysql://localhost/mydb</Set> 
       <Set name="User">root</Set> 
       <Set name="Password">***</Set> 
       <Set name="UseUnicode">true</Set> 
       <Set name="CharacterEncoding">UTF-8</Set> 
      </New> 
     </Arg> 
    </New> 
</Configure> 

然後我和一個Maven命令啓動碼頭:

mvn jetty:run 

相關插件日誌:

[INFO] <<< jetty-maven-plugin:9.4.1.v20170120:run (default-cli) < test-compile @ proj1-admin <<< 
[INFO] 
[INFO] --- jetty-maven-plugin:9.4.1.v20170120:run (default-cli) @ proj1-admin --- 
2017-02-22 11:41:42.311:INFO::main: Logging initialized @3350ms to org.eclipse.jetty.util.log.StdErrLog 
[INFO] Configuring Jetty for project: Proj Admin 
[INFO] webAppSourceDirectory not set. Trying src/main/webapp 
[INFO] Reload Mechanic: manual 
[INFO] Classes = /home/igor/projects/Proj1/admin/target/classes 
[INFO] Configuring Jetty from xml configuration file = /home/igor/projects/proj1/admin/src/main/webapp/WEB-INF/development.jetty-config.xml 
[INFO] Context path =/
[INFO] Tmp directory = /home/igor/projects/proj1/admin/target/tmp 
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml 
[INFO] Web overrides = none 
[INFO] web.xml file = file:///home/igor/projects/proj1/admin/src/main/webapp/WEB-INF/web.xml 
[INFO] Webapp directory = /home/igor/projects/proj1/admin/src/main/webapp 
2017-02-22 11:41:42.449:INFO:oejs.Server:main: jetty-9.4.1.v20170120 
2017-02-22 11:41:44.694:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=1975ms 
2017-02-22 11:41:44.904:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0 
2017-02-22 11:41:44.904:INFO:oejs.session:main: No SessionScavenger set, using defaults 
2017-02-22 11:41:44.907:INFO:oejs.session:main: Scavenging every 600000ms 

然後打印這樣的警告:

2017-02-22 11:41:47.150:INFO:oejsh.ContextHandler:main: Started [email protected]{/,file:///home/igor/projects/proj1/admin/src/main/webapp/,AVAILABLE}{file:///home/igor/projects/proj1/admin/src/main/webapp/} 
2017-02-22 11:41:47.154:WARN:oejw.WebInfConfiguration:main: Can't generate resourceBase as part of webapp tmp dir name: java.lang.IllegalStateException: No resourceBase or war set for context 
2017-02-22 11:41:47.155:WARN:oejw.WebAppContext:main: Failed startup of context [email protected]{/,null,null} 
java.lang.IllegalStateException: No resourceBase or war set for context 
    at org.eclipse.jetty.webapp.WebInfConfiguration.unpack(WebInfConfiguration.java:406) 
    at org.eclipse.jetty.maven.plugin.MavenWebInfConfiguration.unpack(MavenWebInfConfiguration.java:135) 
    at org.eclipse.jetty.webapp.WebInfConfiguration.preConfigure(WebInfConfiguration.java:72) 
    at org.eclipse.jetty.maven.plugin.MavenWebInfConfiguration.preConfigure(MavenWebInfConfiguration.java:95) 
    at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:501) 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:539) 
    at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:432) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131) 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113) 
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) 
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:161) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131) 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113) 
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131) 
    at org.eclipse.jetty.server.Server.start(Server.java:452) 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105) 
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) 
    at org.eclipse.jetty.server.Server.doStart(Server.java:419) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:460) 
    at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:328) 
    at org.eclipse.jetty.maven.plugin.JettyRunMojo.execute(JettyRunMojo.java:170) 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132) 

要我surprize,加載應用程序和workig正常。此外,三線配置文件:

<Set name="resourceBase">./src/main/webapp</Set> 
<Set name="contextPath">/</Set> 
<Set name="war"><Property name="jetty.home" default="."/>./src/main/webapp</Set> 

沒有任何影響,即使我刪除它們。

我看了看文檔,而這些答案,但無法弄清楚:

How to deploy my web application to jetty9 as root application?

No hot deployment in Jetty 9.0.6

Jetty config without resourceBase

我的問題是:

  1. 如何正確配置這個插件來擺脫警告?
  2. 我應該真的擔心,因爲這不是一個錯誤,應用程序正在工作?

回答

1

您的設置很混亂。

爲什麼直接通過Jetty IoC上下文XML配置org.eclipse.jetty.maven.plugin.JettyWebAppContext?不要這樣做,它是無效的。

您不能從jetty-maven-plugin更改resourceBase,因爲jetty-maven-plugin本身需要根據自己的目的控制該設置。

jetty-maven-plugin將使用maven子系統中存在的信息來構建一個resourceBases列表,以使您的webapp從Servlet規範和maven的角度來看有效。它將信息拉離:

  • 項目的構建(如:在你的有效POM定義輸出目錄)
  • 你的項目的插件(比如:從你的插件動態分配的輸出目錄,如Maven的資源-plugin,Maven的編譯器插件,Maven的戰爭插件,JSPC - Maven的插件等)

但從碼頭的適當點,你不能有一個WebAppContext同時限定resourceBasewar,它們是相同的東西,並且具有相同的目的。

  • resourceBase是內碼頭的基本概念(並且是碼頭,Maven的插件如何初始化你的web應用)
  • war是Servlet規範的專業化resourceBase。 (只有當你有一個正確的*.war或擴展Web應用程序部署的使用。這是無效碼頭 - Maven的插件執行期間)

對於配置contextPath,使用碼頭 - Maven的插件<configuration>代替。

如果您對配置JNDI資源的目的,該碼頭的IoC上下文XML,只考慮使其成爲一個正常的配置您的WEB-INF/jetty-env.xml文件。

<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"> 
    <New id="proj1DS" class="org.eclipse.jetty.plus.jndi.Resource"> 
     <Arg></Arg> 
     <Arg>jdbc/proj1</Arg> 
     <Arg> 
      <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"> 
       <Set name="Url">jdbc:mysql://localhost/mydb</Set> 
       <Set name="User">root</Set> 
       <Set name="Password">***</Set> 
       <Set name="UseUnicode">true</Set> 
       <Set name="CharacterEncoding">UTF-8</Set> 
      </New> 
     </Arg> 
    </New> 
</Configure> 
+0

我也跟着你的建議和我的聚甲醛去除這樣的: <的ContextHandlers> \t \t \t / \t \t 警告現在消失了。非常感謝您的幫助! – ipolevoy

相關問題