axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gavin Ellis <gavin.el...@mfuse.com>
Subject RE: JAXBException..... doesn't contain ObjectFactory.class or jaxb.index
Date Thu, 04 Jun 2009 15:41:41 GMT
Ok, looks like jaxb was complaining about the default class loader used to look up the context
ObjectFactory. By default inside

JAXBContext.newInstance(String contextPath)

Initialises the class loader using

Thread.currentThread().getContextClassLoader()

i.e.

public static JAXBContext newInstance( String contextPath )
        throws JAXBException {

        //return newInstance( contextPath, JAXBContext.class.getClassLoader() );
        return newInstance( contextPath, Thread.currentThread().getContextClassLoader() );
    }


For some reason tomcat/axis doesn't like this and you won't find the ObjectFactory on the
classpath.

This is remedied by getting a handle on the classloader in the following way:

JAXBContext jaxbReqContext = JAXBContext.newInstance(requestContext, this.getClass().getClassLoader());

Thanks for the responses to my initial post.

Gavin Ellis
Free Man


From: Martin Gainty [mailto:mgainty@hotmail.com]
Sent: 03 June 2009 19:09
To: axis-user@ws.apache.org
Subject: RE: JAXBException..... doesn't contain ObjectFactory.class or jaxb.index

here is an example of a constructed jaxws artifact
cd $AXIS2_HOME/samples/jaxws-addressbook

//To build this sample, execute the following maven command:
mvn clean install

//This will do the following:
//- Generate the JAXB artifacts (in target/schema)
//- Compile the service implementation classes (in target/classes), including the JAXB //artifacts,
//  and create a JAR containing those classes (target/jaxws-addressbook-//SNAPSHOT.jar)
//- Compile the Dispatch client classes (in target/classes) and create a JAR //containing
those classes
//  (target/jaxws-addressbook-SNAPSHOT-Client.jar).

//Step 1: Generate JAXB artifacts from simple schema
//==================================================
//The file src/AddressBookEntry.xsd describes a simple AddressBookEntry object with //the
following fields:
//    String firstName;
.......

//The following JAXB artifacts are generated in the target/schema/src directory when //the
sample is built
//org\apache\axis2\jaxws\addressbook\AddressBookEntry.java
//org\apache\axis2\jaxws\addressbook\ObjectFactory.java
//org\apache\axis2\jaxws\addressbook\package-info.java

//These files will be compiled into target/classes as part of the build. here is proof
[INFO] [antrun:run {execution: gen-sources}]
[INFO] Executing tasks
[mkdir] Created dir: F:\AXIS\axis2-1.4\samples\jaxws-addressbook\target\schema
[mkdir] Created dir: F:\AXIS\axis2-1.4\samples\jaxws-addressbook\target\schema\src
[mkdir] Created dir: F:\AXIS\axis2-1.4\samples\jaxws-addressbook\target\schema\classes
     [echo] Generating java from echo.xsd
     [java] parsing a schema...
     [java] compiling a schema...
     [java] org\apache\axis2\jaxws\addressbook\AddressBookEntry.java
     [java] org\apache\axis2\jaxws\addressbook\ObjectFactory.java
     [java] org\apache\axis2\jaxws\addressbook\package-info.java
[INFO] Executed tasks

afterwards my Directory of $AXIS2_HOME\samples\jaxws-addressbook\target\classes\org\apa
che\axis2\jaxws\addressbook contains

06/03/2009  01:16 PM               372 AddressBook.class
06/03/2009  01:16 PM             3,469 AddressBookClient.class
06/03/2009  01:16 PM             1,962 AddressBookEntry.class
06/03/2009  01:16 PM             1,873 AddressBookImpl.class
06/03/2009  01:16 PM             1,525 ObjectFactory.class

pom.xml contained within <execution>
                       <id>gen-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <tasks>
                                <property name="schema.output.base.dir" value="target/schema"/>
                                <property name="schema.generated.src.dir" value="${schema.output.base.dir}/src"/>
                                <property name="schema.generated.classes.dir"
                                          value="${schema.output.base.dir}/classes"/>
                                <!-- make the dirs -->
                                <mkdir dir="${schema.output.base.dir}"/>
                                <mkdir dir="${schema.generated.src.dir}"/>
                                <mkdir dir="${schema.generated.classes.dir}"/>
                                <!-- Run JAXB schema compiler with designated schemas -->
                                <echo>Generating java from echo.xsd</echo>
                                <java classname="com.sun.tools.xjc.Driver" fork="true">
                                    <classpath refid="maven.runtime.classpath"/>
                                    <classpath location="${compiled.classes.dir}"/>
                                    <arg line="-d ${schema.generated.src.dir} src/AddressBookEntry.xsd"/>
                                </java>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>

