You can save a lot of time and effort by using java code that others have already written. Such code is usually available as external jar files. But how do you distribute that code with your program?

Check the License Agreement

Before you decide to use code that someone that else wrote, check the license agreement for that code. Are you allowed to use it for commercial use, or only for personal use? Are there any other restrictions?

Is the code bundled in a jar file? Are you required to keep that code in its original form? Are you allowed to redistribute the jar file?

If you are not allowed to redistribute an external jar file, do not use it in your program. You would not be able to sell your program, let alone run your program on any other computer, if you can’t redistribute the external jar file.

The rest of this article assumes the code you want to use is bundled in an external jar file which you are allowed to redistribute.

Build Your Jar File

If you’ve been working with Java, you will have learned that you can easily bundle all your code into a single executable jar file. But what do you do with the external jar files that your program requires?

I heard someone once suggest that you should unpack the external jar file, then bundle all its objects into your jar file. This would simplify distributing your program since you would then have everything in one jar file. However, this likely breaks the license agreement for your allowed use of the external jar file.

Instead, plan to distribute both your program’s jar file and the external jar file as separate jar files. For your program to still work, include the classpath to the required external jar file in the manifest of your program’s jar file.

Build an Install Wizard

How will your program’s jar file’s manifest know where the external jar file will be installed on the next computer? It’s easy if you control the installation of all the external jar files. You may do so by providing an install wizard for your program.

An install wizard can take any number of required resources for your program and install them where you want them on the user’s computer. Your install wizard should make sure that the external jar files are installed in expected locations relative to where your program’s jar file is installed. Then your programs jar file manifest should include classpaths to those expected relative locations of the required external jar files.


Read the license agreement of any external jar file that you want to use in your program. The safest way to package a redistributable external jar file with your program is to keep it in its original jar file form. Create an install wizard to install all your program’s required resources. By doing so, your program should be able to find and access all its required external jar files.

Related posts:

  1. Should You Create a Windows .EXE Wrapper for Java Programs?
  2. Create a Software License Agreement
  3. What is Software Deployment?
  4. How to Protect Your Software from Piracy
  5. Create a Readme.txt File

About the Author

Comments are closed.

More Do-It-Yourself Java Games

More Do-It-Yourself Java Games: An Introduction to Java Graphics and Event-Driven Programming is the second book of the Do-It-Yourself Java Games series. You'll learn to create windows and dialogs, to add buttons and input fields, to use images and drawings, and to respond to keyboard input and mouse clicks and drags. You'll create 10 more games including several puzzles, a dice game, a word game, and a card game.

This book assumes you either have an understanding of basic Java programming or you have read the first book, Do-It-Yourself Java Games: An Introduction to Java Computer Programming. Read more.

Do-It-Yourself Java Games

Do-It-Yourself Java Games: An Introduction to Java Computer Programming uses a unique "discovery learning" approach to teach computer programming: learn Java programming techniques more by doing Java programming than by reading about them.

Through extensive use of fill-in blanks, with easy one-click access to answers, you will be guided to write complete programs yourself, starting with the first lesson. You'll create puzzle and game programs like Choose An Adventure, Secret Code, Hangman, Crazy Eights, and many more, and discover how, when, and why Java programs are written the way they are. Read more

Step-by-Step Tutorial

Many of the tips, techniques, and tools discussed in this blog are demonstrated in a detailed step-by-step tutorial in the book, This Little Program Went to Market, by Annette Godtland.

The book takes a computer program through the entire process of creating, deploying and distributing a program, then selling and marketing it (or any other product) on the Internet. Read more.