是否可以在javac(JDK 9)中混合使用--class-path和--module-path? [英] Is it possible to mix --class-path and --module-path in javac (JDK 9)?

查看:207
本文介绍了是否可以在javac(JDK 9)中混合使用--class-path和--module-path?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编译依赖于我之前编译的其他模块的模块时,我必须指定 - module-path< directory> 选项。这使我依赖的模块可见。

When I compile a module that depends on other modules I've compiled previously I have to specify the --module-path <directory> option. This makes modules I depend on visible.

但与此同时我还想让一些非模块化的Jar文件可见。但是,如果不使它们成为自动模块,只需在旁边指定 - class-path some.jar - module-path<目录> ,然后 javac 似乎忽略了claspath并抛出package yyy not found和其他未找到错误。

But at the same time I would also like to make some non-modular Jar files visible. However if don't make them automatic modules and just specify the --class-path some.jar right next to --module-path <directory>, then javac seems to ignore the claspath and throws "package yyy not found" and other "not found" errors.

我能理解使用 - class-path - module-path 在同一个(编译)时间是非法的,但 javac 并没有以任何方式警告我。

I can understand that using --class-path and --module-path at the same (compile) time is illegal, but javac does not warn me against it in any way.

推荐答案

您可以并行使用类路径和模块路径,但需要考虑一些细节。

You can use class path and module path in parallel, but there are a few details to consider.

显式模块(模块路径上带有模块描述符的JAR)无法读取未命名的模块(类路径上的JAR) - 这是故意的防止模块化JAR依赖于类路径的混乱。

Explicit modules (JARs with a module descriptor on the module path) can not read the unnamed module (JARs on the class path) - that was done on purpose to prevent modular JARs from depending on "the chaos of the class path".

由于模块必须要求其所有依赖项,而这些只能由其他命名模块来实现(即不是类路径上的JAR)模块化JAR的所有依赖项必须放在模块路径上。是的,即使是非模块化的JAR,也会变成自动模块

Since a module must require all of its dependencies and those can only be fulfilled by other named modules (i.e. not JARs on the class path) all dependencies of a modular JAR must be placed on the module path. Yes, even non-modular JARs, which will then get turned into automatic modules.

有趣的是,自动模块可以读取未命名的模块,因此他们的依赖项可以进入类路径。

The interesting thing is that automatic modules can read the unnamed module, so their dependencies can go on the class path.

如果编译非模块化代码或从非模块化JAR启动应用程序,模块系统仍在使用中,并且由于非模块化代码不表示任何依赖性,因此它不会从模块路径解析模块。

If you compile non-modular code or launch an application from a non-modular JAR, the module system is still in play and because non-modular code does not express any dependencies, it will not resolve modules from the module path.

因此,如果非模块化代码依赖于模块路径上的工件,则需要使用 - add-modules 选项。不一定都是它们,只是那些你直接依赖的(模块系统会引入传递依赖) - 或者你可以使用 ALL-MODULE-PATH (检查链接帖子,它更详细地解释了这一点。)

So if non-modular code depends on artifacts on the module path, you need to add them manually with the --add-modules option. Not necessarily all of them, just those that you directly depend on (the module system will pull in transitive dependencies) - or you can use ALL-MODULE-PATH (check the linked post, it explains this in more detail).

这篇关于是否可以在javac(JDK 9)中混合使用--class-path和--module-path?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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