Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Iris Waits
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are launching this through a script - wouldn't you just add these command line options to the script?
 
Iris Waits
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic