• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic