problems executing an other .jar

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 10510 Views - Last Post: 21 January 2012 - 04:12 PM Rate Topic: -----

#1 Damsch12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 20-December 11

problems executing an other .jar

Posted 17 January 2012 - 02:41 PM

I made an updater for my Java programs following a tutorial from here, but then i tried to modify it a bit, but the code its basically the same.
The problem is, I dont know why the updater.jar file doesnt execute update.jar, everything seems ok, I debuged it and everything works perfectly, no exceptions, no errors, if I manually run update.jar the program executes.

Here is the execution code from updater.jar:
    private void update() {
        String[] run = {"java", "-jar", "updater/update.jar"};
        try {
            Runtime.getRuntime().exec(run);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.exit(0);
    }


Any ideas?, if you need anything else to figure this out just tell me.

Is This A Good Question/Topic? 0
  • +

Replies To: problems executing an other .jar

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3687
  • View blog
  • Posts: 16,920
  • Joined: 20-September 08

Re: problems executing an other .jar

Posted 17 January 2012 - 03:53 PM

There are a couple of problems with treatment here. Firstly you should really treat both stdout and stderr of the process on separate streams. See http://technojeeves..../52-runtimeexec

You also might think of using absolute paths to reduce the possibility of error
Was This Post Helpful? 0
  • +
  • -

#3 Damsch12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 20-December 11

Re: problems executing an other .jar

Posted 17 January 2012 - 04:07 PM

View Postg00se, on 17 January 2012 - 03:53 PM, said:

There are a couple of problems with treatment here. Firstly you should really treat both stdout and stderr of the process on separate streams. See http://technojeeves..../52-runtimeexec

You also might think of using absolute paths to reduce the possibility of error


what...?, im sorry im not an advanced JAVA programmer, this is actually the second time in my life I use Threads :D.

I didnt really changed much from the original program from the tut (this tut), I tried it and worked perfectly, but then I wanted to modify it so it can load the internet address from a .ini or .txt file (So it can be used for any program just by changing this file), updater.jar calls update.jar but this one doesnt open, but if you double click on it, it works perfectly.
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3687
  • View blog
  • Posts: 16,920
  • Joined: 20-September 08

Re: problems executing an other .jar

Posted 18 January 2012 - 08:00 AM

    private void update()
    {
        String[] run = {"java","-jar","updater/update.jar"};
        try {
	    //System.out.println("Attempting to update...");
            Process p = Runtime.getRuntime().exec(run);
	    IOUtils.outputProcessStreams(p);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.exit(0);
    }



Is how it should be, or you'll probably see absolutely nothing if there's an error.

All this is a little academic in a way: if you distribute your app via WebStart, it has support for transparent version updates anyway. No other/extra software required.
Was This Post Helpful? 1
  • +
  • -

#5 Damsch12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 20-December 11

Re: problems executing an other .jar

Posted 19 January 2012 - 11:10 AM

    
IOUtils.outputProcessStreams(p);


I get an error here, it says outputProcessStreams() does not exist.

View Postg00se, on 18 January 2012 - 08:00 AM, said:

All this is a little academic in a way: if you distribute your app via WebStart, it has support for transparent version updates anyway. No other/extra software required.

I never used it, so, do you know any good book or tutorial to read about it?
Was This Post Helpful? 0
  • +
  • -

#6 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3687
  • View blog
  • Posts: 16,920
  • Joined: 20-September 08

Re: problems executing an other .jar

Posted 19 January 2012 - 11:21 AM

Quote

I get an error here, it says outputProcessStreams() does not exist.


Works for me. Make sure you put it into the right package and import it. Or put it in the same package as your code (nasty)

http://docs.oracle.c...yment/webstart/
Was This Post Helpful? 1
  • +
  • -

#7 Damsch12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 20-December 11

Re: problems executing an other .jar

Posted 19 January 2012 - 11:33 AM

Oh, thanks, now i got it to work, my bad :). I thought it was Java IOUtils, now i added the class.

By the way, do you know any good book to get more advanced in java?
Was This Post Helpful? 0
  • +
  • -

#8 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3687
  • View blog
  • Posts: 16,920
  • Joined: 20-September 08

Re: problems executing an other .jar

Posted 19 January 2012 - 12:24 PM

Have a look at the Sun/Oracle java tutorials. There's also an online book Thinking in Java by Bruce Eckel. There's no substitute for practise.
Was This Post Helpful? 0
  • +
  • -

#9 Damsch12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 20-December 11

Re: problems executing an other .jar

Posted 19 January 2012 - 12:33 PM

ok, thanks. :)
Thats the book they recommended us in the university.

I tried what you said, but still nothing happens, i tried running it with netbeans, when i click update the gui dissapears and nothing happens, the program is still running in he background, but netbeans is unable to finish it of, its like it gets stucked or something.
Any ideas?
if you want i can give you the netbeans projects to test them :)
Was This Post Helpful? 0
  • +
  • -

#10 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3687
  • View blog
  • Posts: 16,920
  • Joined: 20-September 08

Re: problems executing an other .jar

Posted 19 January 2012 - 12:41 PM

You probably should be trying to run it outside NetBeans now. The original author should probably comment too...
Was This Post Helpful? 0
  • +
  • -

#11 Damsch12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 20-December 11

Re: problems executing an other .jar

Posted 20 January 2012 - 06:02 AM

View Postg00se, on 19 January 2012 - 12:41 PM, said:

You probably should be trying to run it outside NetBeans now.

I did run it outside Netbeans, still the same, nothing happens.

View Postg00se, on 19 January 2012 - 12:41 PM, said:

The original author should probably comment too...

Should i send him a pm?
Was This Post Helpful? 0
  • +
  • -

#12 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3687
  • View blog
  • Posts: 16,920
  • Joined: 20-September 08

Re: problems executing an other .jar

Posted 20 January 2012 - 06:09 AM

Quote

Should i send him a pm?


I'm not sure what the correct approach is on this site. What happened when you amended the code to what i posted? It should have printed something
Was This Post Helpful? 0
  • +
  • -

#13 Damsch12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 20-December 11

Re: problems executing an other .jar

Posted 20 January 2012 - 06:18 AM

Nothing happens, the updater.jar gets closed and nothing else happens.

Instead of sending him a pm, I will reply in the tut, leaving a link to this topic, maybe he will answer.
Was This Post Helpful? 0
  • +
  • -

#14 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2972
  • View blog
  • Posts: 11,223
  • Joined: 15-July 08

Re: problems executing an other .jar

Posted 20 January 2012 - 08:46 AM

It opened and closed because you double clicked the JAR right? Try opening a terminal (or cmd.exe), go to the proper directory and type,

java -jar jarfile.jar



And then, it should output SOMETHING that you can see.
Was This Post Helpful? 0
  • +
  • -

#15 Damsch12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 20-December 11

Re: problems executing an other .jar

Posted 20 January 2012 - 08:59 AM

If double click the updater.jar file, the gui opens and stays open, but when i click the update button, its supposed to close and open the update.jar file, but the update.jar file doesnt open.
The update.jar file works, if you double click it, the program opens, and downloads the update.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2