In JShell, how to import classpath from a Maven project

核能气质少年 提交于 2019-12-17 15:51:39

问题


I have a local Maven project under development. How can I launch jshell with the project class path with all the dependencies, so that I can test project or dependency classes inside JShell.


回答1:


You can use the jshell-maven-plugin:

mvn com.github.johnpoth:jshell-maven-plugin:1.1:run

which will fire up a JShell session with your project's runtime path. If you want to include your test dependencies just add -DtestClasspath to the command.

Source code: https://github.com/johnpoth/jshell-maven-plugin; contributions are welcome :) full disclaimer: I wrote the plugin.

Enjoy!




回答2:


I wrote a simple shell script put in the execution search path:

Shell script file: mshell (for *inux)

mvn dependency:build-classpath -DincludeTypes=jar -Dmdep.outputFile=.cp.txt
jshell --class-path `cat .cp.txt`:target/classes

Shell script file: mshell (for Windows cmd.exe)

mvn dependency:build-classpath -DincludeTypes=jar -Dmdep.outputFile=.cp.txt
for /F %i in (.cp.txt) do jshell --class-path "%i;target/classes"

Then in the maven project directory (for multi-module project, make sure in the module directory instead of parent directory), run:

$ cd $MAVEN_PROJECT_HOME   #make sure module folder for multi-module project
$ mshell

gist link

Thanks Jay for pointing out -DincludeTypes=jar maven option.




回答3:


See In Maven, how to output the classpath being used?.

According to:

jshell --help

run JShell with:

jshell --class-path <path>


来源:https://stackoverflow.com/questions/47705036/in-jshell-how-to-import-classpath-from-a-maven-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!