java 如何在 jetty 类路径上的 jetty/lib 中放置 jars?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26661110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 10:20:34  来源:igfitidea点击:

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

javajettyclasspath

提问by user2197116

I have Jetty jetty-9.2.3.v20140905

我有码头 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 中的 jars 自动在类路径上,但这可能是 jetty 8 的旧行为。

I'm trying to deploy a webapp with websockets. 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)

我正在尝试使用 websockets 部署一个 webapp。我在 webapps 目录中部署了 WAR 文件后,jetty 一直抱怨在 jetty/lib 目录中找不到 jars(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 中的 jars 也不会被拾取

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/lib 目录中的 jetty-server jar 中。

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。

回答by Joakim Erdfelt

What documentation are you reading? (link please)

你在读什么文档?(请链接)

The whole concept of a start.configonly exists in Jetty 8 and earlier.

a 的整个概念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 ALLof the jars in lib/in the server classpath at the same time. 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). 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.

永远没有充分的理由将所有jar 文件同时放入lib/服务器类路径中。事实上,它会导致一个无效的环境,因为您可以更改几个核心技术的不同实现(例如 jsp、jstl 和 javax.el)。还有一些库lib/需要 3rd 方可选库才能运行(如 npn、alpn),这需要您在下载之前确认许可。

What libraries are loaded, from either {jetty.home}/liband/or {jetty.base}/libare 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. (Again, this is all documented in the "Startup Documentation" URL above)

解决有关启动 jetty 和 webapps 的具体问题。 (同样,这都记录在上面的“启动文档”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