0

I am running these line of codes to run a Test.jar which is an executable jar

public static void main(String[] args) throws IOException{

        File f = new File("path to exe jar");
        if(f.exists() && !f.isDirectory()) { 
           System.out.println("Valid");
        }else{
            System.out.println("Invalid");
        }


        ProcessBuilder pb = 
                new ProcessBuilder("path to exec jar", "-jar", "Test.jar",
                        "args1","args2","args3","args4");
        pb.directory(new File("path to exec jar"));
        Process p = pb.start();

    }

And I keep getting this error: File is valid though so I think this might be access issues. What do I need to add to get the access needed?

Valid
Exception in thread "main" java.io.IOException: Cannot run program "abc" (in directory "abc"): CreateProcess error=5, Access is denied
2
  • Drop to the command line and try and use the same command, if it doesn't work from the command line, it won't work in code Commented Oct 12, 2017 at 23:31
  • Why you're using an entire Java JVM just to start another JVM is another mystery. Use a script. Commented Oct 12, 2017 at 23:33

1 Answer 1

2

"path to exe jar" should be "java" in the constructor for ProcessBuilder. You can't execute a path.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.