Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 586985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:09:50+00:00 2026-05-13T15:09:50+00:00

I try to run a jar using reflection with the the getMethod and invoke

  • 0

I try to run a jar using reflection with the the getMethod and invoke method but ran in trouble with the arguments passed to the invoke method:

String mainClass = myprog.Run;
String[] args = new String[2];
args[0] = "-a";
args[1] = "-c ./config/param.xml"

ClassLoader classLoader = createClassLoader(getClassPath());

// Invoke the method
setContextClassLoader(classLoader);
Class<?> theClass = classLoader.loadClass(mainClass);

theClass.getMethod("main", String[].class).invoke(null, (Object) args);

and I get this error:

 [java] java.lang.reflect.InvocationTargetException
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 [java]     at java.lang.reflect.Method.invoke(Method.java:597)
 [java]     at eu.keep.util.JarRunner.run(Unknown Source)
 [java] Caused by: java.lang.RuntimeException: config file 'param.xml' does not exist in folder '/home/user/ ./config'
 [java]     at dioscuri.DioscuriFrame.<init>(Unknown Source)
 [java]     at dioscuri.DioscuriFrame.main(Unknown Source)
 [java]     ... 5 more

As you can see from the stacktrace, it is trying to access the file ‘param.xml’ from the folder ‘/home/user/ ./config’.

Obviously, if the space between ‘/home/user/’ and ‘./config’ was not there, it would all be fine.

I am confused with the fact that I have hardcoded the arguments into String[] args and the second one is “-c ./config/param.xml” and it looks like the dir from which the app is running, i.e. /home/user/, gets concatenated with ./config/ but with a space in between ??

Any idea what is happening ?

David

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:09:51+00:00Added an answer on May 13, 2026 at 3:09 pm

    Maybe if we have a look at your main method, and in particular the way the arguments are managed, we could help you in a better way…

    Note that when you run your main class with the command java ... -a -c ./config/param.xml, then you have 3 arguments in your main(String[] args) method:

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

    will display:

    -> '-a'
    -> '-c'
    -> './config/param.xml'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 301k
  • Answers 301k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the DoEvents() code as shown here: http://blogs.microsoft.co.il/blogs/tamir/archive/2007/08/21/How-to-DoEvents-in-WPF_3F00_.aspx My actual… May 13, 2026 at 8:08 pm
  • Editorial Team
    Editorial Team added an answer Imagine you create a list of Dogs. You then declare… May 13, 2026 at 8:08 pm
  • Editorial Team
    Editorial Team added an answer I think I have now solved this myself. It seems… May 13, 2026 at 8:08 pm

Related Questions

I'm trying to build a runnable JAR using Eclipse's Export function. everything works fine
I have created a jar file to load a native library ( using System.loadlibrary()
How do I set the classpath order in ant? Specifically, When I am trying
I'm looking for a good way to run a Apache Derby server in network
I created a small desktop project using Hibernate, to understand how enterprise patterns are

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.