Java Maven is a project management tool that provides developers with a complete build life cycle structure. Environments with several development teams quickly perform the work of the relevant standards, and most of the project settings are simple and reusable. Maven makes life easier for developers when reporting, monitoring, and configuring automation.
Development Process Benefits
Java Maven helps a developer easily create a Java project. Any new task added to the project is easily integrated into Maven configurations. This increases the productivity of the design and construction process. The main feature of Maven is that this tool can automatically load project libraries.
In performing its functions, for consistency and flexibility, it uses a strict XML-based rule. Since most Java systems are integrated, they create robust Java Maven projects with a basic build system.
Processes that are controlled using this tool:
- Project.
- Documentation.
- Making report.
- Dependencies.
- SDM.
- Releases
- Distributions.
- Distribution list.
- Java Maven Architecture.
Configuration setting
To configure Maven, use the Project Object Model, which is stored in the pom.xml file. POM includes configuration settings related to the project. Plugins configure and edit in the pom.xml file tag. When a user runs on Java Maven, he gets the default settings. Project construction sequence:
- Add code to create and process applications in the source code repository.
- Change configurations / pom.XML / plugin options.
- Create an application for the Java Maven project.
- Save the build process output as a WAR or EAR file to a local location or server.
- Get the file from a local location or server and deploy it to the site.
- Update the application document with the date and latest version, as required by the application.
Maven is written in Java and is used to manage projects in C #, Ruby, Scala and others.
Installation
To use Maven, first make sure that the program is installed on the computer. After that, create a new directory on the hard drive, which will be the root, and then create the pom.xml file inside the directory, placing the following XML.
This is the minimum pom.xml file that you must have before creating a project with Java Maven.
Where:
- GroupId - Identifies the organization.
- ArtifactId - identifies the project. More specifically, it identifies an artifact built from a project, such as a JAR file.
- Version The version of the artifact that creates the POM file.
When a project is being developed, you need to follow the version update. Other projects that use the artifact will reference it using groupId, artifactId, and version.
Testing the POM File
After creating pom.xml inside the root directory, the health of Maven is monitored, as well as how it understands the installed file.
To do this, open the command line and transfer cd to the root. Then run the mvn clean command. It will clear the Java Maven project directory from previous temporary build files. Next, Maven will tell you which project was found, and print it to the command line. This confirms that he understands POM. The result will be displayed on the screen.
When the POM file is checked, create the Java source directory inside the standard layout. In this case, src will be located inside the project root directory. Inside it, the main directory is created, in which the java directory is placed - the root directory for the source code.
Create Java source file
Inside the root source directory src / main / java, a new (java package) helloworld is created. A file called HelloWorld.java is inserted into it.
When the source file is created, open a command prompt and set the project root directory. Then run the following mvn package command. She tells Maven to complete the package assembly phase, which is part of the default lifecycle build. Maven will compile the source file and create a Java Maven jar file containing the compiled Java class.
Maven creates the target subdirectory inside the root. Inside the target, there is a ready-made JAR file, as well as many temporary files, for example, the classes directory containing all the compiled classes.
Based on the POM in this example, the JAR file will be called HelloWorld.1.0.0.jar.
Creating settings files
If Maven is installed for the first time, for example, as part of an installation of Oracle WebLogic Server, it will not yet have a configuration file.
The maven local repository is a local folder that is used to store project dependencies. The default location is the .m2 folder.
An example of the location of the settings file:
- If the username is bob, the directory path on UNIX looks like this: /home/bob/.m2/settings.xml.
- Location on Windows: C: \ Users \ bob \ .m2 \ settings.xml.
To change the default location, find the {M2_HOME} \ conf \ setting.xml file and edit the localRepository key: / path / to / local / repo.
The developer creates Maven settings files in the following cases:
- When using a firewall or proxy server.
- When using your own internal storage manager.
The Maven settings file is called settings.xml and stored in the .m2 directory. The following is an example settings file.
Sync plug-in
Oracle Fusion Middleware 12 provides the Maven Synchronization plug-in, which simplifies the storage configuration process and eliminates the need for the user to figure out which fixes are installed in a particular environment. This plugin populates the repository from Oracle and ensures that assemblies use the correct artifacts in a particular environment. The Oracle Maven synchronization plugin is included in the installation of Oracle WebLogic Server, Oracle Coherence, and Oracle JDeveloper.
To use the plug-in, indicate the location of the Oracle home and repository. It can be specified using the file system path or URL. The plugin checks all Maven artifacts in Oracle and ensures that they are all installed in the specified repository, and the versions match and match at the binary level.
Java Project Transfer Example
If the user has a Java project and wants to convert it to Maven, find the resources folder. Inside it, they find a folder called Scripts, which contains one executable shell script file - .CrunchifyMain.java and is the main starting point for main inside the pom.xml file.
It is recommended to pre-install additional maven-resources-plugin and maven-dependency-plugin plugins, which are responsible for copying project resources to the output directory.
Sequencing:
- Open pom.xml file.
- Update directory location, file name and path (if necessary).
- Right click on Project -> Run As -> Maven Build.
- Specify the clean install argument.
- Specify the / target / Crunchify folder to perform the check.
- Run the project using the command: $ bash> java -jar Crunchify.jar
Compilation and unit tests
Each programmer performs unit tests. To do this, he enters the following command: mvn test.
After executing this command, information will be displayed on the screen:
Maven can load more plugins than it needs to run the tests, since it already has the dependencies needed to compile. Before compiling and executing, it compiles the main code. If you need to compile test sources, run the command: mvn test-compile.
Now, you can compile and run application sources and tests.
Windows installation
It is very simple to install Apache Maven on Windows. Preload the .zip archive, configure the Windows path variable. The sequence of operations:
- Download and unzip the latest version of Maven. In the "Files" section, select the "Binary zip archive" option.
- Unzip the archive to the local folder c: \ tools \ apache-maven-3.3.9.
- Configure the JDK and JAVA_HOME variables for the Windows environment.
- If the JDK is not installed, go to the Java Maven Home download page and download the latest JDK.
- Run the setup program and perform the sequential steps.
- After the installation is complete, open the System-> Advanced system settings-> Environment Variables in the Windows control panel and add the JAVA_HOME variable.
- Add the M2_HOME variable to the Windows environment.
- The next step is to configure the M2_HOME variable to point to the Maven folder, for example: c: \ tools \ apache-maven-3.3.9.
- Add M2_HOME to the bin folder path. To do this, select the Path variable from System-> Advanced system settings-> Environment Variables -> Edit and add it to the end.
- Check if the installation and configuration from the command line launch command were successful: mvn -version
- A message appears on the screen. This means that the Maven setup on the computer was successful. If command line windows were opened before setting environment variables, you will need to restart command line windows.
Download on macOS
Installing Maven works for any version of macOS.
Process sequence:
- On the download page, get the latest Maven Java version of the binary.
- Move the archive to the destination folder, for example, in / usr / local: sudo mv apache-maven-3.3.9-bin.tar.gz / usr / local.
- This command will move the file to / usr / local.
- The run command is retrieved: sudo tar -xvf apache-maven-3.3.9-bin.tar.gz.
- The command will be extracted to the current folder.
- Delete the archive by running the following command: sudo rm apache-maven-3.3.9-bin.tar.gz.
- To access Maven from a directory, configure M2_HOME and add the bin directory to the path.
- Check the launch of the version of the command: mvn -version.
- A message should appear on the screen.
The functions of Maven for macOS are listed in the table below:
Function | Description |
Work offline | If this check box is selected, Maven works offline and uses only resources available locally. This option corresponds to the "offline" command line option. |
Use plugin registry | Check the box to include a link to the Maven plugin registry. This corresponds to the no-plugin-registry command line option. |
Accomplishment of recursive goals | If this check box is selected, the assembly will be repeated in nested projects. Clearing this checkbox corresponds to the non-recursive command line option. |
Print Exception Stack Trace | If this option is checked, traces of the exception stack are generated. This corresponds to the command line errors option. |
Update snapshots | Check this box if you want the Java Maven IDEA to update snapshots during synchronization. |
Output level | Select the desired level of the output log, which allows plug-ins to create messages at the levels of debugging, information, warnings and errors of fatal or disabled output logs. |
Checksum policy | Select the desired checksum matching level when loading artifacts. You can refuse to download when the checksums do not match strict-checksums or give a lax-checksums warning. |
Multiple Project Build Failure Policy | Indicate how to handle a failure in a multi-project assembly. You can refuse to build at the first failure, which corresponds to the fail-fast command line option. The error at the end corresponds to the fail-at-end command-line option. |
Plugin Update Policy | Select the plugin update policy from the drop-down list. You can check for updates that match the check-plugin-updates command-line option. Disable update checking, which corresponds to the no-plugin-updates command line option. This parameter is ignored for Maven 3 and later. |
Streams - T option | Use this field to set the “T” parameter for parallel assemblies. This option is available for Maven 3 and later. |
Maven Main Directory | Use this drop-down list to select the bundled version of Maven (Maven2 requires version 2.2.1, and Maven3 requires version 3.0.5) or the result of allowed system variables such as MAVEN_HOME or MAVEN2_HOME. You can also specify your own version of Maven installed on the user computer and select the desired directory in the dialog box that opens. |
User Settings File | Specify the file containing the configuration for the Maven user in the text box. If you need to specify another, check the "Override" box, click the "Ellipsis" button and select the desired file in the "Select Maven File" dialog box. |
Local repository | By default, the field displays the path to the user's local directory, which stores downloads and contains temporary assembly artifacts. If you need to specify a different directory, select the Override check box, click the Ellipsis button and select the desired path in the Select Local Maven Storage dialog box. |
Setting up a proxy server in Windows
When Maven is installed on Windows, proxy settings are made. If the user received the error message Malformed reply from SOCKS server, then the proxy settings are configured. To make the settings, take the following steps:
- Go to the path - {M2_HOME} /conf/settings.xml.
- Open the settings.xml file in edit mode in any text editor.
- Open and update the tag.
- To save time, you can add proxy data at the end of Maven commands: $ mvn clean install -DproxySet = true -DproxyHost = ur.proxy.server -DproxyPort = port.
You can install the proxy server from the command line. In this case, it is recommended to use its global parameters in the settings.xml file.
Alternative HTTP proxy configuration approaches
There are several alternative approaches that you use to configure the HTTP proxy server, but, in general, they are not as convenient as editing the settings.xml file. For example, you can use the http.proxyHost and http.proxyPort system properties in the InstallDir / etc / system.properties file in the same way as the approach for a stand-alone container without Fabric:
- http.proxy Host = 192.0.2.0.
- http.proxy Port = 8080.
This configuration has the disadvantage of not allowing users to directly access the Maven proxy on the internal network. To compensate for this, you need to configure the host list without a proxy server to include those running Fabric servers.
From the given material it is clear that Java Maven is a platform that simplifies and standardizes the process of building a project, easily handles compilation, distribution, documentation, and teamwork. She also performs most of the tasks associated with the construction.