Java SxS (side by side) configuration
Asked Answered
H

1

11

I am facing a very obscure issue, while I am trying to run a java app in Windows, Side by Side (SxS).

I have done all the preparation creating the java.exe.config and java.exe.manifest files, which I have in the same folder with the JRE.

The application runs normally when I invoke it from the command line (by starting a .bat file). The .bat file uses the SxS configured Java (which is the only one in the box I am running the application)

However, when I try to invoke it from inside another Java process (using Runtime.getRuntime.exec()) or ProcessBuilder it seems that it totally ignores the SxS configuration and the child Java process is complaining it cannot find the COM libraries, which were the reason I had to do SxS. I have to add that the parent Java process is also launched by the Java.exe that is configured for SxS. Thus, I would assume that the "Runtime.getRuntime(), ProcessBuilder()" would give me the Java SxS loaded environment.

Doing some further debugging using some windows tools (procexp.exe, procmon.exe) i found out the following: When i start the application from the .bat file the .manifest file is normally read by crss.exe (as it supposed to be). However, when another process is spawned by Java the .manifest file is NOT taken into consideration at all. One possible problem i could think of is that the current directory of the Java.exe which starts the process is not the same as the java.exe.manifest file is located.

The only thing i can think of is a bug/problem (or maybe they call it a feature) in the java launcher.

Does anyone had a similar problem? Could anyone shed any light on the above? Much appreciated.

So far i had tried the following:

  • Run the java process from inside a .bat file. WORKED
  • Invoked the java process from a parent Java process using Runtime.getRuntime().exec(). DID NOT WORK
  • Invoked the .bat file from a parent Java process using Runtime.getRuntime().exec(). DID NOT WORK
  • Used ProcessBuilder setting the current directory where the .manifest file is. DID NOT WORK
Histrionic answered 16/9, 2013 at 8:12 Comment(3)
We had a similar problem trying to load native dll via JNI that required sxs assemblies. We ended up reading manifest from resources and creating activation context manually in C++ code. Not sure if there is a better way. Try invoking child process via ShellExecute somehow?Sieve
No idea here, but the description of java command seems worth reading docs.oracle.com/javase/7/docs/technotes/tools/windows/java.htmlFidele
@clwhisk the problem is not in the java command. The problem is with how Windows OS loads the java command. It seems that the parent dir of the java process (when windows invokes it) is C:\Windows, thus csrss.exe cannot find the java.exe.manifest file for the SxS configuration.Histrionic
K
1

I tested it in my computer and it works. Try:

  • read getErrorStream() from Runtime.getRuntime().exec(...); and send here, if you can't solve this,
  • run process with full path (C:\Program...),
  • compile java program to .jar, put in to folder with .bat, open CMD, set current directory to this folder and run jar file (using java -jar filename.jar),
Kidding answered 30/4, 2015 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.