-
Notifications
You must be signed in to change notification settings - Fork 0
1.Imp Notes
Maven
A Project Object Model(POM) is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project Artifact is a file(usually JAR) that gets deployed to a Maven repository. Each artifact contains a groupid, artifactid and version number. Groupid is an unique identifier of the project across all projects in a gien maven repository. Artifiact id is the name of the jar in lower case letters. Number of the distribution Plugin performs a course of action on project in maven. Eg: mvn clean, mvn package mvn archetype:generate
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=1.0
-DarchetypeGroupId=org.apache.maven.archetypes
-DarchetypeArtifactId=maven-archetype-quickstart
-DarchetypeVersion=1.4
-Djava-version=11
-DinteractiveMode=false
mvn archetype:generate
-DgroupId=<package name>
-DartifactId=<application name>
-Dversion=<version number>
-DarchetypeGroupId="org.apache.maven.archetypes"
-DarchetypeArtifactId="maven-archetype-webapp"
-Djava-version="17"
-DinteractiveMode=false
java version properties setup in pom file:
<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
</properties>
Execute java main method with maven plugin:
`<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${version}</version>
<configuration>
<mainClass><package>.<mainclass></mainClass>
</configuration>
</plugin>`
mvn clean package exec:java
taskkill /im java.exe /F
List of Maven Plugins: https://maven.apache.org/plugins/index.html
Few frequently in-use maven plugins:
CLEAN :Clean up after the build.
COMPILE :Compiles Java sources.
DEPLOY :Deploy the built artifact to the remote repository.
INSTALL :Install the built artifact into the local repository.
RESOURCES :Copy the resources to the output directory for including in the JAR
SITE :Generate a site for the current project.
Test :Run tests
SUREFIRE :Run the JUnit tests in an isolated class loader.
SHADE :Build an Uber-JAR from the current project, including dependencies.
SOURCE :Build a source-JAR from the current project.
ASSEMBLY :Build an assembly (distribution) of sources and/or binaries
SUREFIRE-REPORT:Generate a report based on the results of unit tests.
Few frequently used options
https://maven.apache.org/ref/3.8.5/maven-embedder/cli.html
-DskipTests : compiles the tests but skips running them.
-Dmaven.test.skip : skips compiling the tests and do not run them.
-pl <module-name> : builds only specified modules
-o : build the module offline
-U : Forces to update the dependencies.
Build specific Modules:
mvn clean install -pl sub-module-name2,sub-module-name3
# Build dependencies (also make)
mvn clean install –pl sub-module-name2 –am
# Build dependents (also make dependents)
mvn clean install -pl sub-module-name2 –amd
To verify the newer versions of dependencies available in the repository:
mvn versions:display-dependency-updates
To get detailed report of the classes those needs refactoring:
From The Command Line, Run the following command from the root of your project:
mvn org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.1.0:report
It downloads the correct Maven version if it's not found.
To create or update all necessary Maven Wrapper files execute the following command:
mvn -N wrapper:wrapper
mvn eclipse:eclipse
There is a very annoying bug in eclipse IDE. Once after importing the maven based web application, a error may appear something similar to
'resource path location type the default superclass, "javax.servlet.http.httpservlet", according to the project's dynamic web module facet version, was not found on the java build path.'
Steps to fix the problem:
- Make sure the the project is set to the right jdk version in pom file as well as in java build path and java compiler in the project properties.
- Remove the erroneous index.jsp page.
- Right click on the project, open properties, navigate to project facets and unlock dynamic web module as shown in the picture.
- Save the changes and update the project[Alt+F5].
Hopefully this should fix the problem.
By default automatic formatting and cleanup is disabled. To enable it, do the following:
Go to Window > Preferences > Java > Editor > Save Actions
Select Perform the selected actions on save.
Select Format Source code abd Format all lines is selected.
Select Organize imports is selected.
Select Additional actions and save the changes.