EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Maven Tutorial Maven XMLBeans
Secondary Sidebar
Maven Tutorial
  • Maven Basic and advance
    • What is Maven
    • How to Install Maven
    • Maven Commands
    • Maven GroupId
    • Maven WAR Plugin
    • Maven Build Command
    • Maven Failsafe Plugin
    • Maven Profile
    • IntelliJ Maven
    • Maven Enforcer Plugin
    • Maven Javadoc Plugin
    • Maven WAR Plugin
    • Maven Build Command
    • Maven GroupId
    • Maven Force Update
    • Maven Encrypt Password
    • Maven Environment Variables
    • AssertJ Maven
    • Maven Run Single Test
    • Maven kafka-clients
    • Maven Quickstart Archetype
    • Maven Install Dependencies
    • Maven XMLBeans
    • Maven Local Repository
    • Maven Versions
    • Maven Jar Plugin
    • Maven Assembly Plugin
    • Maven exec plugin
    • Maven Central Repository
    • Maven Surefire
    • Maven Deploy
    • Maven Phases
    • Maven Archetype
    • Maven Skip Test
    • Maven Dependency Scope
    • Maven Shade Plugin
    • Maven Repository Spring
    • Maven Eclipse Plugin
    • Maven Exclude Dependency
    • Maven Life Cycle
    • Maven Repository
    • Maven POM File
    • Maven Plugins
    • What is Maven Plugins
    • Maven Interview Questions
    • Maven Flags
    • Maven Project
    • Maven Settings.XML

Maven XMLBeans

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.

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.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

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
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - 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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

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 Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more