Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3007
  • Last Modified:

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

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
MarteJ
Asked:
MarteJ
  • 3
  • 3
1 Solution
 
savalouCommented:
You could add the file to your myApplication.jar, couldn't you?
0
 
MarteJAuthor Commented:
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
 
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!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
savalouCommented:
>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
 
savalouCommented:
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
 
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!
0
 
hwmederCommented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now