Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Unknown macro: {scrollbar}

First a little definition of what is the classpath : The class path tells to java tools and applications where to find third party and user classes or libraries. Most of the time it is a suite of path to your file system separated by a ; character.

The classpath is used for two steps : the compilation step (using javac command) and the running step (using java command).

The following shell extract shows you how to run the demo application with full features and specifying classpath elements. Therefore we didn't choose to specify each module libraries one by one, we just included the monolithic build. If you do not remember what I mean by the monolitic build and the module libraries, scroll back to Bundled distribution section.

# On Unix environments
$> cd /path/to/jfreereport/
$> java -classpath="jfreereport-.jar; lib/bsf-2.3.0.jar; lib/bsh-1.3.0.jar; lib/itext-1.4.jar; lib/jcommon-1.0.6.jar; lib/jcommon-xml-1.0.6.jar;
lib/libfonts-0.2.1.jar; lib/libloader-0.1.5.jar; lib/pixie-0.8.6.jar; lib/poi-3.0-alpha1-20050704.jar" org.jfree.report.demo.DemoFrontend

# On Windows environments
$> cd drive:\path\to\jfreereport\
$> java -classpath="jfreereport-.jar; lib\bsf-2.3.0.jar; lib\bsh-1.3.0.jar; lib\itext-1.4.jar; lib\jcommon-1.0.6.jar; lib\jcommon-xml-1.0.6.jar;
lib\libfonts-0.2.1.jar; lib\libloader-0.1.5.jar; lib\pixie-0.8.6.jar; lib\poi-3.0-alpha1-20050704.jar" org.jfree.report.demo.DemoFrontend

Running the demo application is meaningless but it shows you how to specify classpath entries, all you have to do in your applications is to append your libraries and classes and run your Main class instead of the demo one (the last part of previous java commands).
You can also run the demo application using the following statement:

$> java -jar jfreereport-demo-<version>.jar

The javac command is a little bit different because the -classpath option is named -cp and you don't have to specify the Main class to run. However, on newest version of Java JDK, java and javac commands have both options -classpath and -cp to specify the classpath.

Jar

A Jar file is a compressed archive containing a set of files, ressources and directories. If its manifest file contains an attribute named Main-Class, the attribute value (a canonical class name without the leading .class extension) will be launched at startup. Then it will be considered as an executable archive.

A manifest is a simple text file at a specified place in the archive (META-INF/MANIFEST.MF) used to set metadata describing the content of the archive.

As you saw on the previous section running the demo application with the java -jar command, we didn't specify the classpath entries at all. If you wonder why it is working, just have a look to the manifest of this jar archive. You can specify classpath entries in this file, here it is the manifest of the demo archive:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.2.2 (Sun Microsystems Inc.)
Main-Class: org.jfree.report.demo.DemoFrontend
Class-Path: jfreereport-core-0.8.7-10.jar jfreereport-parser-ext-0.8.7-10.jar
jfreereport-parser-simple-0.8.7-10.jar jfreereport-gui-csv-0.8.7-10.jar
jfreereport-gui-html-0.8.7-10.jar jfreereport-gui-pdf-0.8.7-10.jar
jfreereport-gui-plaintext-0.8.7-10.jar jfreereport-gui-print-0.8.7-10.jar
jfreereport-gui-xls-0.8.7-10.jar jfreereport-misc-bsf-0.8.7-10.jar
jfreereport-misc-beanshell-0.8.7-10.jar jfreereport-misc-configstore-filesystem-0.8.7-10.jar
jfreereport-misc-logging-base-0.8.7-10.jar jfreereport-output-xml-0.8.7-10.jar
jfreereport-gui-rtf-0.8.7-10.jar jfreereport-misc-survey-0.8.7-10.jar jfreereport-0.8.7-10.jar

If you are attentive you perhaps saw that not any libraries we saw on the previous section are present. It is because they are specified in the manifest of the included jfreereport-0.8.7-10.jar library:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.2.2 (Sun Microsystems Inc.)
Class-Path: lib/jcommon-1.0.6.jar lib/libloader-0.1.5.jar lib/libfonts-0.2.1.jar
lib/pixie-0.8.6.jar lib/bsf-2.3.0.jar lib/bsh-1.3.0.jar
lib/gnujaxp.jar lib/itext-1.4.jar lib/poi-3.0-alpha1-20050704.jar

TODO

these manifest define too much libraries, check if it is a problem or not.

You can now make your own executable archive to simplify the running step, however this solution can be restrictive if the manifest is hardcoded. Having shell scripts or Ant files could be a good idea in complex cases.
Here is a little reminder on how about to create a jar using the jar command:

$> jar cf <filename>.jar <files and directories to package>

Or this one if you want to specify a manifest file:

$> jar cfm <manifestfile> <filename>.jar <files and directories to package>

If you want more information about Jars you should perhaps have a look at Sun Jar tutorial page.

Using Eclipse IDE

There is no known issue or tip for using JFReport inside Eclipse IDE.
If you are developer and you want to work on 0.8 branch source code you will have to use the release-0_8_7-branch tag as you could see on this screenshot:

Otherwise you just need to include the required libraries to the classpath of your project. Right click on your project and Build Path then Configure Build Path:

Using IntelliJ IDE

The only one known issue using IntelliJ if you plan to be a JFreeReport developer (working with sources) is to add some file patterns in .... to be copied over the compile directory. The patterns to add are *.css and *.txt. Here is how it look like:

If you are developer and you want to work on 0.8 branch source code you will have to use the release-0_8_7-branch tag as you could see on this screenshot:

Otherwise you just need to include the required libraries to the classpath of your project...

Using Netbeans IDE

Using Borland IDE

Desactivate compile optimization features.

Webapp

There is nothing to say as I could see

Applet

A Java applet is small application served by a web server and running inside the client web browser virtual machine. You also have to know that to prevent illegal accesses from the applet to the client local file system, it must be signed to allow the client to verify its authenticity.

Before talking about how to sign applets, I will introduce the basis needed to make and run an applet:

An applet use the same technologies as a standard Java application (a JRE/JDK, libraries,...) but its main class must extends java.applet.Applet class. Within the web server it must be embedded into an HTML page as the following using the applet tag:

<applet code="my.package.MyApplet.class" width="200" height="200" codebase="applet/">
</applet>

The code attribute is used to define the canonical applet class with the appended .class suffix. The codebaseattribut is not mandatory (default set to ".", the calling HTML page) is used to define from where the ressources will be downloaded. As no external libraries are specified, we assume this server layout for the above example : <codebase>/my/package/MyApplet.class

If you need to specify libraries, you must do it using the archive attribute. The archive attribute is a coma separed list of jars also using the codebase attribute value to be retrieved:

<applet code="my.package.MyApplet.class" width="200" height="200" codebase="applet/"
archive="jfree/jfreereport-0.8.7-10.jar">
</applet>

If you need more informations about using applets you should have a look at Sun applet page.

If you planned to use Java applets and want to write and read to the client file system,... you have to package it into a jar and to sign it with a certificate. If you don't remember how to make a jar from your classes, go back to previous Jar section.
In the following sections we will show you only one maner to play with certificates using the java tools bundled with your JDK so there will be no need to setup any other 3rd party applications. This is certainly how you will work in a development environment using free certificates.
If you think you are too light about asymmetric key algorithms, signature, certificate,... you should perhaps read some papers about it to gain knowledge.

TODO

Have english ouputs.
PS: I didn't ever used applet signature and not much played with certificates, so if you see interesting commands or options to add to these sections...


Generate a certificate

As we don't have a certificate issued from a Certificate Authority (CA) we will generate one called self signed certificate. It is self signed because this certificate is in the mean time its CA.

c:\temp>"c:\Program Files\Java\jdk1.6.0\bin\keytool.exe" \-genkey \-keyalg rsa \-keystore MyKeystore.jks \-alias MyAlias
Tapez le mot de passe du Keystore : <pass1>
Ressaisissez le nouveau mot de passe : <pass1>
Quels sont vos prÚnom et nom ?
[Unknown] :  MyName
Quel est le nom de votre unitÚ organisationnelle ?
[Unknown] :  MyOrg
Quelle est le nom de votre organisation ?
[Unknown] :  MyCorp
Quel est le nom de votre ville de rÚsidence ?
[Unknown] :  MyCity
Quel est le nom de votre Útat ou province ?
[Unknown] :  MyCountry
Quel est le code de pays Ó deux lettres pour cette unitÚ ?
[Unknown] :  FR
Est-ce CN=MyName, OU=MyOrg, O=MyCorp, L=MyCity, ST=MyCountry, C=FR ?
[non] :  oui

