J2PrinterWebStartTest Application --------------------------------- Brief Description : This sample demonstrates the use of the J2PrinterWorks class J2PrinterWebStart which enables J2PrinterWorks-based printing from Java Web Start applications. The following JNLP API is used by the Application : PrintService : This interface provides methods for access to JNLP printing functions. In particular, the methods showPageFormatDialog(PageFormat) and print(Pageable) are used to Java Web Start is launched automatically by browser when the user clicks on a link which is associated with JNLP file. It then downloads and caches the J2PrinterWebStartTest on the local client machine where browser is running. When invoked next time, this cached application is run without downloading and runs as fast as a traditionally installed application. By default applications are run in a protective environment (sandbox) with restricted access to local disk and network resources. Java Web Start only transfers JAR files from the Web server to the location determined by it on the client machine. To provide a simple and convenient packaging format of Applications, Java Web Start includes a servlet in the developer's pack. The name of the servlet is JnlpDownloadServlet and is packaged into the jnlp-servlet.jar file. This servlet eases deployment of application on any J2EE-complaint application server by packing a JNLP files and its associated resources in a Web Archive (.war) file. For more details on Java Web Start product and JNLP API, Please check out online docs at http://java.sun.com/products/javawebstart/developers.html Files : src - This directory has all the required source files : J2PrinterWebStartTestApplication.java lib - This directory has any .jar files required at the compilation time. class - This directory containing .class files is generated by the build process. war - This directory contains all the files required for deploying a web based application. Application related .jnlp files and .jar files are inside /app. build.xml - This file is used by Ant for building the application. It is kind of a Makefile for ant tool. Building & Deployment of Application : 1) In the file /war/app/J2PrinterWebStartTest.jnlp modify the tag "codebase=" to point to the location on your web server where J2PrinterWebStartTest will be installed, e.g. codebase="http://www.yourwebsite.com/J2PrinterWebStartTest/war/app" 2) Place a copy of J2PrinterWorks.jar into the folder /war/app. 3) Build .class and .jar files by running ant main in the parent directory where build.xml file resides. Ant is the Java-based build tool to use for building this application. For more information, check out http://jakarta.apache.org/. 4) To test, copy the resulting /war folder to the specified location on your web server, e.g. /J2PrinterWebStartTest/war Then in your favorite browser, navigate to the file http://www/yourwebsite.com/J2PrinterWebStartTest/war/index.html Click on the "Launch Application" link to start the application. Alternatively, you can double-click /war/app/J2PrinterWebStartTest.jnlp 5) To ease the deployment of application to on any J2EE-complaint server, all the resources required including .jnlp and jar files can be packed into a Web Archive (.war) file. To build .war file, run below command inside the war directory jar -cvf ../J2PrinterWebStartTestApplication.war . Then copy J2PrinterWebStartTestApplication.war file generated to the your web server directory. For examples, for a Tomcat server, copy the file J2PrinterWebStartTestApplication.war to the directory $TOMCAT_HOME/webapps and restart the web server.