[英]How to run Java 9 application with classpath rather than module path in IDEA?
When I run a main class in IDEA, it puts the module and its dependencies on a module path.当我在 IDEA 中运行主类时,它会将模块及其依赖项放在模块路径上。 Is it possible to change it to a classpath?是否可以将其更改为类路径?
If you don't define a module-info, IDEA would set the application and your dependencies on the classpath.如果您不定义模块信息,IDEA 将在类路径上设置应用程序和您的依赖项。 Since you have a module-info it's an explicit module so it has to be on the module path.因为你有一个模块信息,它是一个显式模块,所以它必须在模块路径上。 Normally you would handle your dependecies now as automatic-modules.通常你现在会把你的依赖作为自动模块来处理。
Howsoever, your dependencies at least have a good reason to be on the classpath.但是,您的依赖项至少有充分的理由位于类路径中。 We discussed that here Why Java 9 does not simply turn all JARs on the class path into automatic modules?我们在这里讨论了为什么 Java 9 不简单地将类路径上的所有 JAR 都变成自动模块?
For example, mymodule depends on an automatic-module which however needs a jar that can't become an automatic-module yet.例如,mymodule 依赖于一个自动模块,但是它需要一个还不能成为自动模块的 jar。 On commandline it would like this:在命令行上它会像这样:
java -cp legacy.jar -p "mymodule.jar;automodule.jar;" java -cp legacy.jar -p "mymodule.jar;automodule.jar;" -m mymodule/com.example.mymodule.Application -m mymodule/com.example.mymodule.Application
IMO intellij doesn't currently support that. IMO intellij 目前不支持。 As a workaround to run the entire application on the classpath at least, you could rename the model-info for disabling/not to be a jigsaw-module for a moment.作为至少在类路径上运行整个应用程序的解决方法,您可以重命名模型信息以暂时禁用/不作为拼图模块。
To answer the question, the heuristic IDEA uses to run an application with a module path is currently slightly off (IDEA 2018.01).为了回答这个问题,IDEA 用于运行具有模块路径的应用程序的启发式方法目前略有偏差 (IDEA 2018.01)。 It apparently takes more into consideration than it should.它显然比它应该考虑的更多。
See IDEA-187390 and IDEA-193714 for details.有关详细信息,请参阅IDEA-187390和IDEA-193714 。
So if your current project does not have a module-info file and you still end up with a module path the current case that I know is that you are running the main class from a dependency.因此,如果您当前的项目没有模块信息文件并且您仍然以模块路径结束,我知道的当前情况是您正在从依赖项运行主类。 Just build a small wrapper inside your project and run the main class from there, that brings you back to the classpath.只需在您的项目中构建一个小包装器并从那里运行主类,这将带您回到类路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.