Java Web Start and JAXB - problems with file


I am new to JWS, and am experiencing difficulties with the jnlp file. I am using JAXB to read an xml file in my application. I am having problems figuring out how to enter this file in the <resources> part of the jnlp file.

Here is part of the servlet that defines the jnlp file, with all the jar files needed. I need to add the file somehow...?

out.println (" <resources>");
out.println (" <j2se version=\"1.4+\"");
out.println (" initial-heap-size=\"256m\"");
out.println (" max-heap-size=\"512m\"/>");
out.println (" <jar href=\"lib/myApplication.jar\"/>");
out.println (" <jar href=\"lib/jaxb-api.jar\"/>");
out.println (" <jar href=\"lib/jaxb-xjc.jar\"/>");
out.println (" <jar href=\"lib/jaxb-libs.jar\"/>");
out.println (" <jar href=\"lib/jaxb-impl.jar\"/>");
out.println (" <jar href=\"lib/jaxp-api.jar\"/>");
out.println (" <jar href=\"lib/xercesImpl.jar\"/>");
out.println (" <jar href=\"lib/xalan.jar\"/>");
out.println (" <jar href=\"lib/sax.jar\"/>");
out.println (" <jar href=\"lib/dom.jar\"/>");
out.println (" <jar href=\"lib/jax-qname.jar\"/>");
out.println (" <jar href=\"lib/namespace.jar\"/>");
out.println (" <jar href=\"lib/relaxngDatatype.jar\"/>");
out.println (" </resources>");

Please help, this is quite urgent!
Thankful for any help!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could add the file to your myApplication.jar, couldn't you?
MarteJAuthor Commented:
Yes, I have already tried that, but I get an error:


javax.xml.bind.JAXBException: Unable to locate for package first_dir.second_dir.jaxb_dir

The error is caught for the following code in the class that reads the xml file:


JAXBContext jc = JAXBContext.newInstance("first_dir.second_dir.jaxb_dir");


I probably stated the question wrong, but I thought the error is caused because I had not placed the file correctly in the jnlp file.
The JAXB code is compiled to first_dir.second_dir.jaxb_dir, where the jaxb.propterties file is created.

I cannot figure out why the file is not found. Any suggestions? Thanks!
MarteJAuthor Commented:
I forgot to say that it works when the applications is run from command line, not through Java Web Start.

Greatful for any help!
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

>I thought the error is caused because I had not placed the file correctly in the jnlp file.
>The JAXB code is compiled to first_dir.second_dir.jaxb_dir, where the jaxb.propterties file is created.

You don't have to do anything in the jnlp file about the file.  

Are you sure the file is in the myApplication.jar file and in the proper subdirectory, i.e., first_dir.second_dir.jaxb_dir?

Maybe I'm just amusing myself.

Here's a simple experiment to try:

A jnlp file (call it app.jnlp):
<?xml version="1.0" encoding="UTF-8"?>
<jnlp codebase="$$codebase">
         <title>Example 1</title>
         <description>just an example</description>
       <j2se version="1.4+"/>
       <jar href="lib/testjaxb.jar"/>
       <jar href="lib/jaxb-api.jar"/>
       <jar href="lib/jaxb-xjc.jar"/>
       <jar href="lib/jaxb-libs.jar"/>
       <jar href="lib/jaxb-impl.jar"/>
       <jar href="lib/jaxp-api.jar"/>
  <application-desc main-class="org.example.jaxb.TestJaxb"/>

A java class:
package org.example.jaxb;

import javax.xml.bind.*;

public class TestJaxb {
  static public void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance( "org.example.jaxb" );

an html file:
<a href="app.jnlp">Launch</a>

The javac command:
javac org\example\jaxb\

Well, I've got the jaxb libs in my jre/endorsed dir so I don't include them in the compile or execute commands.
The java commandline:
java -cp . org.example.jaxb.TestJaxb

This results in an exception
Exception in thread "main" javax.xml.bind.JAXBException: in package
org.example.jaxb does not contain the javax.xml.bind.context.factory property.
But that's because I've got nothing in the properties file.  But it finds it.

I jarred it up as follows:
jar cf testjaxb.jar org\example\jaxb\TestJaxb.class org\example\jaxb\

my deployment structure:

  index.html app.jnlp
  testjaxb.jar jaxb-api.jar and-abuncha-other-jars

When I connect to this page and click on launch, the application fails with the same exception as before.  So it's reading the properties file, at least.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarteJAuthor Commented:
Sorry for a very late reply, but I have been struggeling with this some time.
First of all I found out that I was not running the latest version of JWSDP, but jwsdp-1.2. I have downloaded jwsdp-1.3 now, but my application will gives me the same exception running with Java Web Start. It works fine when running it as an ordinary application.

I tried out your great example, thank you so much! It took some time to merge your example into my deployment, but I got it to work (the example, that is). I will have to look more into my real application to find the problem.

Again - thank you for taking the time to test this for me and submitting the code!!! I learnt a lot!

I am working with jaxb-1.0-beta on Win2000.

My JAXB application works just fine when my class files are in the appropriate folders in the file system.

I then wrap up my application in a jar file which includes the file com\mycompany\mypackage\

Now I get the infamous exception:
javax.xml.bind.JAXBException: Unable to locate for package com.mycompany.mypackage

I have learned the following through Web Surfing.

 - jaxb-1.0-beta has a bug.
 - This bug is fixed, but not released.

So I did not bother to upgrade to the latest release of JAXB.

So let's fix it.  Dig deep enough and the problem is found at the following line.
   InputStream is = classLoader.getResourceAsStream( propFileName );

propFileName contains "com\ncems\premis\xml\jaxb\"

This works just fine for finding the file in the Win2000 file system.  It fails to find the file in the jar file.

If I change the propFileName String to contain "com/ncems/premis/xml/jaxb/", then it can find the file in both the jar file and the Win2000 file system.

Time for a kluge.

The last point in my code, before hitting the exception, is the following line.
   JAXBContext jaxb = JAXBContext.newInstance("com.mycompany.mypackage");

newInstance comes in two flavors.  The other one lets me specify the ClassLoader to be used to find the file.  So, I changed the above line to the following.
   JAXBContext jaxb = JAXBContext.newInstance("com.mycompany.mypackage", new JAXBClassLoader());

Now I just need a well behaved definition for JAXBClassLoader.  The following kluge works for me.


public class JAXBClassLoader extends ClassLoader {

  private ClassLoader d_classLoader = Thread.currentThread().getContextClassLoader();

  public InputStream getResourceAsStream(String name) {
    if (name.endsWith("")) {
      name = name.replace('\\','/');
    return d_classLoader.getResourceAsStream(name);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.