You can run, test and adapt all the examples for this Wiki using the Eclipse development platform. You create a new workspace (in my case, this workspace is located in directory C:/itext-wiki on a Windows machine), and create a project examples (located in C:/itext-wiki/examples). In this directory, you’ll have some important subdirectories:
The source code directory is named src, and it will contain all the *.java classes you’re using, organized in packages: com.lowagie.util, com.lowagie.database, com.lowagie.filmfestival, and so forth.
It is important that you select this directory as one of the Source folders on build path in the Java Build Path entry of your project’s properties dialog.
When defining the source folder for your examples project in Eclipse, make sure the source code and the compiled class files are in separate directories. Eclipse will create a directory bin automatically.
You can check this in the Source tab of the Java Build Path dialog: the default output folder will be examples/bin (in my case referring to C:/itext-wiki/examples/bin/).
The external libraries directory is a map you should create yourself. In my case, it’s C:/itext-wiki/examples/lib/. You’ll need at least the iText.jar in it. For examples that need a database, you’ll also need the hsqldb.jar.
In your project, you need to add these jars in the Libraries tab of the Java Build Path dialog.
For reasons of convenience, I am using hsqldb as database in the examples. Because the samples on this site are all small standalone examples, you’ll be using hsqldb in standalone mode. This mode runs the database engine as part of your application program in the same Java Virtual Machine. The database files will be located in directory databases.
For those who want to try the examples on their own database system: I am also providing the SQL scripts in directory sqlscripts.
For some examples, you’ll need resources that are not stored in the database, but as a file on the file system. You’ll find these resouces (images, XML files,...) in a separate directory resources.
We’ll also store all the results of our examples (mostly PDF files) in a separate directory, more specifically in the results directory.
I wouldn’t advise it, but it is possible to change the location of all these directories. Most of them are stored in the file examples.properties that can be found in the root directory of your examples (that’s C:/itext-wiki/examples on my system). The entries of this file are loaded statically into the object com.lowagie.util.Examples, more specifically into its member variable properties. Whenever a path to a resource, a database file,... is needed, you’ll see something like this appear in the source code:
String path = Examples.properties.getProperty("sqlscripts", "sqlscripts/");
The code above tries to get the value stored in the examples.properties file (./sqlscripts/), but if it doesn’t find it, it uses sqlscripts/ instead (which has the same effect).
You can also use the examples.properties file for other purposes, for instance to use other values for the username and password:
/** Username for this database */ public static String USERNAME = Examples.properties.getProperty("username", "sa"); /** Password for this database */ public static String PASSWORD = Examples.properties.getProperty("password", "");
It goes without saying that you’ll have to create the database from scratch using these new credentials if you don’t want to work with username=sa and password=[empty].
Setting up the environment for the examples presented on this wiki should be simple, especially if you are using Eclipse as your development platform, and if you don’t change the directory structure presented on http://itext.ugent.be/wiki/examples/.