[英]jshell use external dependency from Maven repository
I'd like to use JShell to launch a Class which is contained in a Maven repository:我想使用 JShell 启动 Class,它包含在 Maven 存储库中:
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>2.2.16.Final</version>
</dependency>
Looking at the docs, I can see you can specify the classpath using the following option:查看文档,我可以看到您可以使用以下选项指定类路径:
jshell --class-path=
That however implies that you have the library locally.然而,这意味着您在本地拥有图书馆。 I wonder if it's possible to just specify the Maven GAV or an HTTP URL to pick up the Class from that dependency.我想知道是否可以仅指定 Maven GAV 或 HTTP URL 从该依赖项中获取 Class。 Any idea?任何的想法? Thanks谢谢
If you don't have a pom.xml
with all your dependencies listed, a simple solution is to symlink or copy the jars you need to a single directory, say $HOME/.java/lib
and launch jshell like this:如果你没有列出所有依赖项的pom.xml
,一个简单的解决方案是符号链接或复制你需要的 jars 到一个目录,比如$HOME/.java/lib
并像这样启动 jshell:
CLASSPATH=$HOME/.java/lib/*:. jshell
If you do have a pom.xml
in the current directory, you can do this:如果你在当前目录中有一个pom.xml
,你可以这样做:
CLASSPATH=`mvn dependency:build-classpath -DincludeTypes=jar -Dmdep.outputFile=/dev/stderr 2>&1 >/dev/null`:target/classes jshell
Note, because of JDK bug 8177650 , you probably don't want to use the --class-path option.请注意,由于JDK 错误 8177650 ,您可能不想使用 --class-path 选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.