Skip to main content

JAXBContext in applet doesn't work

Please note these forums are being decommissioned and use the new and improved forums at
2 replies [Last post]
Joined: 2013-09-17


my problem is to use JAXBContext.newInstance(myClassNyme.class) in my applet. My applet contains only one method. Input parameter is a string (with xml structure).
public String testApplet (final String data) throws JAXBException {
byte[] dataAsByte = data.getBytes();
GenericDataTransformer transformer = new GenericDataTransformer(); // my own class
Map dataMap = transformer.transform(dataAsByte);

ErrorMessage error = new ErrorMessage (); // Is only small class with @Xml annotations
JAXBContext jc = JAXBContext.newInstance(ErrorMessage.class);
System.out.println("context was created");
StringWriter writer = new StringWriter();
jc.createMarshaller().marshal(error, writer);
return writer.getBuffer().toString();
In java console I get "errorId:201" and that's it. No more messages, no more errors. Only network: cacheentry not found [URL: file:/C:/..../MyApplet.jar, Version: null].
In JUnit tests are all green
Html: APPLET CODE="applet.MyApplet.class" NAME="demoApplet"
style="width: 1px; height: 1px; float: left;">

With ant task I create a jar
"jar destfile="${build.dir}/${}" filesetmanifest="mergewithoutmain" duplicate="preserve">
attribute name="Built-By" value="${}"/>
attribute name="Main-Class" value="MyApplet"/>
attribute name="Class-Path" value="."/>
fileset dir="${basedir}/bin/classes" />
zipfileset excludes="META-INF/*.SF" src="lib/jaxb-api-2.2.5.jar"/>
zipfileset excludes="META-INF/*.SF" src="lib/jaxb-impl-2.2.5.jar"/>
zipfileset excludes="META-INF/*.SF" src="lib/generic_data-0.69.jar"/>
And sign it later:
target name="Sign jar files" description="Signs jars">
signjar alias="${keystore.alias}" keystore="${keystore.file}" storetype="${keystore.type}"
storepass="idexpert" sigalg="MD5withRSA" digestalg="SHA1" lazy="true" >
fileset dir="${build.dir}" >
include name="*.jar" />
ivy:publish settingsref="ref.settings.ivy" artifactspattern="${build.dir}/[artifact]-[revision]-[type].[ext]" resolver="shared" overwrite="true" />

Has anyone any idea? Applet, html and ant tasks are new areas for me. But i have to do that.

Please help !!

I am very thankful for your ideas.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2013-09-17

I have lost my problem. Solution was very simple.
JAXBContext.newInstance... has to access to file system. But java security doesn't allow to do that.
If you want to allow this access you have to add "privileged" block in your method and add your "access here JAXBContext.newInstance.." in this block. With Access controller it will be possible.
My solution :

public String testApplet (final String data) {
------ // the same code as above
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
JAXBContext jc = JAXBContext.newInstance(ErrorMessage.class);
System.out.println("context was created");
try {
System.out.println("context was successful created"); ;
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
return null;

More information you get in google. (search after Access controller)

Joined: 2006-05-05

Yes, you are right. To work with JAXB in applets or Java Web Start you have to grant JAXB some privileges.