Smart questions
Smart answers
Smart people
Join Tek-Tips Forums

Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Problems executing a jar file from within java code

posdef (TechnicalUser) (OP)
27 Apr 10 4:53

The problem is as follows, I am writing an analysis software, and as a final step of the analysis I want to give the users to view the analysis done. I have found a nice open source software for that last part and what I'd like to do is to execute that program from within my code so that the user doesn't need to bother with that..

The code as it is today looks like this:


try {
            String path_2_owlfile = owlFile.getCanonicalPath();
            if (path_2_owlfile.contains("owl")){
                Object[] o = command.toArray();
                String[] cmd = Arrays.copyOf(o, o.length, String[].class);
                // debug info
                StringBuilder sb = new StringBuilder();
                for (int i=0;i<cmd.length;i++){
                    sb.append(" ");
                Process child = Runtime.getRuntime().exec(cmd);

note that i use system.err for debug since system.out points to a file (the packages i use in my code create a lot of clutter so I set the out stream to a file to keep the terminal relatively clean)

So what happens is that my code executes without any Exceptions thrown, but the application I want to run is never launched. If I c/p the debug text from system.err to terminal, everything works fine.. What could this depend on, and how would one go about solving it?

Diancecht (Programmer)
27 Apr 10 18:40
It's difficult to say since I guess you see a command window flickering without time to read. I'd redirect the output of the command to a file using > to see if there's any error.

Appart from that, did you consider the idea of adding the jar to the classpath of your program and invoke a Java class?


posdef (TechnicalUser) (OP)
28 Apr 10 4:16
Hey Dian,

thanks for the reply.. Following your suggestion, I added


to my code. Still no exceptions or errors, not even a file called debug.log. Frustrating...

Could you elaborate on your secondary suggestion? If I understood correctly you suggest that I include the jar file in the classpath and create an instance within my java code. I am not quite sure how that would work, seeing as the jar file consists of lots of packages and classes..  
TonHu (Programmer)
28 Apr 10 6:13
Output redirection using > is a function of cmd.exe/, not of the OS.

The second suggestion by Dian is IMHO spot on, why go through the outside door, when you can just directly interface?
posdef (TechnicalUser) (OP)
29 Apr 10 4:25


Output redirection using > is a function of cmd.exe/, not of the OS.

True, i had forgotten about that..


The second suggestion by Dian is IMHO spot on, why go through the outside door, when you can just directly interface?

I see what you are getting at, though I am not quite sure how I could accomplish that, as they are two separate projects. I'd really appreciate if you could elaborate on that..  
Diancecht (Programmer)
29 Apr 10 5:50
Let's start with the first problem. I'd use this code to capture the output and see what's going on.



Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close