SpÚcifiez le mot de passe de la clÚ pour <pass2>
(appuyez sur EntrÚe s'il s'agit du mot de passe du Keystore) :
Ressaisissez le nouveau mot de passe : <pass2>

The -genkey option is used to specicy it will be a self signed certificate and then a key par (private and public) must be genetated.
The -keyalg <algorithm> option is used to specify the type of the key pair, RSA is used because it is considered more secure.
The -keystore <name>.jksoption is used to specify a new file where the keys will be stored. If it is not specified the default java keystore will be used.
The -alias <name> option is used to specify to name the certificate un the keystore.
Now we have a valid certificate chain if you want to tune the certificate creation, have a look at Sun keytool page.

TODO

I don't know if the alias must be same when you have a chain.


Export a certificate 

As this self signed certificate is not considered as trusted because it is not issued from a known CA. You will then need to install the public key of your generated certificate in the browser.

c:\temp>"c:\Program Files\Java\jdk1.6.0\bin\keytool.exe" \-keystore MyKeystore.jks \-alias MyAlias \-export \-file MyCert.crt
Tapez le mot de passe du Keystore : <pass1>
Certificat enregistrÚ dans le fichier <MyCert.crt>

The -export option is used to specify that we want to extract the public key.
The -file <name> is used to give the public certificate filename.

Now we have extracted the public certificate chain.

TODO

I don't kow it it extracts the whole chain


Import a certificate

If you already have a certificate, you can import into the keystore.

c:\temp>"c:\Program Files\Java\jdk1.6.0\bin\keytool.exe" \-keystore MyKeystore.jks \-alias MyAlias \-import \-file YourCert.crt

Signing

Signing itself is realy simple, you just have to use that jarsigner command like the following:

c:\temp>"c:\Program Files\Java\jdk1.6.0\bin\jarsigner.exe" \-keystore MyKeystore.jks MyApplet.jar MyAlias
Enter Passphrase for keystore: <pass1>
Enter key password for MyAlias: <pass2>

Warning:
The signer certificate will expire within six months

TODO

I guess all jars must be signed and not only the applet one.

This command will append some files and attributes to the manifest of MyApplet.jar. It may be used more than once if you want your jar to be signed by multiple parties.

If you want to check the result type the following command:

c:\temp>"c:\Program Files\Java\jdk1.6.0\bin\jarsigner.exe" \-keystore MyKeystore.jks \-verify \-verbose \-certs MyApplet.jar
146106 Mon Dec 18 22:56:22 CET 2006 META-INF/MANIFEST.MF
145992 Tue Dec 19 21:27:30 CET 2006 META-INF/MYALIAS.SF
913 Tue Dec 19 21:27:30 CET 2006 META-INF/MYALIAS.RSA
0 Thu Nov 02 14:36:40 CET 2006 META-INF/
smk      298 Thu Nov 02 14:36:36 CET 2006 loader.properties

X.509, CN=MyName, OU=MyOrg, O=MyCorp, L=MyCity, ST=MyCountry, C=FR (myalias)
[certificate will expire on 19/03/07 21:25]

0 Thu Nov 02 14:36:12 CET 2006 org/
0 Thu Nov 02 14:36:12 CET 2006 org/jfree/
0 Thu Nov 02 14:36:36 CET 2006 org/jfree/report/
smk      886 Thu Nov 02 14:36:12 CET 2006 org/jfree/report/Anchor.class

X.509, CN=MyName, OU=MyOrg, O=MyCorp, L=MyCity, ST=MyCountry, C=FR (myalias)
[certificate will expire on 19/03/07 21:25]

smk      487 Thu Nov 02 14:36:12 CET 2006 org/jfree/report/AnchorElement.class

X.509, CN=MyName, OU=MyOrg, O=MyCorp, L=MyCity, ST=MyCountry, C=FR (myalias)
[certificate will expire on 19/03/07 21:25]

...

s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in keystore
i = at least one certificate was found in identity scope

jar verified.

Ant task

As we don't like much manual tasks we will ask Ant to the rescue.

Thomas, gimme your ant task!!!

  • No labels