在JShell中,如何从Maven项目导入类路径 [英] In JShell, how to import classpath from a Maven project

查看:235
本文介绍了在JShell中,如何从Maven项目导入类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在开发的本地Maven项目.如何使用具有所有依赖项的项目类路径启动jshell,以便可以在JShell中测试项目或依赖项类.

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.

推荐答案

我写了一个简单的shell脚本放在执行搜索路径中:

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

Shell脚本文件: mshell (用于* inux)

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脚本文件: mshell (对于Windows cmd.exe)

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"

然后在maven项目目录中(对于多模块项目,请确保在模块目录中而不是在父目录中)运行:

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

要点链接

感谢杰伊指出-DincludeTypes = jar maven选项.

这篇关于在JShell中,如何从Maven项目导入类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