如何在IDEA中使用类路径而不是模块路径运行Java 9应用程序? [英] How to run Java 9 application with classpath rather than module path in IDEA?

查看:875
本文介绍了如何在IDEA中使用类路径而不是模块路径运行Java 9应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在IDEA中运行主类时,它将模块及其依赖项放在模块路径上。是否可以将其更改为类路径?

When I run a main class in IDEA, it puts the module and its dependencies on a module path. Is it possible to change it to a classpath?

推荐答案

如果您没有定义模块信息,IDEA会设置应用程序和您对类路径的依赖关系。由于你有一个模块信息,它是一个显式模块,所以它必须在模块路径上。通常,您现在可以将自己的dependecies作为自动模块处理。

If you don't define a module-info, IDEA would set the application and your dependencies on the classpath. 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.

但是,您的依赖关系至少有充分的理由进入类路径。我们在这里讨论了为什么Java 9不会简单地将类路径上的所有JAR转换为自动模块?

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?

例如,mymodule依赖于自动模块然而,它需要一个不能成为自动模块的jar。在命令行上它会这样:

For example, mymodule depends on an automatic-module which however needs a jar that can't become an automatic-module yet. On commandline it would like this:

java -cp legacy.jar -pmymodule.jar; automodule.jar; -m mymodule / com.example.mymodule.Application

java -cp legacy.jar -p "mymodule.jar;automodule.jar;" -m mymodule/com.example.mymodule.Application

IMO intellij目前不支持。作为至少在类路径上运行整个应用程序的解决方法,您可以重命名模型信息以禁用/暂时不是拼图模块。

IMO intellij doesn't currently support that. 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.

这篇关于如何在IDEA中使用类路径而不是模块路径运行Java 9应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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