In this article, we will learn and find ways to run/execute maven in offline mode
With Maven, everything from compiling to build to deploy becomes easy for every application with the configuration of pom.xml for respective projects i.e.;
- Download all required artifacts for project
- Compile and build project
- Package as a war or jar or ear based on configuration
- Finally deploying to app server
But downloading artifacts from Internet makes compiling & packaging slower to complete all above tasks for a very large enterprise applications
So sometimes it is very important to run/execute maven goal in offline mode
Apache Maven – offline execution
There are 3 ways to run/execute maven in offline mode
- Run maven build in offline mode using “mvn –o install”
- Point to local m2_repo repository in xml
- Turn-on offline mode from maven’s xml using the element <offline />
Note: To run/execute maven in offline mode, it is very necessary to have every required artifacts inside local m2_repo repository
1. Command approach :
Way 1: Run maven build in offline mode using “mvn –o install”
By appending “-o” to maven goals dictates that it should run/execute in offline mode. But before that, developer should make sure every required artifacts already downloaded/stored
1st execute, “mvn dependency:go-offline” goal –> which checks every possible dependencies required for project before going offline
mvn dependency:go-offline
2nd execute, your required goal in offline mode. For example,
mvn –o install
or
mvn --offline install
Note: 1st execute isn’t required, if developers are sure that every required artifacts present in the local repository
2. pom.xml Modification approach
Way 2: Point to local m2_repo repository in pom.xml
Once developer is sure that, every required artifacts present in the local m2_repo repository then just change the pom.xml with the below chunk
<repository>
<id>central</id>
<url>file://D:\Users\.m2\repository</url>
</repository>
Generally, <repository> element inside pom.xml provides URL address from where required artifacts need to be downloaded
3. Settings.xml Modification approach
Way 3: Turn-on offline mode from maven’s settings.xml using the element <offline />
Earlier approaches are at the finer level with changes impacting only project in consideration. But this approach is at the highest level as turning-on <offline /> mode to true, applies to every projects in that particular system
<offline>true</offline>
While modifying Settings.xml, developer should consider all factors as it will impact every projects on that particular system
Useful Eclipse IDE shortcuts :
- Eclipse IDE – How to show line numbers ?
- Eclipse IDE – How to GO TO any line number directly ?
- Eclipse IDE – How to remove unused imports ?
- Eclipse IDE – How to clean project ?
- Eclipse IDE – How to build Java project automatically ?
- Eclipse IDE – How to comment and un-comment line & block ?
- Eclipse IDE – How to generate constructor using fields ?
- Eclipse IDE – How to generate getters and setters ?
- Eclipse IDE – How to search files ?
- Eclipse IDE – How to locate methods in Java file ?
- Eclipse IDE – How to open editor using CTRL + E ?
- Eclipse IDE – Java compiler compliance level issue
Related Articles:
- Apache Maven – Introduction
- Apache Maven – Install on Windows 7 OS
- Apache Maven – Settings.xml explanation
- Apache Maven – Proxy setting explanation
- Apache Maven – pom.xml explanation
- Apache Maven – Plugins explanation
- Apache Maven – Changing default Maven repository location in Windows 7 OS
- Apache Maven – Local, Central and Remote Repositories
- Apache Maven – Installing custom library into local repository
- Apache Maven – Transitive dependencies explanation
- Apache Maven – Exclusion of Transitive dependencies
- Apache Maven – Dependency Scopes
- Apache Maven – Skipping unit test using surefire plugin
- Apache Maven – Exclusions and Inclusions of unit test
- Apache Maven – offline execution
- Apache Maven – Co-ordinates explained
- Eclipse + Maven – Integration
- Eclipse + Maven – How to import Maven project with pom.xml ?
- Eclipse + Maven – Setting M2_REPO classpath variable in IDE
- Eclipse + Maven – M2_REPO is Non Modifiable
- Eclipse + Maven – Creating and exploring projects using archetypes
- Eclipse + Maven – Converting Web project to Maven project
- Eclipse + Maven – mvn eclipse:eclipse command
- Eclipse + Maven – Plugin execution not covered by lifecycle configuration
References:
- http://maven.apache.org/plugins/maven-dependency-plugin/go-offline-mojo.html
- https://maven.apache.org/plugins/maven-dependency-plugin/
- https://maven.apache.org/settings.html
Happy Coding !!
Happy Learning !!