Skip to main content

JVM Additional options like agentlib and Xbootclasspath

3 replies [Last post]
Joined: 2009-10-21
Points: 0


When the JT Harness kicks off its tests, it does a Runtime.exec and spawns off a new JVM process. Is there a way to pass additional JVM options to this java process which gets spawned? For example, the following is a command which gets spawned via the Runtime.exec when i run a simple Helloworld application.

com.sun.javatest.lib.ExecStdTestOtherJVMCmd C:\Java\jdk1.6.0_02\bin\java.exe -classpath C:\jtharness\examples\tutorial\helloworld\lib\javatest.jar;C:\jtharness\examples\tutorial\helloworld\classes $testExecuteClass $testExecuteArgs

To the above java command, is it possible to add options like -Xbootclasspath and agentlib? For example, convert the above call to the following:

com.sun.javatest.lib.ExecStdTestOtherJVMCmd C:\Java\jdk1.6.0_02\bin\java.exe -Xbootclasspath/a: -agentlib: -Dsomekey=somevalue -classpath C:\jtharness\examples\tutorial\helloworld\lib\javatest.jar;C:\jtharness\examples\tutorial\helloworld\classes $testExecuteClass $testExecuteArgs

If the above is possible which file do i need to edit?
Any help is appreciated. Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-11-11
Points: 0

It can also be done in the Interview class. Chances are, you need to write your own interview anyway. I started with a variant of Simple and Modified the getOtherVMExecuteCommand() question.

something like:
private String getOtherVMExecuteCommand() {
char fs = File.separatorChar;
char ps = File.pathSeparatorChar;

StringBuffer sb = new StringBuffer();
String temp;
sb.append("com.sun.javatest.lib.ExecStdTestOtherJVMCmd ");
sb.append("-v ");
String lDisp = System.getenv("DISPLAY");
if (lDisp != null && lDisp.length() > 0) {
sb.append("DISPLAY=" + lDisp + " ");
File jvm = qJVM.getValue();
sb.append(jvm == null ? "unknown_jvm" : jvm.getPath());
File[] cpFiles = qClassPath.getValue();
if (cpFiles != null && cpFiles.length > 0) {
sb.append(" -classpath \'");
for (int i = 0; i < cpFiles.length; i++) {
if (i > 0) {
temp = cpFiles[i].getAbsolutePath();

sb.append(" org.junit.runner.JUnitCore $testExecuteClass $testExecuteArgs");
// sb.append(" org.mine.proj.javatest.junit.JUnitRunner $testExecuteClass $testExecuteArgs ");
return sb.toString();

Joined: 2009-10-21
Points: 0

Thanks Bern. I was able to solve the issue by modifying the SimpleInterviewParameters class just like you suggested. Much better than my previous approach.

I created a few questions that I needed during the interview and now i have these JVM arguments asked to be entered during the interview.

Thanks again.

Joined: 2009-10-21
Points: 0

I was able to achieve this. For someone who is trying to do the same this is what i did.

[b]com.sun.javatest.ProcessCommand[/b] file gets called by the ExecStdTestOtherJVMCmd class when the tests are being executed. The ProcessCommand makes a Runtime.exec() call. There are String[] (arrays) namely cmd and cmdEnv in the ProcessCommand class under the exec method. These arrays need modification. You can append the JVM arguments to the cmd String array. It worked for me.

Compile the class ProcessCommand and update it to the javatest.jar file.

I hope this is useful for someone who is trying to do the same. I would love to know if there is a better way of doing it.