Release Your Code — Chapter 17

Deployment options

  • Local — The entire application runs on the end-user’s computer, as a stand-alone, probably GUI, program, deployed as an executable JAR
  • Combination of local and remote — The application is distributed with a client portion running on the user’s local system, connected to a server where other parts of the application are running
  • Remote — The entire Java application runs on a server system, with the client accessing the system through some non-Java means, probably a web browser.


Packges can prevent name conflicts, but only if you choose a package name that’s guaranteed to he unique, The best way to do that is to preface your packages with your reverse domain name. You must put a class into a directory structure that matches the package hierarchy. The -d flag tells the complier, “Put the class into its package directory structure, using the class specified after the -d as the root directory. If the directories aren’t there, create them first and then put the class In the right place”.

Making an executable JAR with packages

  1. Make sure all of your class files are within the correct package structure, under the classes directory.
  2. Create a manifest.txt file that states which class has the main() method, and be sure to use the fully-qualified class name. Put the manifest tile into the classes directory.
  3. Run the Jar tool to create a JAR file that contains the package directories plus the manifest. The only thing you need to include is the ‘com’ directory, and the entire package (and all classes) .

Few more important points about deployment

  • Organize your project so that your source code and class files are not in the same directory.
  • A standard organization structure is to create a project directory, and then put a source directory and a classes directory inside the project directory.
  • Organizing your classes into packages prevents naming collisions with other classes. If you prepend your reverse domain name on to the front of a class name. To put a class in a package, put a package statement at the top of the source code file, before any import statements
  • To be in a package, a class must be in a directory structure that exactly matches the package structure. For a class, com.wickedlysmartFoo. the Foo class must be in a directory named wickedlysmart (which is in a directory named com)
  • To make your compiled class land in the correct package directory structure under the classes directory, use the -d compiler flag.
  • To run your code, cd to the classes directory, and give the fully-qualified name of your class.
  • You can bundle your classes into JAR (Java Archive) flies.
  • You can make an executable JAR file by putting a manifest into the JAR that states which class has the main() method. To create a manifest file, make a text file with an entry.
  • The entire package directory structure (and only the directories matching the package) must be immediately inside the JAR file.
  • To run an executable JAR file, type:


Java Web Start technology lets you deploy a stand-alone client application from the Web. Java Web Start includes a ‘helper app’ that must be installed on the client (along with Java). A Java Web Start (JWS) app has two pieces: an executable JAR and a .jnlp file. A.jnlp file is a simple XML document that describes your JWS application. It includes tags for specifying the name and location of the JAR, and the name of the class with the main() method. When a browser gets a .jnlp file from the server (because the user clicked on a link to the .jnlp file), the browser starts up the JWS helper app. The JWS helper app reads the .jnlp file and requests the executable JAR from the Web server. When the JWS gets the JAR, it invokes the main() method as specified inthe .jnlp file.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Upulie Handalage

Upulie Handalage

Everything in my point of view. Here for you to read on....