Apache PDFBox is an open source Java library that can be used to create, render, print, split, merge, alter, verify and extract text and meta-data of PDF files. Another very popular Java library for working with PDF files is called iText. The package goal will compile your Java code, run any tests, and finish by packaging the code up in a JAR file within the target directory. The name of the JAR file will be based on the project’s and.For example, given the minimal pom.xml file from before, the JAR file will be named gs-maven-0.1.0.jar.
We can create a simple maven example by executing the archetype:generate command of mvn tool.
To create a simple java project using maven, you need to open command prompt and run the archetype:generate command of mvn tool.
Syntax
The syntax to generate the project architecture is given below:
Example
The example to generate the project architecture is given below:
Note: Here, we are using maven-archetype-quickstart to create simple maven core project. if you use maven-archetype-webapp, it will generate a simple maven web application.
Output
Now it will generate following code in the command prompt:
Generated Directory Structure
Now go to the current directory from where you have executed the mvn command. For example: C:UsersSSS ITCubeGenerator. You will see that a simple java project is created that has the following directory:
As you can see, there are created 3 files pom.xml, App.java and AppTest.java. Let's have a quick look at these files:
1) Automatically Generated pom.xml file
2) Automatically Generated App.java file
3) Automatically Generated AppTest.java file
Compile the Maven Java Project
To compile the project, go to the project directory,
for example: C:UsersSSS ITCubeGenerator and write the following command on the command prompt:
Now, you will see a lot of execution on the command prompt. If you check your project directory, target directory is created that contains the class files.
Run the Maven Java Project
To run the project, go to the project directorytargetclasses,
for example: C:UsersSSS ITCubeGeneratortargetclasses and write the following command on the command prompt:
Now, you will see the output on the command prompt:
Output of the maven example
How to build the maven project or how to package maven project?
The mvn package command completes the build life cycle of the maven project such as:
- validate
- compile
- test
- package
- integration-test
- verify
- install
- deploy
![Maven By Sample Pdf Files Maven By Sample Pdf Files](https://cdn.e-iceblue.com/images/art_images/How-to-install-SpirePDF-for-Java-from-Maven-Repository-2.png)
Visit this link to know more about build life cycle http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
You need to execute the following command on the command prompt to package the maven project:
Now you will see that a jar file is created inside the project/target directory.
You can also run the maven project by the jar file. To do so, go to the maven project directory, for example: C:UsersSSS ITCubeGenerator and execute the following command on the cmd:
Now you will see the following output: