1

所有东西都在 Windows XP Pro SP2/32 位下运行。

我已经从 http://dist.codehaus.org/jetty/jetty-7.0.0-prereleases/jetty-7.0.0pre3/jetty-assembly-7.0.0pre3.zip>dist.codehaus.org 下载了 Jetty 7 pre3。
我已将码头提取到C:\jetty-7.0.0pre3\(所以我有 C:\jetty-7.0.0pre3\bin\ 和其他目录)
我已将我的 webapp 放入C:\jetty-7.0.0pre3\webapps\

我的 web.xml 中有资源引用:

<resource-ref>
  <description>dev datasource</description>
  <res-ref-name>jdbc/dev</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

并在 jetty.xml 中进行了配置:

<Array id="plusConfig" type="java.lang.String">
  <Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
  <Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
  <Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
  <Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
  <Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
</Array>

<New id="dev" class="org.mortbay.jetty.plus.naming.Resource">
  <Arg>jdbc/dev</Arg>
  <Arg>
    <New class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
      <Set name="User">username</Set>
      <Set name="URL">jdbc:oracle:thin:@10.201.201.64:1521:DEV</Set>
      <Set name="Password">password</Set>
    </New>
  </Arg>
</New>

<Call name="addLifeCycle">
  <Arg>
    <New class="org.mortbay.jetty.deployer.WebAppDeployer">
      <Set name="contexts"><Ref id="Contexts"/></Set>
      <Set name="webAppDir"><SystemProperty name="jetty.home" default="."/>/webapps</Set>
      <Set name="parentLoaderPriority">false</Set>
         <Set name="extract">true</Set>
         <Set name="allowDuplicates">false</Set>
      <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
      <Set name="ConfigurationClasses"><Ref id="plusConfig"/></Set>
    </New>
  </Arg>
</Call>

我正在运行java -DOPTION=plus -jar start.jarC:\jetty-7.0.0pre3\我收到以下错误:

2008-10-14 12:12:49.163::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
2008-10-14 12:12:49.413::WARN:  Config error at <New id="dev" class="org.mortbay.jetty.plus.naming.Resource"><Arg>jdbc/dev</Arg><Arg>
    <New class="oracle.jdbc.pool.OracleConnectionPoolDataSource"><Set name="User">username</Set><Set name="URL">jdbc:oracle:thin:@10.201.201.64:1521:DEV</Set><Set name="Password">password</Set></New>
  </Arg></New>
2008-10-14 12:12:49.413::WARN:  EXCEPTION
java.lang.ClassNotFoundException: org.mortbay.jetty.plus.naming.Resource
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.mortbay.util.Loader.loadClass(Loader.java:91)
        at org.mortbay.xml.XmlConfiguration.nodeClass(XmlConfiguration.java:224)
        at org.mortbay.xml.XmlConfiguration.newObj(XmlConfiguration.java:572)
        at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:256)
        at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:214)
        at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:971)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.mortbay.start.Main.invokeMain(Main.java:218)
        at org.mortbay.start.Main.start(Main.java:564)
        at org.mortbay.start.Main.main(Main.java:136)

C:\jetty-7.0.0pre3\lib\plus\jetty-plus-7.0.0pre3.jar在类路径上。在同一个控制台中:

C:\jetty-7.0.0pre3>set classpath
CLASSPATH=C:\Program Files\IBM\WebSphere MQ\Java\lib\providerutil.jar;C:\Program
 Files\IBM\WebSphere MQ\Java\lib\com.ibm.mqjms.jar;C:\Program Files\IBM\WebSpher
e MQ\Java\lib\ldap.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jta.jar;C:\Pro
gram Files\IBM\WebSphere MQ\Java\lib\jndi.jar;C:\Program Files\IBM\WebSphere MQ\
Java\lib\jms.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\connector.jar;C:\Pro
gram Files\IBM\WebSphere MQ\Java\lib\fscontext.jar;C:\Program Files\IBM\WebSpher
e MQ\Java\lib\com.ibm.mq.jar;.;c:\Program Files\Java\jdk1.5.0_05\classes;C:\Prog
ram Files\Java\jre1.5.0_05\lib\ext\QTJava.zip;C:\Program Files\Java\jre1.5.0_05\
lib\spring.jar;c:\jetty-7.0.0pre3\lib\plus\jetty-plus-7.0.0pre3.jar

怎么了?我应该如何添加org.mortbay.jetty.plus.naming.Resource到 start.jar 的可见性区域?

4

1 回答 1

2

The problem is that addLifeCycle does not take a Resource object; it takes LifeCycle implementations such as WebAppContexts or WebAppDeployers.

Assuming you have a WebAppDeployer (or equivalent) set up in your jetty.xml, try this:

<Array id="plusConfig" type="java.lang.String">
  <Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
  <Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
  <Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
  <Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
  <Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
</Array>

<Call name="addLifeCycle">
  <Arg>
    <New class="org.mortbay.jetty.deployer.WebAppDeployer">
      ....
      <Set name="ConfigurationClasses"><Ref id="plusConfig"/></Set>
      ....
    </New>
  </Arg>
</Call>


<New id="dev" class="org.mortbay.jetty.plus.naming.Resource">
  <Arg>jdbc/dev</Arg>
  <Arg>
    <New class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
      <Set name="User">username</Set>
      <Set name="URL">jdbc:oracle:thin:@10.201.201.64:1521:DEV</Set>
      <Set name="Password">password</Set>
    </New>
  </Arg>
</New>

If you want the datasource only for a particular webapp, then do a similar configuration within a jetty-env.xml file for that webapp.

Also, since you're using Jetty 7, you will need to load the (optional) plus libraries (if the exe isn't doing that for you already). You'll know they aren't being loaded, because you'll get a ClassNotFoundException on startup.

Starting up Jetty on Linux, I would do it like so:

java -DOPTIONS=plus -jar start.jar 

However, I am not familiar with Windows. Possibly

Jetty-Service.exe -DOPTIONS=plus

would work? If not, then look for something which would set the system property "OPTIONS" to "plus" when you run jetty.

于 2008-10-10T10:50:18.840 回答