//also if well at the pom.xml in modules/jaxbri we see the generate-test-sources phase will
create required classes
                    <execution>
                        <id>gen-ts</id>
                        <phase>generate-test-sources</phase>
                        <configuration>
                            <tasks>
                                <property name="axis2.home" value="${basedir}/target"/>
                                <property name="maven.class.path" refid="maven.runtime.classpath"/>
                                <!-- Theres got to be a better way to do this -->
                                <property name="schema.source.dir" value="test-resources/xsd"/>
                                <property name="wsdl.source.dir" value="test-resources/wsdl"/>
                                <property name="schema.output.base.dir" value="target/schema"/>
                                <property name="schema.generated.src.dir" value="${schema.output.base.dir}/src"/>
                                <property name="schema.generated.classes.dir"
                                          value="${schema.output.base.dir}/classes"/>
                                <!-- make the dirs -->
                                <mkdir dir="${schema.output.base.dir}"/>
                                <mkdir dir="${schema.generated.src.dir}"/>
                                <mkdir dir="${schema.generated.classes.dir}"/>
                                <!-- Run JAXB schema compiler with designated schemas -->
                                <echo>Generating JAX-B classes for DocLitBareService
test</echo>
                                <java classname="com.sun.tools.xjc.Driver" fork="true">
                                    <classpath refid="maven.runtime.classpath"/>
                                    <classpath location="${compiled.classes.dir}"/>
                                    <arg line="-d ${schema.generated.src.dir} -quiet -wsdl
${wsdl.source.dir}/DocLitBareService.wsdl"/>
                                </java>
..........
                                <ant dir="target/wsdl/Test01"/>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>

F:\AXIS\axis2-1.4\modules\jaxbri>mvn -e generate-test-sources
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Apache Axis2 - JAXB-RI Data Binding
[INFO]    task-segment: [generate-test-sources]
[INFO] ------------------------------------------------------------------------
[INFO] artifact org.codehaus.mojo:build-helper-maven-plugin: checking for update
s from ws-zones
[INFO] [resources:resources]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] skip non existing resourceDirectory F:\AXIS\axis2-1.4\modules\jaxbri\conf

[INFO] Copying 1 resource
[INFO] [compiler:compile]
[INFO] Compiling 3 source files to F:\AXIS\axis2-1.4\modules\jaxbri\target\class
es
[INFO] [antrun:run {execution: gen-ts}]
[INFO] Executing tasks
    [mkdir] Created dir: F:\AXIS\axis2-1.4\modules\jaxbri\target\schema
    [mkdir] Created dir: F:\AXIS\axis2-1.4\modules\jaxbri\target\schema\src
    [mkdir] Created dir: F:\AXIS\axis2-1.4\modules\jaxbri\target\schema\classes
     [echo] Generating JAX-B classes for DocLitBareService test
     [echo] Generating Service / Service Client for Test01 test
     [java] Retrieving document at 'test-resources/wsdl/Test01.wsdl'.

//proof that sources were generated in the correct folder
 Directory of F:\AXIS\axis2-1.4\modules\jaxbri\target\wsdl\Test01\src\com\foo\xm
lns\axis2\test01

06/03/2009  01:28 PM             1,720 Add.java
06/03/2009  01:28 PM             1,669 ObjectFactory.java
06/03/2009  01:28 PM               192 package-info.java

//command line tool used to create these class is called wsimport here is the doc
     You can use the JAX-WS tool, wsimport, to process a
      WSDL file and generate portable Java artifacts that are used
      to create a Web service. The portable Java artifacts created
      using the wsimport tool are:

        Service endpoint interface (SEI)

        Service class

        Exception class that is mapped from the
        <code>wsdl:fault</code> class (if any)

        Java Architecture for XML Binding (JAXB) generated type
        values which are Java classes mapped from XML schema
        types

Run the wsimport -keep -verbose wsdl_URL
command to generate the portable artifacts. The
-keep option tells the tool not to delete the generated files, and the
-verbose option tells it to list the files that were created.
The ObjectFactory.java file that is created contains factory methods for each Java content
interface
and Java element interface generated in the associated package. The
package-info.java file takes the targetNamespace value
and creates the directory structure.

http://java.sun.com/javase/6/docs/technotes/tools/share/wsimport.html

conclusion:execute maven task which calls generate-test-sources and generates classes from
com.sun.tools.xjc.Driver

after that you would only need to compile with javac
build your service aar
then deploy to axis2

HTH
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten
wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist
unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet
keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen
wir keine Haftung fuer den Inhalt uebernehmen.

Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.




________________________________
From: gavin.ellis@mfuse.com
To: axis-user@ws.apache.org
Date: Wed, 3 Jun 2009 17:33:09 +0100
Subject: RE: JAXBException..... doesn't contain ObjectFactory.class or jaxb.index
As I understand it the jaxb.index file is not relevant in this scenario, or at least doesn't
exist in the standalone version that works. So in this case, is the problem when trying to
load ObjectFactory.class caused by a similar issue?

