Solved

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

Posted on 2003-11-20
7
2,791 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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