java - problem with arguments when running a jar using reflection -


I tried to apply the method to run a jar using reflection with getMethod but arguments called to pass Having run into trouble with the given method:

  string mainClass = myprog.Run; String [] args = new string [2]; Argos [0] = "-a"; Argus [1] = "-C ./config/param.xml" Class Loader Classloader = CreateClassPath (); // method call the setContextClassLoader (classLoader); Class & lt ;? & Gt; TheClass = classLoader.loadClass (Main Class); TheClass.getMethod ("main", string []. Square). Ivok (tap, object);  

I get this error:

  [java] java.lang.reflect.InvocationTargetException [java] sun.reflect.NativeMethodAccessorImpl.invoke0 on ( Native method) SunkreflectkNativeMethodAccessorImplkinvoke ([Java] on NativeMethodAccessorImpl.java:39) [Java] sun.reflect.DelegatingMethodAccessorImpl.invoke (on DelegatingMethodAccessorImpl.java:25) [Java] java.lang.reflect.Method On. Call (Method.java:597) eu.keep.util.JarRunner.run (Unknown Source) [Java] because at [Java]: java.lang.RuntimeException: not present in the config file 'param.xml' folder Is '/ home / user / ./config' [Java] on dioscuri.DioscuriFrame. & Lt; Init & gt; (Unknown source) [java] dioscuri.DioscuriFrame.main (unknown source) [java] ... 5 more  at 

As you can see from Stacktrace, that folder '/ home Trying to access the file 'param.xml' from / user / ./config '.

Obviously, if there was no space between '/ home / user /' and './config', then it would be al-El properly.

I'm confused with the fact that I String [] args arguments hardcoded in and the second one is "-c ./config/param.xml" and it looks like dir where The app is running, i.e. / home / user /, is mixed with ./config/, but with a space in between ??

Any ideas what is happening?

David

Maybe if we do main method, and in particular the way the argument is understood, we can help you better ...

Note that when you type the command java ... Run your main square with -a -c ./config /param.xml , then you have 3 arguments in your main (string [] args method:

  public static zero main (string [] args) {for (string s: arg } {System.out.println ("->" + + '' '));} ...  

will be displayed:

  -> & gt; -a '- & gt; - C '- & gt;' ./config/param.xml ' 

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -