Error package javax xml bind annotation does not exist

I'm using CXF 2.4.2 and DynamicClientFactory in OC4J 10.1.3.4 (and 10.1.3.5). When DynamicClientFactory tries to compile the dinamycally g...

I’m using CXF 2.4.2 and DynamicClientFactory in OC4J 10.1.3.4 (and 10.1.3.5).

When DynamicClientFactory tries to compile the dinamycally generated Java sources, the following errors occur:

INFO: Created classes: XXX, YYY, …
 C:..org.apache.cxf.endpoint.dynamic.DynamicClientFactory@12f767-1314800629516-src…XXX.java:4: package javax.xml.bind.annotation does not exist
 import javax.xml.bind.annotation.XmlAccessType;
                                  ^
 C:..org.apache.cxf.endpoint.dynamic.DynamicClientFactory@12f767-1314800629516-src…YYY.java:4: package javax.xml.bind.annotation does not exist
 import javax.xml.bind.annotation.XmlAccessType;
                                  ^

I dug into the DynamicClientFactory code and found that setupClasspath, the method which sets the Classpath for the javac compilation iterates between the supplied ClassLoader (or the Context ClassLoader if none is supplied) and the SystemClassLoader extrating the ClassPath paths for each one; this extraction is done only if the ClassLoader in turn is an instance of URLClassLoader. In OC4J, the ClassLoaders are usually instances of oracle.classloader.PolicyClassLoader (which is not an instance of URLClassLoader). For this reason, the Classpath for the compilation is not correctly set.

There was a reported bug (CXF-2549) which gives a solution for Weblogic. I didn’t find a good similar solution for OC4J to send a patch.

I found the necessary compilation libraries are the JAXB ones. What I did, before calling createClient, was to set a new URLClassLoader which include the JAXB jars:

URL[] jaxbUrls = null;

jaxbUrls = new URL[]{
  new URL(«file:/C:/…/jaxb-api-2.2.1.jar»),
  new URL(«file:/C:/…/jaxb-impl-2.2.1.1.jar»),
  new URL(«file:/C:/…/jaxb-xjc-2.2.1.1.jar»)
};

ClassLoader currentCL = Thread.currentThread().getContextClassLoader();

URLClassLoader urlCL = new URLClassLoader(jaxbUrls, currentCL);

client = dcf.createClient(xxx, yyy, urlCL, zzz);

The compilation is now succesful.

DynamicClientFactory internally creates another URLClassLoader which includes the newly generated classes and set it as the current thread’s Context Class Loader; for this reason, when working with DynamicClientFactory in a multithreaded environment, there are some gotchas relating the ClassLoaders, but I thing this is material for another post.

EDIT: I found a better way to initialize the JAXB jars URL’s array:

import oracle.classloader.PolicyClassLoader;
import oracle.classloader.SharedCodeSource;

Class someJaxbClazz = Class.forName(«javax.xml.bind.annotation.XmlAccessType»);
PolicyClassLoader jaxbClazzClassLoader = (PolicyClassLoader)someJaxbClazz.getClassLoader();
SharedCodeSource[] sharedCodeSources = jaxbClazzClassLoader.getCodeSources(false);

for(SharedCodeSource sharedCodeSource : sharedCodeSources) {
    URL location = sharedCodeSource.getLocation();
    if(location.toString().toLowerCase().contains(«jaxb»)) {
        System.out.println(«JAXB jar URL found->» + location);
    }
}

In my case, it printed somethig like:

JAXB jar URL found->file:/C:/…/cxf/2.4.2/jaxb-api-2.2.1.jar
JAXB jar URL found->file:/C:/…/cxf/2.4.2/jaxb-impl-2.2.1.1.jar
JAXB jar URL found->file:/C:/…/cxf/2.4.2/jaxb-xjc-2.2.1.1.jar

:-)

Hello —

I am trying to build authnet-sdk-java.jar for DPM processing…. 

I downloaded the SDK-java-master, edited the build.properties (added the correct api login and transaction key) and ran «ant jar» from my windows command line.  I got the following error messages (100 in total), which tells me something isn’t setup right in the environment. 

Iran the ant command in the sdk-java-master directory.  I also downloaded sdk-java-anet-java-sdk-1.8.2 but got the same error message when I tried to build.

Has anyone seen this before?  can you help?  Thanks.  Michael

Buildfile: build.xml

compile:
    [javac] Compiling 316 source files to C:UsersMAromolaranDesktopNGStudent DevelopmentCC processing areasdk-java-mastertargetclasses
    [javac] C:UsersMAromolaranDesktopNGStudent DevelopmentCC processing areasdk-java-mastersrcmainjavanetauthorizedataarbSubscription.java:6: package javax.xml.bind.annotation does not exist
    [javac] import javax.xml.bind.annotation.XmlRootElement;
    [javac]                                  ^
    [javac] C:UsersMAromolaranDesktopNGStudent DevelopmentCC processing areasdk-java-mastersrcmainjavanetauthorizedatacreditcardCreditCard.java:7: package javax.xml.bind.annotation does not exist
    [javac] import javax.xml.bind.annotation.XmlRootElement;
    [javac]                                  ^
    [javac] C:UsersMAromolaranDesktopNGStudent DevelopmentCC processing areasdk-java-mastersrcmainjavanetauthorizedataecheckECheck.java:5: package javax.xml.bind.annotation does not exist
    [javac] import javax.xml.bind.annotation.XmlRootElement;
    [javac]                                  ^
    [javac] C:UsersMAromolaranDesktopNGStudent DevelopmentCC processing areasdk-java-mastersrcmainjavanetauthorizedataOrder.java:8: package javax.xml.bind.annotation does not exist
    [javac] import javax.xml.bind.annotation.XmlRootElement;
    [javac]                                  ^
    [javac] C:UsersMAromolaranDesktopNGStudent DevelopmentCC processing areasdk-java-mastersrcmainjavanetauthorizedataAddress.java:5: package javax.xml.bind.annotation does not exist
    [javac] import javax.xml.bind.annotation.XmlRootElement;
    [javac]                                  ^
    [javac] C:UsersMAromolaranDesktopNGStudent DevelopmentCC processing areasdk-java-mastersrcmainjavanetauthorizedataAddress.java:6: package javax.xml.bind.annotation does not exist
    [javac] import javax.xml.bind.annotation.XmlType;

Posted By: Anonymous

I’m trying to deserialize XML data into a Java content tree using JAXB, validating the XML data as it is unmarshalled:

try {
  JAXBContext context = JAXBContext.newInstance("com.acme.foo");
  Unmarshaller unmarshaller = context.createUnmarshaller();
  unmarshaller.setSchema(schema);
  FooObject fooObj = (FooObject) unmarshaller.unmarshal(new File("foo.xml"));
} catch (UnmarshalException ex) {
  ex.printStackTrace();
} catch (JAXBException ex) {
  ex.printStackTrace();
}

When I build the project with Java 8 it’s fine, but building it with Java 11 fails with a compilation error:

package javax.xml.bind does not exist

How do I fix the issue?

Solution

According to the release-notes, Java 11 removed the Java EE modules:

java.xml.bind (JAXB) - REMOVED
  • Java 8 – OK
  • Java 9 – DEPRECATED
  • Java 10 – DEPRECATED
  • Java 11 –
    REMOVED

See JEP 320 for more info.

You can fix the issue by using alternate versions of the Java EE technologies. Simply add Maven dependencies that contain the classes you need:

<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
  <version>2.3.0</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-core</artifactId>
  <version>2.3.0</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
  <version>2.3.0</version>
</dependency>

Jakarta EE 8 update (Mar 2020)

Instead of using old JAXB modules you can fix the issue by using Jakarta XML Binding from Jakarta EE 8:

<dependency>
  <groupId>jakarta.xml.bind</groupId>
  <artifactId>jakarta.xml.bind-api</artifactId>
  <version>2.3.3</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
  <version>2.3.3</version>
  <scope>runtime</scope>
</dependency>

Jakarta EE 9 update (Nov 2020)

Use latest release of Eclipse Implementation of JAXB 3.0.0:

  • Jakarta EE9 API jakarta.xml.bind-api
  • compatible implementation jaxb-impl
<dependency>
  <groupId>jakarta.xml.bind</groupId>
  <artifactId>jakarta.xml.bind-api</artifactId>
  <version>3.0.0</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
  <version>3.0.0</version>
  <scope>runtime</scope>
</dependency>

Note: Jakarta EE 9 adopts new API package namespace jakarta.xml.bind.*, so update import statements:

javax.xml.bind -> jakarta.xml.bind
Answered By: Anonymous

Related Articles

  • How to generate JAXB classes from XSD?
  • Examples of GoF Design Patterns in Java’s core libraries
  • javax.xml.bind.JAXBException: Class *** nor any of its super…
  • org.springframework.beans.factory.NoSuchBeanDefinitionExcept…
  • Use JAXB to create Object from XML String
  • Multipart File Upload Using Spring Rest Template + Spring…
  • Which is the best library for XML parsing in java
  • Autowiring fails: Not an managed Type
  • TLS 1.3 server socket with Java 11 and self-signed…
  • Java.lang.NoClassDefFoundError:…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

What to provide:

…for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update…

…for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraftlogs.

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge’s log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse’s installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler

  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile’s GameDir property to the pack’s instance folder (not the instances folder, the folder that has the pack’s name on it).
  4. Now launch the pack through that profile and follow the «Mojang Launcher» instructions above.

Video:

Spoiler

or alternately, 

Fallback («No logs are generated»):

If you don’t see logs generated in the usual place, provide the launcher_log.txt from .minecraft

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus’ support team.

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:

    1. git init
    2. git remote add origin [Your Repository’s URL]

      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout —track origin/master
    5. git stage *
    6. git commit -m «[Your commit message]»
    7. git push
  4. Navigate to GitHub and you should now see most of the files.

    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

Понравилась статья? Поделить с друзьями:
  • Error permission denied apply2files usr local lib docker cli plugins
  • Error overloaded operator must be a unary or binary operator has 3 parameters
  • Error perl execution failed
  • Error overloaded function with no contextual type information
  • Error performing query перевод