murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Invoke a JAVA PROGRAM during Updating

Wed Aug 29, 2012 3:21 pm

Hi,

When my application is being updated by a new version, I need to run a standalone java program (which i am able to run successfully through command prompt).
I also need the update to rollback, incase the java program fails to execute completly.

p.s. The java program essentially runs a couple of DDL scripts on the previously installed application's DB.

Thank you.
ASH

mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Invoke a JAVA PROGRAM during Updating

Thu Aug 30, 2012 10:44 am

Hello Ash,

Here's what you can try:
- add the .JAR file as part of your installation from Files and Folders page
- add a search for "java.exe" from the Search page
- follow How do I hide the command window of a custom action? article
- use the search above with your command line in the "Action Data" field of the attached custom action and set the custom action to be "Deferred, with no impersonation"
- you should also add a java launch condition so the package will install only on machines that have it installed

I attached a basic test project with .JAR file that demonstrate the functionality.
test.zip
(4.02 KiB) Downloaded 334 times
Regarding "retCode.jar":
- mainclass "testOK" returns 0
- mainclass "test" returns 3
=>When testOK is executed from the custom action "Action Data" field, the installation will continue.
=>When test is executed from the custom action "Action Data" field, the installation will automatically rollback.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Invoke a JAVA PROGRAM during Updating

Wed Sep 05, 2012 7:35 am

Hi Mihai.

I did this in another fashion:
I added the migration.JAR & a executeMigration.BAT (java -jar migration.jar)
Then used a 'Launch a installed file' Custom action to invoke the executeMigration.BAT

It worked during an installation. I have to do this during an update.
BUT i'm having a general problem with the update of my application. (I've sent you a mail with the verbose log & aip yesterday) [mail sub: Update Issue]
mihai.petcu wrote:- you should also add a java launch condition so the package will install only on machines that have it[/b] installed

Do you mean 'it' as in, the target computer should hav java.exe installed? Ok. That's fine.

I, wanted to know how to make sure the update can be rolledback if the java program does NOT execute successfully.
Does the 'Synchronous Execution, check for return code' option in Execution Properties of the 'Custom Action Properties' page ensure this ?

Thanks.

ASH

Daniel
Posts: 8187
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Invoke a JAVA PROGRAM during Updating

Fri Sep 07, 2012 10:28 am

Hello,

Yes, when "Synchronous execution, check return code" or "Asynchronous execution, wait for return code at the end of the sequence" options from "Custom Action Properties" right pane are enabled the installation will rollback if the related custom actions fails.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Invoke a JAVA PROGRAM during Updating

Fri Sep 07, 2012 10:35 am

A rollback is triggered when the return code indicates the custom action was not executed successfully. If your custom action's execution property evaluates the return code then it can rollback the installation.

You can read more about execution properties in the following user guide articles:
Custom Action Properties
Custom Action Return Code

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Invoke a JAVA PROGRAM during Updating

Fri Sep 07, 2012 12:52 pm

yeah,

I'v read the above links over and over again. it;s almost engraved in my mind :)

Anyway, this my present situation:
Case 1:
I analyzed your test.zip. Did the same thing as in your Java Custom Action.aip; using aicustact.dll & java.exe search.
As mentioned above, I need this CustomAction to be executed during an UPDATE alone.
But for a 'Launch attached file' there is no 'Execution Stage Condition' where i can set it must happen ONLY during an UPDATE.

Case 2:
I reverted back to calling the JAR file, through a BAT file. Both these files are in the APPDIR; so i used a 'Launch installed file' to invoke the BAT file.
This custom Action is scheduled in the 'Final Dialog Stage' -> 'Finish Execution'.
This I got working during an update as required.
But the problem is a rollback if the action fails.
For this, as seen in the test.zip; i added the System.exit(3) in my java code incase an exception occured.
BUT, though a pop-up shows a component in the installation has failed, the update is NOT ROLLEDBACK.
WHY IS THIS SO?

Case 3:
I assumed the above problem is cuz the CustomAction is executed too late in the sequence.
As the custom action relies on files in the APPDIR, I advanced this custom action from 'Final Dialog Stage' : 'Finish Execution' TO 'Install Execute Stage' -> 'Add Resources'
In this scenario, the new JAR is NOT getting executed.
I mean; remember this is a UPDATE process. i.e. there is already an old JAR in the APPDIR(from the original installation). This old JAR is getting executed instead of the new one.

now. please advice me on how I can proceed.

mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Invoke a JAVA PROGRAM during Updating

Mon Sep 10, 2012 3:19 pm

Hello,
As mentioned above, I need this CustomAction to be executed during an UPDATE alone. But for a 'Launch attached file' there is no 'Execution Stage Condition' where i can set it must happen ONLY during an UPDATE.
I don't understand what you mean by this. "Execution stage condition" is available for any custom action. To find out about the condition you can read the related How do I determine if an Upgrade is being performed? FAQ.
For this, as seen in the test.zip; i added the System.exit(3) in my java code incase an exception occured. BUT, though a pop-up shows a component in the installation has failed, the update is NOT ROLLEDBACK. WHY IS THIS SO?
Not every .JAR can have its return code evaluated by the installer. The example I attached follows the user guide article and it uses our own "CreateExeProcess" which does that.
As the custom action relies on files in the APPDIR, I advanced this custom action from 'Final Dialog Stage' : 'Finish Execution' TO 'Install Execute Stage' -> 'Add Resources'. In this scenario, the new JAR is NOT getting executed. I mean; remember this is a UPDATE process. i.e. there is already an old JAR in the APPDIR(from the original installation). This old JAR is getting executed instead of the new one.
What upgrade order are you using?
In case of "Uninstall old version first and then install new version" the new .JAR should be present after "Install Execute Stage" -> "Add Resources" but in case of "Install new version first and then uninstall old version" the old version is removed right before "InstallFinalize". To avoid similar issues with custom actions you could add them as "Launch attached file" instead of "Launch installed file".

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Invoke a JAVA PROGRAM during Updating

Mon Sep 17, 2012 9:56 am

Hi,
mihai.petcu wrote:I don't understand what you mean by this. "Execution stage condition" is available for any custom action.
This is from the AIP in the above zip. It's the Custom Action which calls the aicustact:
noExecutionStageCondition.png
noExecutionStageCondition.png (41.13 KiB) Viewed 6293 times
There is no "Execution stage condition" available for this custom action.
This is a 'Launch attached file' custom action, which i need to be run ONLY on an UPDATE.

mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Invoke a JAVA PROGRAM during Updating

Mon Sep 17, 2012 12:13 pm

Hello,

After discussing the issue with the development team, it seems there was a related bug in version 9.4 regarding this which was fixed in version 9.5. If you change the selection and then come back to the custom action, the "Execution Stage Condition" will be shown. You can either use this workaround or update to 9.5.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”