Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Friday, 22 December 2023

How to upgrade Maven

 

java.lang.IllegalStateException

I had installed maven in my ubuntu using command 

apt install maven

This installed maven in path /usr/share/maven

Months later, I encountered a maven exception when compiling a java project. The error was as follow:

[ERROR] Error executing Maven.
[ERROR] java.lang.IllegalStateException: Unable to load cache item
[ERROR] Caused by: Unable to load cache item
[ERROR] Caused by: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper

My java version at the time was

openjdk version "17.0.2" 2022-10-18
OpenJDK Runtime Environment (build 17.0.2+8-Ubuntu-2ubuntu120.04)
OpenJDK 64-Bit Server VM (build 17.0.2+8-Ubuntu-2ubuntu120.04, mixed mode, sharing)

and my maven version at the time was

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 17.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.10.16.3-microsoft-standard-wsl2", arch: "amd64", family: "unix"

The cause of the error was that maven version(3.6.3) is old. I needed to upgrade to the latest version of maven.

Unfortunately, I could not upgrade to the latest maven version (3.9.0 at the time) using the aptpackage manager on Ubuntu. Generally, the easiest way to install anything on Ubuntu is via the apt package manager. However, it often does not include the latest JDK packages.

These are the steps to install the latest maven version on Ubuntu:

  1. Download the latest maven binaries

a. cd into the /tmp directory on your terminal

b. Check https://maven.apache.org/download.cgi and copy the link for the “Binary tar.gz archive” file.

c. Run the following command to download the binaries:

wget https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz

d . Untar the archive file and extract it in the directory

tar -xvf apache-maven-3.9.6-bin.tar.gz
mv apache-maven-3.9.6 maven
mv maven /usr/share/

Note: the latest maven version I was downloading was 3.9.6. Make sure to replace the version in the commands above with the maven version

Friday, 18 September 2020

End to End Automation of Java web App Using jenkins, bitbucket,sonaqube,Maven,Tomcat,Artifactory,Slack

 Tools Used:

  • Bitbucket— Source Code Management
  • Maven — Build Tool
  • Jenkins — Continuous Integration (CI/CD)
  • Artifactory — Artifact Repository Manager
  • SonarQube — Code Quality and Code Analysis
  • Tomcat — Application Server(Web container)



What is the Requirement? - Setup MyDevopsApp Java Project using Maven in Bitbucket and Automate end to end Builds, Code quality checks, Deployments and Collaboration using Jenkins and other Devops tools we have used so far. Could you please work on below lab exercise on a brand new EC2 instance(small instance) and show the output when we meet on next week end?


