Solved

Java Web Start and JAXB - problems with jaxb.properties file

Posted on 2003-11-20
7
2,632 Views
Last Modified: 2012-06-27
Hi,

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 jaxb.properties 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!!
0
Comment
Question by:MarteJ
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:savalou
ID: 9787172
You could add the file to your myApplication.jar, couldn't you?
0
 

Author Comment

by:MarteJ
ID: 9787615
Yes, I have already tried that, but I get an error:

---

javax.xml.bind.JAXBException: Unable to locate jaxb.properties 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 jaxb.properties 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!
0
 

Author Comment

by:MarteJ
ID: 9787868
I forgot to say that it works when the applications is run from command line, not through Java Web Start.

Greatful for any help!
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 3

Expert Comment

by:savalou
ID: 9788726
>I thought the error is caused because I had not placed the jaxb.properties 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 jaxb.properties file.  

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

0
 
LVL 3

Accepted Solution

by:
savalou earned 500 total points
ID: 9789410
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">
  <information>
         <title>Example 1</title>
         <vendor>Myself</vendor>
         <description>just an example</description>
     </information>
     <resources>
       <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"/>
     </resources>
  <application-desc main-class="org.example.jaxb.TestJaxb"/>
</jnlp>

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:
<html>
<head></head>
<a href="app.jnlp">Launch</a>
<body></body>
</html>

The javac command:
javac org\example\jaxb\TestJaxb.java

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: jaxb.properties 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\jaxb.properties

my deployment structure:

/testjaxb
  index.html app.jnlp
/testjaxb/lib
  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.
0
 

Author Comment

by:MarteJ
ID: 9816697
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!
0
 

Expert Comment

by:hwmeder
ID: 10017617
Finding jaxb.properties

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\jaxb.properties.

Now I get the infamous exception:
javax.xml.bind.JAXBException: Unable to locate jaxb.properties 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\jaxb.properties"

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

If I change the propFileName String to contain "com/ncems/premis/xml/jaxb/jaxb.properties", then it can find the jaxb.properties 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 jaxb.properties 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.

import java.io.InputStream;
import java.net.URL;

public class JAXBClassLoader extends ClassLoader {

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

  public InputStream getResourceAsStream(String name) {
    if (name.endsWith("jaxb.properties")) {
      name = name.replace('\\','/');
    }
    return d_classLoader.getResourceAsStream(name);
  }
}
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now