wiki:JavaApps

Using BOINC with Java applications

How to run a java app with BOINC - a simple wrapper approach without using BOINC api

(for windows hosts only, because of jsmooth)

You need:

  • The wrapper application from boinc/samples. Make sure it's the latest version.
  • The boinc_zip library
  • A Java Virtual Machine to distribute with your science application. On a windows PC with Java installed, you'll usually find it e.g. in c:\Program Files\Java\jre<version>
  • Jsmooth to generate a launcher. Use version 0.9.9-6, since version 0.9.9-7 has a bug: every time it runs, a (small) jar file is left behind in the temp directory of the users machine.

What needs to be done:

  • Create a launcher for your executable jar file using JSmooth (Use the JSmooth option to just create a launcher, don't wrap everything into one exe file. otherwise JSmooth extracts the whole app into a temp dir every time the app runs, and the files are only deleted on reboot).
  • Use the wrapper to start the launcher you created.
  • JSmooth has a lot of options, and some of them are important for everything to run smoothly, so it's probably best to test the application at this stage in an environment where you know that all computers have Java installed.
  • We recommend the a configuration similar to this:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <jsmoothproject>
        <JVMSearchPath>registry</JVMSearchPath>
        <JVMSearchPath>javahome</JVMSearchPath>
        <JVMSearchPath>jrepath</JVMSearchPath>
        <JVMSearchPath>jdkpath</JVMSearchPath>
        <JVMSearchPath>exepath</JVMSearchPath>
        <JVMSearchPath>jview</JVMSearchPath>
        <bundledJVMPath>jre</bundledJVMPath>
        <classPath>YourJavaApplication.jar</classPath>
        <embeddedJar>false</embeddedJar>
        <executableName>YourLauncherApp.exe</executableName>
        <initialMemoryHeap>-1</initialMemoryHeap>
        <mainClassName>MainClassOfYourJavaApp</mainClassName>
        <maximumMemoryHeap>-1</maximumMemoryHeap>
        <maximumVersion></maximumVersion>
        <minimumVersion></minimumVersion>
        <skeletonName>Autodownload Wrapper</skeletonName>
        <skeletonProperties>
            <key>Message</key>
            <value><![CDATA[
    
            Message to users when finding a jvm fails
    
            ]]>
            </value>
        </skeletonProperties>
        <skeletonProperties>
            <key>DownloadURL</key>
            <value>http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab</value>
        </skeletonProperties>
        <skeletonProperties>
            <key>SingleProcess</key>
            <value>1</value>
        </skeletonProperties>
        <skeletonProperties>
            <key>Debug</key>
            <value>0</value>
        </skeletonProperties>
    </jsmoothproject>
    
  • Make a copy of the folder containing the jvm. Recursively remove all write protections on files and folders. This is very important! If you don't do that, the BOINC client will not be able to delete it after completing the workunit and fill up the whole harddisk very quickly.
  • Read the license information files inside the jvm. One of them contains a list of files which can be deleted to make the jvm a bit smaller. (What you want to remove is application-specific, but you may find this a useful starting point: http://www.malariacontrol.net/download/jre.zip). Then zip that folder to e.g. "jre.zip" and add it to your application.

  • Use boinc_zip from within the wrapper application by adding something like this to wrapper.cpp:
    	string inzip;
    	boinc_resolve_filename_s("jre.zip",inzip);
    	string outzip("jre");
    	
    	if(boinc_zip(UNZIP_IT, inzip, outzip))
    		fprintf(stderr, "unzipping failed\n");
    
  • Make sure the jmooth launcher looks for an "embedded" jvm in the folder that you unzip to from the wrapper.
  • That's it. Since it is not possible to use the BOINC API from within the Java application, it would be polite to let the users opt out of running your application, e.g. if they have a lot of suspend/resume events.
Last modified 4 years ago Last modified on 12/19/12 14:14:28