Lab Exercise Steps:
1. Also, create a repo called MyAutomationRepo in bitbucket. (lab exercise # 5)
2. Create a Java project called MyDevopsApp (instead of MyWebApp which we did before (lab exercise #5) using Maven.
3. Set the above project in Bitbucket(lab exercise #5)
4. Set up a free style job called MyDevopsFreeStyleJob (use webhooks,lab exercise #6, lab exercise # 8) in Jenkins and automate builds, deployments to Tomcat server (lab exercise #6). Also integrate with SonarQube to see the code quality report(lab exercise #10). Finally Jenkins should deploy to Tomcat immediately if there is a code change(lab exercise #7, lab exercise 8). Also jenkins should upload WAR into Artifactory as well. (lab exercise # 17, lab exercise 18). And send notifications to Slack(lab exercise # 19)
5 Finally show the below output in Tomcat by modifying index.jsp (lab exercise #6) in your java project. 
       Congrats I am now a Devops Engineer I Can Migrate App to cloud using Bitbucket,Jenkins,Maven and Tomcat!!!
6. SonarQube dashboard should be viewed in Sonarqube.
7. Artifactory should show uploaded artifacts as well.
8. Slack should show the message coming from Jenkins for every build success/failure.

Tips:

You all know the maven command to create a Java project using Maven and where you to change the word MyWebApp to MyDevopsApp.
mvn archetype:generate -DgroupId=com.mkyong -DartifactId=MyWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Thursday, 17 September 2020

How to integrate Artifactory to Jenkins and publish artifact to Artifactory

 

Integrate Artifactory with Jenkins - Upload Artifacts from Jenkins to Artifactory - How to Integrate Jenkins with Artifactory

You can install plug-in called Artifact plug-in to integrate Artifactory with Jenkins. Let us see how to integrate Jenkins with Artifactory and able to upload War/Ear/Jar/Exe/DLLs using Maven.




Pre-requistes:
Install Artifactory plugin in Jenkins.



Make sure Maven 3 is also configured under Manage Jenkins--> Global Tool configuration
Enter Name as Maven3
/usr/share/maven as MAVEN_HOME



Configure Arifactory in Jenkins:
1. Go to Manage Jenkins, Click on configure system. Look for Artifactory section, click on Add Artifactory server



2. Enter Artifactory url like given below:
some name for server_id
http://public_dns_name:8082
admin/Admin123 as credentials
Click on Test connection to verify everything is right.
You should get the message like below:
Found Artifactory 7.4.1



Apply...Save

3. Once you installed the above plug-in, click on existing Freestyle job configuration.
4. Go under Build environment
Select Maven 3 - Artifactory integration check box
and click on refresh Repositories and choose repos as mentioned below:







 5.Click on Add Build step and choose Invoke Artifactory Maven 3



6. Enter value as below, MyWebApp/pom.xml as root POM
and goal as install




Apply....Save
7. Now click on Build, Jenkins should build using Maven and upload WAR file into Artifactory.

8. Login to Artifactory, Click on Artifactory --> Packages



Saturday, 22 August 2020

Create Your First Maven Project and Migrate to Source Control(Bitbucket) Using Git Bash and Vscode- PT 1

 To Complete this Task, You need to have the following :

Bitbucket account: https://bitbucket.org/product

Git Bash: https://git-scm.com/

Vscode: https://code.visualstudio.com/

Maven and Java: Refer to previous posts

 https://violetstreamstechnology.blogspot.com/2020/08/how-to-install-maven-and-java-jdk-in.html

https://violetstreamstechnology.blogspot.com/2020/08/pleasefollow-steps-to-install-java.html

Step 1: Create a New Project folder in your PC


Right click on your workspace ---->New----Folder

You can Name it whatever you like. ( I name mine projects)

Step 2: Go into the folder, launch Git Bash

Go into the folder---right click---Select--- Git Bash Here

This will launch Git Bash in your current folder

Step 3: Create First Maven Project

To create your first maven project copy and paste the following command in Git Bash console:

mvn archetype:generate -DgroupId=com.mkyong -DartifactId=MyWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false


This will create a folder called MyWebApp

Step 4: Load Project into Vscode

Go to the Git Bash Console and Type the following to load the Maven project into Vscode

code .

This will launch Vscode with the project in your current directory

Step 5: Setup SSH keys in Bitbucket

Go to Git bash console and type

ssh-keygen

It will prompt you to specify where you want to save the ssh keys and to enter passwords.

You can use default location and no password. Type enter 3 times


Go to the location your public key is(mine is /c/Users/FCP/.ssh/id_rsa.pub), you can open the file with notepad and copy the text or use the cat command to view it in git bash. You can also navigate to the file and view it using vscode. All examples are below

Using git bash:

Eg Enter

cat /c/Users/FCP/.ssh/id_rsa.pub

This will give you something like this:
$ cat /c/Users/FCP/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC5brfa2BmLK0mXytu/ePZw+IGP0yiaZGSOl3AWeQNWeSG2M9IZC8Vndodq93/jNX/AZakKag4sFripB7usvMzFqW6ctWbbBsom+objw0m14PN+PegqSHtQapxWe66Dg11tAz8+mZ5VSwyf14nujqUi/+kiiqfLYnshAYYoQSeeEtufP14ws/co5/Ckx49RyZfpWu1U3GqBoqVbD6/n65dLdPenlZ0gjCpAUC6ggwwqqq05zqoOUIakGhiqi9iFBWjXn9NHQ47DoAjZtr8NtCRkx1WPpnaw7Pyu9YnjTzRYUYLdVq7+tYEtssqwqddeem20oPNowJIJE0RI9TbgVsyrxJBv/CjtuP4CL+WJPSObFIb2MCtiJ+DKgY9pLhJDq858p99m9Rp6j//EWMTUaSwgYVDEHpMbqvGNuUUws01XowWT8vnjC+GFncIe+1kGxPTVxe/R1JamdXcm/AvrilfyODCLcfy0mcfevkSqWQHfSNJfCekOWNh95ufZwaZQDho8orhxQs30jUls= FCP@DESKTOP-Q59LJHR2J

Copy only the section Highlighted in Green Above
Step 5.1: Create a New Repo In Bitbucket

Go to your Bitbucket Account and Create a New Repo

Workspace: You can leave this as its default value or define it so that team members can collaborate. We will leave this as default.
Project name: Name of your project. we shall use MyWebApp
Repository name: Name of your repository. we shall use MyFirstRepo
Access level: Private repository . This repo wont be open to the public
 Then click Create 


Step 5.2: Copy SSH keys to your Repo
Go to your new repo. Click on Repository settings
Click Access keys then  click Add keys


Copy and Paste your ssh keys into the box the click Add SSH keys

Go to your repo home and copy the ssh command to clone your repo

Go to your Git Bash console and paste the command to clone your new repo


Congrats you have successfully Cloned your first Repo!!!!!!!!!!

How to upgrade Maven

  java.lang.IllegalStateException I had installed maven in my ubuntu using command  apt install maven This installed maven in path /usr/shar...