简体   繁体   English

使用自定义类路径使用 GraalVM 本机映像命令行?

[英]Working GraalVM native-image command line with custom classpath?

I'm on a project that currently builds into 26 jars (+6 if we count the test-only jars).我正在进行一个项目,该项目目前构建为 26 个 jars (如果我们计算仅测试 jar,则为 +6)。 We want to combine them all into a single executable for performance reasons.出于性能原因,我们希望将它们全部组合成一个可执行文件。 This is on a windows machine, with graalVM-ce-java11-20.0.0.这是在 windows 机器上,带有 graalVM-ce-java11-20.0.0。 We're using IntelliJ and gradle.我们正在使用 IntelliJ 和 gradle。 I'm currently just trying to come up with a command line that's work even a little before I try to reproduce it in gradle.在我尝试在 gradle 中重现它之前,我目前只是想提出一个可以工作的命令行。 Gradle isn't in the picture yet, thus the lack of the appropriate tag. Gradle 尚未出现在图片中,因此缺少相应的标签。

I've tried everything I can think of to get past my first missing class, to no avail.我已经尝试了我能想到的一切来克服我第一次失踪的 class,但无济于事。 This strikes me as something basic that I'm too close to and can't see the forest due to all the thrice cursed trees in the way.这让我觉得有些基本的东西,我离得太近了,由于路上所有的三次被诅咒的树,我看不到森林。

I currently have all the jars in the graalvm/bin folder.我目前在 graalvm/bin 文件夹中拥有所有 jars。 That should make it easy, right?这应该很容易,对吧? Not so much.没那么多。

I'm trying to build jar D, using classes from (among other places), jar A. foo.bar.AP is the first class it can't find, which kicks it out or to a fallback build.我正在尝试构建 jar D,使用来自(以及其他地方)的类 jar A. foo.bar.AP 是第一个 class 它无法找到的回退构建,

I've tried a relative path to the directory: native-image -cp./ -jar D我尝试了目录的相对路径: native-image -cp./ -jar D

I've tried a full path to the directory: native-image -cp c:/foo/bar/baz -jar D我尝试了目录的完整路径: native-image -cp c:/foo/bar/baz -jar D

I've tried a full path the jar in question: native-image -cp c:/graalvm/bin/A.jar -jar D我已经尝试了一个完整的路径 jar 有问题: native-image -cp c:/graalvm/bin/A.jar -jar D

I've tried all the aliases for the class path:我已经尝试了 class 路径的所有别名:

  • native-image -cp... -jar D
  • native-image -classpath... -jar D
  • native-image --class-path... -jar D

I've even tried adding a classpath to D.jar's MANIFEST.MF via gradle's jar { manifest { attributes: ( "Class-Path": "..." ) } } .我什至尝试通过 gradle 的jar { manifest { attributes: ( "Class-Path": "..." ) } }向 D.jar 的 MANIFEST.MF 添加一个类路径。 This is right along side the working "Main-Class": "foo.bar.D.baz" attribute in the same place.这是在同一个地方工作的"Main-Class": "foo.bar.D.baz"属性旁边。

Did I just happen on the one directory that native-image automatically ignores (it's own bin folder?) Lets find out, Nope.我是不是发生在 native-image 自动忽略的一个目录上(它是自己的 bin 文件夹?)让我们找出来,不。 that didn't help either.那也没有帮助。

Note that I haven't tried all the possible combinations/permutations here.请注意,我没有在这里尝试所有可能的组合/排列。 --class-path with X, Y, but not Z. --class-path有 X,Y,但不是 Z。

What am I missing?我错过了什么? If someone could post a known-good command line (ideally for windows), I'd deeply appreciate it.如果有人可以发布一个已知良好的命令行(理想情况下适用于 Windows),我将不胜感激。

The first thing to try is to get the command line working without native-image, just using plain java.首先要尝试的是让命令行在没有本机映像的情况下工作,只需使用普通的 java。

Similar to what the java launchers does, native-image does not support mixing -jar and -cp if you pass -jar , it will override the classpath and the -cp argument will be ignored.java启动器所做的类似, native-image不支持混合-jar-cp如果您传递-jar ,它将覆盖类路径并且-cp参数将被忽略。

You avoid using -jar and simply pass the name of the main class:您避免使用-jar并简单地传递主 class 的名称:

native-image -cp ...;D foo.bar.D.baz

(i'm assuming here that D is the full path to your jar) (我在这里假设D是你的 jar 的完整路径)

The Class-Path attribute in the JAR should work (in which case you don't need to pass -cp ) but you need to be careful about how the paths in this attribute are resolved: they will be resolved relative to the location of the jar containing the attribute. JAR 中的Class-Path属性应该可以工作(在这种情况下,您不需要传递-cp )但您需要注意如何解析此属性中的路径:它们将相对于jar 包含该属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM