EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • All Courses
    • All Specializations
  • Blog
  • Enterprise
  • Free Courses
  • All Courses
  • All Specializations
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials Maven Tutorial Maven XMLBeans
 

Maven XMLBeans

Updated February 20, 2023

Maven XMLBeans

 

 

Introduction to Maven XMLBeans

Maven xmlbeans is a part of the maven plugin artifact which was starting with the xml beans as 5.0. Maven xml beans is a technology that was used to access xml while binding the types of java. Maven xmlbeans is providing several ways to get an xml. Using xml schema which was compiled for generating java types represents the schema types defined in maven.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Key Takeaways

  • Maven xmlbeans is nothing but the tool which was used to allow to access full power on xml. XMLBeans uses the xml schema which was used to compile the interfaces of java.
  • By using xml beans java interfaces and classes are used to access and modify the instance data.

What is Maven XMLBeans?

At the time of creating java types, we can access the instance of schema by using accessors of java beans styles of getting foo and set foo. The API of xml beans is allowing us to reflect the xml schema itself by using the model of xml schema object. The model of the cursor will traverse the xml of the full Infoset. Maven xml beans support xml DOM. To use the maven xmlbeans we need to add the xmlbeans plugin into the pom.xml configuration files.

A maven xml beans plugin is parsing the xsd files and produces the corresponding object model which was based on the parser of apache xml beans. The maven plugin produces two sets of output files referred by generated sources and classes. The former is compiled into the output build directory. The maven xml beans is a tool that allows access to xml java.

Use of Maven XMLBeans

Given below shows the project template of maven xmlbeans:

1. While using the project template we are also assigning details of the project.

Group name – com.example
Artifact – maven_xmlbeans
Name – maven_ xmlbeans
Packaging – jar
Java version – 8
Language – java

Maven XMLBeans 1

2. In this step we are downloading and extracting the project and opening the same by using the spring tool suite.

downloading and extracting the project

3. In this step we are checking the project structure of the maven xmlbeans project and also checking the pom.xml file.

Maven XMLBeans 3

4. After opening the project in the spring tool suite now in this step we are adding the xml beans dependency in the pom.xml file. We are adding this dependency in the pom.xml file.

Code:

<dependency>
  <groupId> org.apache.xmlbeans </groupId>
  <artifactId> xmlbeans </artifactId>
  <version> 2.3.0 </version>
</dependency>

Output:

Maven XMLBeans 4

5. After adding the dependency now we are executing the maven test command to run the test of the project as follows. We are executing the test by using the GUI terminal as follows.

testing the project

Maven XMLBeans Plugin

The source file of xml beans is generated by using basedir. The class of type system holder is generated by using basedir resources. The generated resources and sources are added to the project resources.

The below example shows how we can add the maven xml beans plugins into the maven. We are adding the maven xml beans plugin in the pom.xml files.

Code:

<plugin>
<groupId> org.codehaus.mojo </groupId>
<artifactId> xmlbeans-maven-plugin </artifactId>
<version> 2.3.3 </version>
<executions>
<execution>
<goals>
<goal> xmlbeans </goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory> path </schemaDirectory>
<xmlConfigs>
<xmlConfig implementation = "java.io.File">
path
</xmlConfig>
</xmlConfigs>
<noUpa> false </noUpa>
<sourceGenerationDirectory>
   path
</sourceGenerationDirectory>
  </configuration>
</plugin>

Output:

generated by using basedir

After adding the plugin of maven xml beans into the pom.xml file. Now in this step, we are running the maven application by using the maven test command as follows. In the below example we are using the spring tool suite to run the application as follows.

Maven XMLBeans 7

Maven XMLBeans Configure File

Maven xml beans configuration file uses the special compiler for converting xml schema into the bunch of java classes that we have defined for accessing the XML elements and other content. By using the xml schema the compiler of the java class is the nearest approach to put our schemas and compiler into separate jar files. We can mix all this code. To create the maven xmlbeans configure file we need to add the plugin code into the pom.xml files. In the below example, we are adding the code in the pom.xml file as follows.

Code:

<plugin>
<groupId> org.codehaus.mojo </groupId>
<artifactId> xmlbeans-maven-plugin </artifactId>
<version> 2.3.3 </version>
<configuration>
<schemaDirectory> configuration dir path </schemaDirectory>
<xmlConfigs>
<xmlConfig implementation="java.io.File">
  Configuration file path
</xmlConfig>
</xmlConfigs>
<noUpa> false </noUpa>
<sourceGenerationDirectory>
  Configuration file directory.
</sourceGenerationDirectory>
</configuration>
</plugin>

Output:

Configure File

The pom.xml file is working as a configuration file in maven xml beans. We are configuring the configuration file path where our actual file is stored and the file directory of the configuration file.

After configuring the file in the below example we are running the configuration file which we have added to the pom.xml file.

Maven XMLBeans 9

Example of Maven XMLBeans

The below example shows to add the maven xmlbeans dependency into the project of maven. We are adding the dependency into the pom.xml file as follows. We are adding this dependency in the dependency section of the pom.xml file.

Code:

<dependency>
  <groupId> org.apache.xmlbeans </groupId>
  <artifactId> xmlbeans </artifactId>
  <version> 2.3.0 </version>
</dependency>

Output:

Maven XMLBeans 10

After adding the configuration to the pom.xml file now we are testing the maven project. In the below example, we are using the spring tool suite GUI.

Maven XMLBeans 11

After adding the configuration in the pom.xml file now we are testing the maven project as follows. In the below example, we are using the command line.

Code:

mvn test

Output:

Command line

Maven XMLBeans 13

Conclusion

By using xml schema which was compiled for generating java types which were representing the schema types which was defined in maven. Maven xml beans support xml DOM. To use the maven xmlbeans we need to add the xmlbeans plugin in the pom.xml configuration files.

Recommended Articles

This is a guide to Maven XMLBeans. Here we discuss the introduction, use of maven XMLBeans, plugin, configure file, and example. You may also have a look at the following articles to learn more –

  1. Maven kafka-clients
  2. Maven Install Dependencies
  3. Maven Run Single Test
  4. Maven Quickstart Archetype
Primary Sidebar
Footer
Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW