aspose file tools*
The moose likes Distributed Java and the fly likes How to invoke java.lang.reflect.Method with JDI java options Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "How to invoke java.lang.reflect.Method with JDI java options" Watch "How to invoke java.lang.reflect.Method with JDI java options" New topic
Author

How to invoke java.lang.reflect.Method with JDI java options

Iris Waits
Greenhorn

Joined: Jul 27, 2006
Posts: 2
Hello, I have to launch a remote application on my machine. I managed to do that with a small script that invokes the main method of the application I want to execute, but now I have the problem to launch this application with some options to java command (these options are about remote debugging with JDI ). I tried with System.setProperty(..) but it didn't fixed. In other words, what I would like to di is the following, if I could do it from command line:
java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket myApp.jar (myApp.jar is on a remote host)
while all that I'm able to do is
java myApp.jar
Of course I want to do it from my java code, not from command line.
Thank you everybody
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

If you are launching this through a script - wouldn't you just add these command line options to the script?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Iris Waits
Greenhorn

Joined: Jul 27, 2006
Posts: 2
What I do is to launch an instance of the class containing main function, here is an extract of the code:

Object obj = ....; //obj is the class containg main, for instance MyClass
java.lan.reflect.Method m = .....; //m is the main method

Object result = m.invoke(obj, args);

This works, the main method gets called and so the application starts. Of course, the main method is called from a jar built in the right way.
But the way the main method gets called is like doing

java MyClass

How can I change java options so that when the main method gets called, this is like calling java -options??

Thanks,
Iris
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

The "options" in this case are not command line options to the java program (which you would be able to get from the String[] parameter to main()), but are command line options to the JVM. You can't specify JVM options for a specific class - and as far as I know, so far there isn't a way to change JVM options from inside a JVM. You'll need to specify these options on the command line of whatever JVM is running this class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to invoke java.lang.reflect.Method with JDI java options