【问题标题】:IllegalArgumentException: Object is not of type class org.eclipse.jetty.plus.jndi.ResourceIllegalArgumentException:对象不是类型 org.eclipse.jetty.plus.jndi.Resource
【发布时间】:2014-06-23 15:18:05
【问题描述】:

尝试使用 Jetty 9.1.4 + Gradle 构建一个 hello world 应用程序。 我的项目结构

  • [项目根目录]
      • [分级]
        • [jetty-9.1.4]
          • [库]
          • jetty-jndi-9.1.4.v(...).jar
          • jetty-plus-9.1.4.v(...)/jar
      • [源]
        • [主要]
          • [java]
            • [小服务程序]
              • HelloWorldServlet.java
          • [网络应用]
            • [WEB-INF]
              • jetty-env.xml
              • web.xml
      • build.gralde
我的 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <servlet>
        <display-name>HelloWorldServlet</display-name>
        <servlet-name>HelloWorldServlet</servlet-name>
        <servlet-class>servlet.HelloWorldServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>HelloWorldServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

我的码头-env.xml

<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
        <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
            <Set name="Url">jdbc:mysql://sql2.freemysqlhosting.net/sql238625</Set>
            <Set name="User">sql238625</Set>
            <Set name="Password">gD5%tN5!</Set>
        </New>
    </Arg>
</New>

我的 build.gradle

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'eclipse-wtp'

repositories {
    mavenCentral()
}

dependencies {
    providedCompile 'javax.servlet:servlet-api:2.5'
    compile 'mysql:mysql-connector-java:5.1.30'
    runtime 'javax.servlet:jstl:1.1.2'
    providedCompile fileTree(dir: 'jetty-9.1.4/lib', include: '*.jar')
}

httpPort = 8080
stopPort = 9451
stopKey = 'foo'

当我执行 gradle jettyRunWar 任务时,我在堆栈跟踪中遇到了这个异常:

Failed startup of context org.gradle.api.plugins.jetty.internal.JettyPluginWebAppContext@12cb504{/recipe-beagle,D:\Dev\projects\recipe-beagle\build\libs\recipe-beagle.war}
java.lang.IllegalArgumentException: Object is not of type class org.eclipse.jetty.plus.jndi.Resource
    at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:189)
    at org.mortbay.jetty.plus.webapp.EnvConfiguration.configureWebApp(EnvConfiguration.java:130)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1269)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:489)
    at org.gradle.api.plugins.jetty.internal.JettyPluginWebAppContext.doStart(JettyPluginWebAppContext.java:112)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:224)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.gradle.api.plugins.jetty.internal.Jetty6PluginServer.start(Jetty6PluginServer.java:111)
    at org.gradle.api.plugins.jetty.AbstractJettyRunTask.startJettyInternal(AbstractJettyRunTask.java:240)[...]

那么,可能是什么原因以及如何使它起作用?

【问题讨论】:

    标签: gradle jetty illegalargumentexception


    【解决方案1】:

    原因是在运行 jettyRunWar gradle 任务。 Gradle jetty 插件使用 6.xxx 版本的 jetty 服务器,它的包是 org.mortbay.* 并且它们不适合新的 (jetty-9.1.4) org.eclipse.jetty.*。 解决方案不是使用 gradle 插件任务,而是与 gradle 'war' 任务进行战争,将这场战争手动放到本地 jetty_installation_directory/webapps 中,然后使用命令 java -jar start.jar 在 jetty_installation_directory 中运行 jetty。

    为了让事情顺利进行,build.gradle 必须如下所示:

    apply plugin: 'java'
    apply plugin: 'war'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        providedCompile 'javax.servlet:servlet-api:2.5'
        compile 'mysql:mysql-connector-java:5.1.30'
        runtime 'javax.servlet:jstl:1.1.2'
    }
    
    task copyFilesToJetty(type : Copy) {
        from 'build/libs'
        into 'jetty-9.1.4/webapps'
        include '*.war'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-07
      • 2018-05-11
      • 2017-08-31
      • 2015-09-14
      • 2013-07-23
      • 2010-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多