简体   繁体   中英

jshell use external dependency from Maven repository

I'd like to use JShell to launch a Class which is contained in a Maven repository:

<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. 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:

CLASSPATH=$HOME/.java/lib/*:. jshell

If you do have a pom.xml in the current directory, you can do this:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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