Webstart: service.installSucceeded(false) becomes endless loop
Hi at all !
I have a problem implementing an installer for webstart. The installation of my program is ok but if i want to finish the installer with service.installSucceeded(false); i think i get a endless loop and the WS says that there was a JNLPException: Launch File Error.
Here my jnlp file:
<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for JVision Application -->
<jnlp
spec="1.0+"
codebase="http://myhost/mydir"
href="jai.jnlp">
<information>
<title>Some Title</title>
<vendor>myself</vendor>
<description>Installer</description>
<description kind="short">Software</description>
<homepage href="http://java.sun.com"/>
<icon href="splash.jpg"/>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.4+" initial-heap-size="64m" max-heap-size="64m" java-vm-args="-Dhallo=hallo" />
<jar href="test.jar"/>
<property name="url.to.file" value="http://myhost/mydir/exe_file_that_should_be_installed.exe"/>
<property name="destination.file.name" value="exe_file_that_should_be_installed.exe"/>
<property name="destination.path.name" value="/path_where_my_installer_places_the_exe_file"/>
<property name="install.type" value="NATIVE_EXE_INSTALLATION"/>
</resources>
<installer-desc main-class="myself.webstart.Installer"/>
</jnlp>
And here the installer i wrote:
/*
* Created on 07.12.2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package myself.webstart;
import javax.jnlp.ExtensionInstallerService;
import javax.jnlp.ServiceManager;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
/**
* @author Arnold
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Installer {
String sourceFile = System.getProperty("url.to.file");
String destinationFile = System.getProperty("destination.file.name");
String jrePath = System.getProperty("sun.boot.library.path");
ExtensionInstallerService service = null;
String type;
BufferedWriter log = null;
public Installer(String type)
{
this.type = type;
}
public void install()
{
try
{
log = new BufferedWriter(new FileWriter(System.getProperty("user.home") + File.separator + "WebStartInstall.log"));
service = (ExtensionInstallerService) ServiceManager.lookup("javax.jnlp.ExtensionInstallerService");
if("NATIVE_EXE_INSTALLATION".equals(type))
{
String destinationPath = System.getProperty("destination.path.name");
log.write("Native EXE Installation\n");
log.write("Transfering file\n");
log.flush();
transferFile(sourceFile,destinationPath + File.separator + destinationFile);
log.write("Transfered file\n");
log.write("Installing file\n");
log.flush();
installFile(destinationPath + File.separator + destinationFile);
deleteFile(destinationPath + File.separator + destinationFile);
log.write("Installed file\n");
log.flush();
}
else if("COPY_FILE_INSTALLATION".equals(type))
{
String destinationPath = System.getProperty("destination.path.name");
log.write("Copy File Installation\n");
log.write("Transfering file\n");
log.flush();
transferFile(sourceFile,destinationPath + File.separator + destinationFile);
log.write("Transfered file\n");
log.flush();
}
else if("JRE_COPY_FILE_INSTALLATION".equals(type))
{
log.write("JRE Copy File Installation\n");
log.write("Transfering file\n");
log.flush();
transferFile(sourceFile,jrePath + File.separator + destinationFile);
log.write("Transfered file\n");
log.flush();
}
log.write("All done\n");
log.write("Deleting WebStartInstall.log\n");
log.flush();
log.close();
deleteFile(System.getProperty("user.home") + File.separator + "WebStartInstall.log");
service.installSucceeded(false);
System.exit(0);
} catch (Throwable th) {
System.out.println(th.getMessage());
if(log != null)
{
try
{
log.write(th.getMessage());
log.close();
}catch (IOException ioe) {}
}
if (service != null)
service.installFailed();
}
}
public static void main(String args[])
{
Installer i = new Installer(System.getProperty("install.type"));
i.install();
}
public void deleteFile(String file)
{
(new File(file)).delete();
}
public void installFile(String destinatinFile) throws IOException,InterruptedException
{
Process p = Runtime.getRuntime().exec(destinatinFile);
p.waitFor();
}
public void transferFile(String sourceFile,String destinationFile) throws IOException
{
BufferedInputStream in = null;
ByteArrayOutputStream baos = null;
FileOutputStream fos = null;
try
{
log.write("SourceFile: " + sourceFile + "\n");
log.write("DestinationFile: " + destinationFile + "\n");
log.flush();
URL hostURL = new URL(sourceFile);
in = new BufferedInputStream(hostURL.openStream());
baos = new ByteArrayOutputStream();
int readByte = 0;
byte[] buff = new byte[4096];
while( -1 != (readByte = in.read( buff )) )
{
baos.write( buff, 0, readByte );
}
File destFile = new File(destinationFile);
if(destFile.exists())
{
log.write("File allready exists\n");
log.write("SourceFileSize: " + baos.size() + "\n");
log.write("DestinationFileSize:" + destFile.length() + "\n");
log.flush();
if(destFile.length() != baos.size())
{
log.write("File has different size\n");
log.flush();
destFile.delete();
fos = new FileOutputStream(destFile);
fos.write(baos.toByteArray());
}
}
else
{
log.write("File doesn't exist. Write it\n");
log.flush();
fos = new FileOutputStream(destFile);
fos.write(baos.toByteArray());
}
}catch (IOException ioe)
{
try
{
log.write(ioe.getMessage());
log.flush();
}catch (IOException ioe2) {}
throw ioe;
}
finally
{
try
{
if(fos != null) fos.close();
if(baos != null) baos.close();
if(in != null) in.close();
}catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
}
Anyone any idea where my mistake could be ?
yours
arnold
[7416 byte] By [
arnold_mad] at [2007-11-25 18:24:42]

# 3
> Hi at all !
>
> I have a problem implementing an installer for
> webstart. The installation of my program is ok but if
> i want to finish the installer with
> service.installSucceeded(false); i think i get a
> endless loop and the WS says that there was a
> JNLPException: Launch File Error.
>
> Here my jnlp file:
>
> <?xml version="1.0" encoding="utf-8"?>
> <!-- JNLP File for JVision Application -->
> <jnlp
>spec="1.0+"
>codebase="http://myhost/mydir"
>href="jai.jnlp">
><information>
><title>Some Title</title>
><vendor>myself</vendor>
><description>Installer</description>
> <description kind="short">Software</description>
> ion>
><homepage href="http://java.sun.com"/>
><icon href="splash.jpg"/>
><offline-allowed/>
></information>
><security>
><all-permissions/>
></security>
><resources>
> <j2se version="1.4+" initial-heap-size="64m"
> 64m" max-heap-size="64m" java-vm-args="-Dhallo=hallo"
> />
><jar href="test.jar"/>
> <property name="url.to.file"
> ile"
> value="http://myhost/mydir/exe_file_that_should_be_ins
> talled.exe"/>
> <property name="destination.file.name"
> ame" value="exe_file_that_should_be_installed.exe"/>
> <property name="destination.path.name"
> ame"
> value="/path_where_my_installer_places_the_exe_file"/>
>
> <property name="install.type"
> ype" value="NATIVE_EXE_INSTALLATION"/>
></resources>
> <installer-desc
> esc main-class="myself.webstart.Installer"/>
> </jnlp>
>
>
> And here the installer i wrote:
>
> /*
> * Created on 07.12.2004
> *
> * To change the template for this generated file go
> o to
> * Window>Preferences>Java>Code Generation>Code and
> d Comments
> */
> package myself.webstart;
>
> import javax.jnlp.ExtensionInstallerService;
> import javax.jnlp.ServiceManager;
>
> import java.io.BufferedInputStream;
> import java.io.BufferedWriter;
> import java.io.ByteArrayOutputStream;
> import java.io.File;
> import java.io.FileOutputStream;
> import java.io.FileWriter;
> import java.io.IOException;
> import java.net.URL;
>
> /**
> * @author Arnold
> *
> * To change the template for this generated type
> e comment go to
> * Window>Preferences>Java>Code Generation>Code and
> d Comments
> */
> public class Installer {
> String sourceFile =
> le = System.getProperty("url.to.file");
> String destinationFile =
> le = System.getProperty("destination.file.name");
> String jrePath =
> th = System.getProperty("sun.boot.library.path");
>
>ExtensionInstallerService service = null;
>String type;
>BufferedWriter log = null;
>
>public Installer(String type)
>{
>this.type = type;
>}
>
>public void install()
>{
> try
> {
> log = new BufferedWriter(new
> edWriter(new
> FileWriter(System.getProperty("user.home") +
> File.separator + "WebStartInstall.log"));
> service = (ExtensionInstallerService)
> llerService)
> ServiceManager.lookup("javax.jnlp.ExtensionInstallerSe
> rvice");
>
>
>if("NATIVE_EXE_INSTALLATION".equals(type))
> {
> String destinationPath =
> estinationPath =
> System.getProperty("destination.path.name");
> log.write("Native EXE
> rite("Native EXE Installation\n");
>log.write("Transfering file\n");
>log.flush();
>
>
> transferFile(sourceFile,destinationPath
> estinationPath + File.separator + destinationFile);
>log.write("Transfered file\n");
>log.write("Installing file\n");
>log.flush();
> installFile(destinationPath +
> estinationPath + File.separator + destinationFile);
> deleteFile(destinationPath +
> estinationPath + File.separator + destinationFile);
>log.write("Installed file\n");
>log.flush();
> }
> else
> else
>else if("COPY_FILE_INSTALLATION".equals(type))
> {
> String destinationPath =
> estinationPath =
> System.getProperty("destination.path.name");
> log.write("Copy File
> write("Copy File Installation\n");
>log.write("Transfering file\n");
>log.flush();
>
>
> transferFile(sourceFile,destinationPath
> estinationPath + File.separator + destinationFile);
>log.write("Transfered file\n");
>log.flush();
> }
> else
> else
>else if("JRE_COPY_FILE_INSTALLATION".equals(type))
> {
> log.write("JRE Copy File
> e("JRE Copy File Installation\n");
>log.write("Transfering file\n");
>log.flush();
> transferFile(sourceFile,jrePath +
> ceFile,jrePath + File.separator + destinationFile);
>log.write("Transfered file\n");
>log.flush();
> }
> log.write("All done\n");
> log.write("Deleting
> te("Deleting WebStartInstall.log\n");
> log.flush();
> log.close();
>
> deleteFile(System.getProperty("user.home")
> user.home") + File.separator +
> "WebStartInstall.log");
> service.installSucceeded(false);
> System.exit(0);
> } catch (Throwable th) {
> System.out.println(th.getMessage());
> if(log != null)
> {
>try
>{
> log.write(th.getMessage());
> log.close();
>}catch (IOException ioe) {}
> }
> if (service != null)
>service.installFailed();
>
> }
>}
>
>public static void main(String args[])
>{
>
> Installer i = new
> i = new
> Installer(System.getProperty("install.type"));
> i.install();
>}
>
>public void deleteFile(String file)
>{
> (new File(file)).delete();
>}
>
> public void installFile(String destinatinFile)
> ile) throws IOException,InterruptedException
>{
> Process p =
> cess p = Runtime.getRuntime().exec(destinatinFile);
> p.waitFor();
>}
>
> public void transferFile(String sourceFile,String
> ring destinationFile) throws IOException
>{
> BufferedInputStream in = null;
> ByteArrayOutputStream baos = null;
> FileOutputStream fos = null;
> try
> {
> log.write("SourceFile: " + sourceFile +
> sourceFile + "\n");
> log.write("DestinationFile: " +
> ionFile: " + destinationFile + "\n");
> log.flush();
> URL hostURL = new URL(sourceFile);
> in = new
> in = new
> new BufferedInputStream(hostURL.openStream());
> baos = new ByteArrayOutputStream();
> int readByte = 0;
> byte[] buff = new byte[4096];
> while( -1 != (readByte = in.read( buff ))
> ead( buff )) )
> {
>baos.write( buff, 0, readByte );
> }
> File destFile = new
> stFile = new File(destinationFile);
> if(destFile.exists())
> {
>log.write("File allready exists\n");
> log.write("SourceFileSize: " +
> rceFileSize: " + baos.size() + "\n");
> log.write("DestinationFileSize:" +
> tionFileSize:" + destFile.length() + "\n");
>log.flush();
>if(destFile.length() != baos.size())
>{
> log.write("File has different
> ("File has different size\n");
> log.flush();
> destFile.delete();
> fos = new
>fos = new FileOutputStream(destFile);
> fos.write(baos.toByteArray());
>}
> }
> else
> {
> log.write("File doesn't exist. Write
> n't exist. Write it\n");
>log.flush();
> fos = new
>fos = new FileOutputStream(destFile);
>fos.write(baos.toByteArray());
> }
> }catch (IOException ioe)
> {
> try
> {
>log.write(ioe.getMessage());
>log.flush();
> }catch (IOException ioe2) {}
> throw ioe;
> }
> finally
> {
> try
> {
>if(fos != null) fos.close();
>if(baos != null) baos.close();
> if(in != null) in.close();
> ull) in.close();
> }catch (IOException ioe)
> {
>ioe.printStackTrace();
> }
> }
>
>}
>
> }
>
>
> Anyone any idea where my mistake could be ?
>
> yours
>
> arnold
as