Gavin Ellis

From: Martin Gainty [mailto:mgainty@hotmail.com]
Sent: 03 June 2009 17:03
To: Gavin Ellis
Subject: RE: JAXBException..... doesn't contain ObjectFactory.class or jaxb.index


--a definite bug



The javadoc for JAXBContext.newInstance(String,ClassLoader) needs to more clearly specify
the expected format of the class names listed in "jaxb.index".



Right now, the RI is expecting classnames of the form: "ClassName.class"



The attached test case is failing because the index file contains: "fully.qualified.ClassName"



also



"modify the RI to work for "ClassName" rather than "ClassName.class"







specifying classname without package. prefix or .class suffix is the fix
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6314008

so it seems the workaround is to use "ClassName.class" and not PackageName.ClassName.class
(patch was supposed to be applied in JAXB 2)

does this help?
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten
wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist
unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet
keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen
wir keine Haftung fuer den Inhalt uebernehmen.

Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.



________________________________
From: gavin.ellis@mfuse.com
To: axis-user@ws.apache.org
Date: Wed, 3 Jun 2009 15:41:59 +0100
Subject: JAXBException..... doesn't contain ObjectFactory.class or jaxb.index
I'm currently experiencing an issue when trying to initialise a jaxb context inside a jar
dependency inside an axis aar module i.e.

axis.war\WEB-INF\services\myService.aar!\lib\myDependency.jar!\com.mycompany.MyClass.class

I have tested this lib standalone and everything works fine, the jaxb context is initialised
as expected. However when it is referenced inside an aar module inside axis, then the following
exception is thrown:

javax.xml.bind.JAXBException: "com.mfuse.novo.transactions.adapter.orbis.oxi.generated" doesnt
contain ObjectFactory.class or jaxb.index
                at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:183)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:597)
                at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
                at javax.xml.bind.ContextFinder.find(ContextFinder.java:277)
                at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
                at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
                at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
                at com.mfuse.novo.adapters.connections.jaxb.JaxbConnectionImpl.initMarshaller(JaxbConnectionImpl.java:70)
                ... 34 more

I have debugged into the code and attempted to load ObjectFactory manually and it appears
to be on the classpath. I've also inspected the package inside the jar and it contains ObjectFactory.class.

I noticed that axis WEB-INF/lib already contains an earlier version of jaxb, which I thought
might possibly be causing a conflict here so tried swapping these out for the ones that I
used in the lib, but this made no difference.

Has anyone else experienced a similar issue?

Regards,

Gavin Ellis




________________________________
The information contained in this message is confidential and is intended for the addressee
only. Any unauthorised dissemination or copying or use or disclosure of information contained
herein is strictly prohibited and may be illegal. If you are not the named or intended recipient
please notify us immediately by telephone (+44 207 154 2070) or return e-mail. We have installed
active virus software but do not accept liability or responsibility for the security or reliability
of transmission or for any virus transmitted; as such you should carry out your own virus
checks before opening any attachment.
Mfuse Limited registered in England and Wales, company number 04468412. Registered Office:
3rd Floor, Mitre House, 177 Regent Street, London W1B 4JN
________________________________
Windows Live(tm) SkyDrive(tm): Get 25 GB of free online storage. Get it on your BlackBerry
or iPhone.<http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009>

________________________________
The information contained in this message is confidential and is intended for the addressee
only. Any unauthorised dissemination or copying or use or disclosure of information contained
herein is strictly prohibited and may be illegal. If you are not the named or intended recipient
please notify us immediately by telephone (+44 207 154 2070) or return e-mail. We have installed
active virus software but do not accept liability or responsibility for the security or reliability
of transmission or for any virus transmitted; as such you should carry out your own virus
checks before opening any attachment.
Mfuse Limited registered in England and Wales, company number 04468412. Registered Office:
3rd Floor, Mitre House, 177 Regent Street, London W1B 4JN
________________________________
Insert movie times and more without leaving Hotmail®. See how.<http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd_062009>

________________________________
The information contained in this message is confidential and is intended for the addressee
only. Any unauthorised dissemination or copying or use or disclosure of information contained
herein is strictly prohibited and may be illegal. If you are not the named or intended recipient
please notify us immediately by telephone (+44 207 154 2070) or return e-mail. We have installed
active virus software but do not accept liability or responsibility for the security or reliability
of transmission or for any virus transmitted; as such you should carry out your own virus
checks before opening any attachment.
Mfuse Limited registered in England and Wales, company number 04468412. Registered Office:
3rd Floor, Mitre House, 177 Regent Street, London W1B 4JN

Mime
View raw message