Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native-image] windows: ProcessBuilder bug #1185

Closed
mbbee opened this issue Apr 23, 2019 · 9 comments
Closed

[native-image] windows: ProcessBuilder bug #1185

mbbee opened this issue Apr 23, 2019 · 9 comments

Comments

@mbbee
Copy link

mbbee commented Apr 23, 2019

I'm getting the error below when i use ProcessBuilder in a native image.

Exception in thread "System-2" java.lang.NoClassDefFoundError: Ljava/io/IOException;
        at com.oracle.svm.jni.functions.JNIFunctions.FindClass(JNIFunctions.java:326)
        at java.lang.ProcessImpl.create(ProcessImpl.java)
        at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
        at java.lang.ProcessImpl.start(ProcessImpl.java:137)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
        at java.lang.Runtime.exec(Runtime.java:620)
        at java.lang.Runtime.exec(Runtime.java:450)
        at TestNativeImage.startCommandSimple(TestNativeImage.java:32)
        at TestNativeImage.main(TestNativeImage.java:22)

Same with eg Runtime.getRuntime().exec(commandStr, null, workingDir);

I'm using the native-image-maven-plugin version 1.0.0-rc15
thx

@cstancu
Copy link
Member

cstancu commented Apr 23, 2019

@mbbee Java classes accessed via JNI need to be registered. See the JNI documentation for details.

@cstancu
Copy link
Member

cstancu commented Apr 23, 2019

In your case you should add -H:JNIConfigurationFiles=jni-config.json to the native-image command, where jni-config.json contains at least:

[
  {
    "name" : "java.io.IOException"
  }
]

After that you may need to expand this config file with further classes/methods/fields accessed via JNI.

For an automated method of discovering all the elements accessed via JNI look at Assisted Configuration of Native Image Builds. I would suggest to build from source or wait for RC16 which is coming out soon since we have fixed a series of issues with the native-image-agent since RC15.

@mbbee
Copy link
Author

mbbee commented Apr 23, 2019

the graalvm-ee-1.0.0-rc16-snapshot-windows-amd64 produces other strange errors when i try to run the command "cmd /c dir" with Process or ProcessBuilder. Maybe an encoding issue:

Der Befehl "dir?%�" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

i also tried native-image-agent which created an empty "jni-config.json "

another strage issue: the following statement retrieves a wrong (not existing) directory:
File workingDir = new File(System.getProperty("user.home"));
result: C:\Users\somebody

@mbbee
Copy link
Author

mbbee commented Apr 24, 2019

many problems are gone with native-image-maven-plugin 1.0.0-rc16
but following still exisits:
System.getProperty("user.home")) retrieves wrong dir
and ProcessBuilder has problems with empty spaces in path ( this was a problem in jdk8 ?)

@mbbee
Copy link
Author

mbbee commented Apr 27, 2019

file.isDirectory() is also buggy, sometimes it works sometimes not
(Files.isDirectory is allways korrect)

	public static void checkIsDirectory() {
		Path currentPath = Paths.get("").toAbsolutePath();
		System.out.println("path: " + currentPath.toString());
		File file = currentPath.toFile();
		File[] files = file.listFiles();
		for (File f : files) {
			String type = f.isDirectory() ? "D" : "F";
			String type2 = Files.isDirectory(f.toPath()) ? "D" : "F";
			if (type.equals(type2))
				System.out.println("OK------ type: " + type + " " + type2 + " file: " + f.getName());
			else
				System.err.println("ERROR--- type: " + type + " " + type2 + " file: " + f.getName());
		}
	}

@mbbee
Copy link
Author

mbbee commented Apr 27, 2019

and ProcessBuilder doesn't find the "cmd" command
eg "cmd /c R:\putty.exe"

@peter-hofer
Copy link
Member

Have you tried with the 19 release? We have fixed an issue how strings are passed which is likely related to this.

@mbbee
Copy link
Author

mbbee commented Jun 12, 2019

ProcessBuilder has wrong environment.
environment is from build time not from runtime!

@peter-hofer
Copy link
Member

Looks like you opened #1312 for this, closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants