简体   繁体   English

如何在Jetty类路径中将jar放入jetty / lib?

[英]How do I place jars in jetty/lib on the jetty classpath?

I have Jetty jetty-9.2.3.v20140905 我有Jetty jetty-9.2.3.v20140905

My understanding was that jars in lib/jar or lib/ext were automatically on the classpath, but this may have been old behavior from jetty 8. 我的理解是lib / jar或lib / ext中的jar自动出现在类路径中,但这可能是jetty 8的旧行为。

I'm trying to deploy a webapp with websockets. 我正在尝试使用websockets部署webapp。 With my deployed WAR file in the webapps directory, jetty keeps complaining that it cannot find jars sitting right there in the jetty/lib directory (jetty-http, jetty-io, jetty-security, jetty-server, jetty-servlet, jetty-util are the ones my webapp needs that it cannot find) 随着我在webapps目录中部署的WAR文件,jetty一直抱怨它找不到位于jetty / lib目录中的jar(jetty-http,jetty-io,jetty-security,jetty-server,jetty-servlet,jetty- util是我的webapp需要的,它找不到)

jars placed in lib/ext are also not picked up when I do a --module-ext 当我执行--module-ext时,放在lib / ext中的jar也没有被拾取

How can I resolve this? 我该如何解决这个问题?

To address the answer below, (editing the original questioN) I have tried enabling the server module, whose server.mod file contains the following lines: 为了解决下面的答案,(编辑原始问题)我尝试启用服务器模块,其server.mod文件包含以下行:

[lib]
lib/servlet-api-3.1.jar
lib/jetty-schemas-3.1.jar
lib/jetty-http-${jetty.version}.jar
lib/jetty-server-${jetty.version}.jar
lib/jetty-xml-${jetty.version}.jar
lib/jetty-util-${jetty.version}.jar
lib/jetty-io-${jetty.version}.jar

From the command line, I do 从命令行,我做

java -jar start.jar --module=server jetty.port=8182

and the result is: 结果是:

2014-10-30 15:26:13.907:WARN:oejuc.AbstractLifeCycle:main: FAILED   
org.eclipse.jetty.annotations.ServletContainerInitializersStarter@2635068e: 
java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler
java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler

org.eclipse.jetty.server.Handler is right there in jetty-server jar sitting in my jetty/lib directory. org.eclipse.jetty.server.Handler就在jetty-server jar中,坐在我的jetty / lib目录下。

Perhaps the jetty.version or jetty.base variables are incorrect? 也许jetty.version或jetty.base变量不正确?

When I perform a 当我表演时

--list-classpath

I do see all the jars in the lib directory there. 我确实看到了lib目录中的所有jar文件。

What documentation are you reading? 你在读什么文件? (link please) (请链接)

The whole concept of a start.config only exists in Jetty 8 and earlier. start.config的整个概念仅存在于Jetty 8及更早版本中。

Current documentation is at http://www.eclipse.org/jetty/documentation/current/ 当前文档位于http://www.eclipse.org/jetty/documentation/current/

That text is not valid for Jetty 9.2.3.v20140905 该文本对Jetty 9.2.3.v20140905

There is never a good reason to have ALL of the jars in lib/ in the server classpath at the same time. 从来没有一个很好的理由同时在服务器类路径中的lib/中包含所有 jar。 In fact it would result in an invalid environment, as there are different implementations of several core technologies that you can change (such as jsp, jstl, and javax.el). 实际上,它会导致无效的环境,因为您可以更改几种核心技术的不同实现(例如jsp,jstl和javax.el)。 There are also libraries present in lib/ that require 3rd party optional libraries to function (like npn, alpn), which require you to acknowledge a license before they are downloaded. lib/中还存在需要第三方可选库运行的库(如npn,alpn),这些库要求您在下载许可证之前确认许可证。

What libraries are loaded, from either {jetty.home}/lib and/or {jetty.base}/lib are determined by what modules you have enabled in your jetty instance configuration. {jetty.home}/lib和/或{jetty.base}/lib加载的库由您在jetty实例配置中启用的模块决定。

To learn about startup, start.jar, command line, modules, libs, xml configuration, configuration properties, {jetty.base} , {jetty-dir} , and {jetty.home} , see the "Startup Documentation" at http://www.eclipse.org/jetty/documentation/current/startup.html 要了解启动,start.jar,命令行,模块,库,xml配置,配置属性, {jetty.base}{jetty-dir}{jetty.home} ,请参阅http:中的“启动文档”。 //www.eclipse.org/jetty/documentation/current/startup.html

To address your specific question about starting jetty and webapps. 解决有关启动jetty和webapps的特定问题。 (Again, this is all documented in the "Startup Documentation" URL above) (同样,这些都记录在上面的“启动文档”URL中)

Here's a quick example using {jetty.home} itself (not recommended anymore, but works): 这是一个使用{jetty.home}本身的快速示例(不推荐使用,但有效):

# Unpack the distribution
[~]$ unzip jetty-distribution-9.2.3.v20140905
[~]$ cd jetty-distribution-9.2.3.v20140905

# Copy your war into place
[jetty-distribution-9.2.3.v20140905]$ cp ~/Projects/mywebapp.war webapps/

# Run Jetty
[jetty-distribution-9.2.3.v20140905]$ java -jar start.jar

Now for the more appropriate way, using a {jetty.base} : 现在以更合适的方式,使用{jetty.base}

# Unpack the distribution
[~]$ unzip jetty-distribution-9.2.3.v20140905

# Make a {jetty.base} directory to house your configuration
[~]$ mkdir myappbase
[~]$ cd myappbase

# Since this is a new {jetty.base}, lets initialize it
[myappbase]$ java -jar ../jetty-distribution-9.2.3.v20140905/start.jar \
  --add-to-start=http,logging,deploy,jsp,ext,resources
INFO: http            initialised in ${jetty.base}/start.ini (appended)
INFO: server          initialised in ${jetty.base}/start.ini (appended)
INFO: logging         initialised in ${jetty.base}/start.ini (appended)
MKDIR: ${jetty.base}/logs
INFO: deploy          initialised in ${jetty.base}/start.ini (appended)
MKDIR: ${jetty.base}/webapps
...(snip)...
MKDIR: ${jetty.base}/lib
MKDIR: ${jetty.base}/lib/ext
INFO: resources       initialised in ${jetty.base}/start.ini (appended)
MKDIR: ${jetty.base}/resources

# Lets see what we have now
[myappbase]$ ls -F
lib/  logs/  resources/  start.ini  webapps/

# Copy your webapp into place
[myappbase]$ cp ~/Projects/mywebapp.war webapps/

# Run Jetty
[myappbase]$ java -jar ../jetty-distribution-9.2.3.v20140905/start.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM