DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How are you handling the data revolution? We want your take on what's real, what's hype, and what's next in the world of data engineering.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • Introducing Graph Concepts in Java With Eclipse JNoSQL
  • Simplify NoSQL Database Integration in Java With Eclipse JNoSQL 1.1.3

Trending

  • Building V1 Gen-AI Products at Scale: Technical Product Patterns That Work
  • The Shift to Open Industrial IoT Architectures With Data Streaming
  • Your Kubernetes Survival Kit: Master Observability, Security, and Automation
  • Modernizing Apache Spark Applications With GenAI: Migrating From Java to Scala
  1. DZone
  2. Coding
  3. Frameworks
  4. Sonar Installation and Eclipse Plugin

Sonar Installation and Eclipse Plugin

By 
Hari Subramanian user avatar
Hari Subramanian
·
Jan. 07, 14 · Interview
Likes (3)
Comment
Save
Tweet
Share
226.5K Views

Join the DZone community and get the full member experience.

Join For Free

This Document tries to help you install Sonar, analyze your project with your Sonar installation, integrate with Eclipse, clean up violations dynamically, and practice better coding.

Table of Contents

  1. Sonar Installation
  2. Download Sonar
  3. Unzip and Install
  4. Run Sonar
  5. Sonar Console
  6. Access your Sonar installation
  7. Generate Sonar Report
  8. Update your POM with SONAR configurations
  9. Example
  10. Access your project in Sonar
  11. Integrate SONAR with Eclipse
  12. Eclipse Sonar Plug-In Installation
  13. Eclipse Integration (To install this plugin in the Eclipse IDE)  - With Eclipse Market Place
  14. Eclipse Integration (To install this plugin in the Eclipse IDE)  - With Eclipse Software Update
  15. Configure Sonar in your Eclipse
  16. Link your project for the first time
  17. Analyze and clean up the code violations
  18. Run Sonar Analysis in Local

Sonar Installation

Download Sonar

Download the sonar here http://dist.sonar.codehaus.org/sonar-3.5.1.zip  and unzip the download to your favorite folder

Unzip and Install

After Unzip you will see folder structure would look something like as follows.. 

Figure 1 – Sonar Dir Structure

Run Sonar

Depends on your OS, you need to run the executable , for an instance if you are running linux-x86 and 64 bit, then you need to run start.sh

Figure 2 – Run Sonar

Sonar Console

After you start the sonar you will see some info as follows after you run the sonar

Figure 3 - Sonar Console

Access your Sonar installation

Now you can browse your sonar installation http:localhost:9000

Generate Sonar Report

Update your POM with SONAR configurations

After we have the sonar installed, we can generate the reports for any maven project, by adding the following lines in your project pom.xml (sonar hosts in your properties section)

Figure 4 - POM XML for Sonar Generation


Example

Let’s take an example of project-common; do the following steps

· Checkout the latest code from repository to your work space

· Do mvn clean install

· Modify your pom.xml (pom.xml) to have the following under properties section

· <sonar.host.url> http://localhost:9000/ </sonar.host.url>

· Save the file

· Do mvn sonar:sonar in your command / terminal

· You will see some messages as following.

Figure 5 - Sonar report Generation - I

Note: And after few minutes (depends on the size of the modules the sonar report would even take longer)

Figure 6 - Sonar Report Generation - II

Finally you would see the following that indicates the sonar reporting is completed..

Figure 7 - Sonar Report Generation Successful

Access your project in Sonar

Now go to you http://localhost:9000 you would see the project report that you ran for

Figure 8 - Sonar Project Report at your Local 

Integrate SONAR with Eclipse

Eclipse Sonar Plug-In Installation

Eclipse Integration (To install this plugin in the Eclipse IDE)  - With Eclipse Market Place

Figure 9 - Sonar Eclipse Plug-in Install (Market Place)

Figure 10 - Sonar Eclipse Plug-in Install (Market Place) II

Eclipse Integration (To install this plugin in the Eclipse IDE)  - With Eclipse Software Update

Go to Help > Install New Software... This should display the Install dialog box.

Paste the Update Site URL (http://dist.sonar-ide.codehaus.org/eclipse/) into the field Work with and press Enter. This should display the list of available plugins and components:

Figure 11- Sonar Eclipse Plug-in Install (With Install New Software Menu)

Choose Sonar Java, follow the steps and install the plugin

Note: Please make sure the project that you want to associate with sonar has already analyzed in your sonar installation


Configure Sonar in your Eclipse

Configure your local/remote sonar in your Eclipse

Go to Window > Preferences > Sonar > Servers.

Sonar Eclipse is pre-configured to access a local Sonar server listening on http://localhost:9000/. You can edit this server, delete it or add a new one.

Figure 12 - Configure Sonar Server in Eclipse

Link your project for the first time

Once the Sonar server is defined, the next step is to link your Eclipse projects with projects defined and analyzed on this Sonar server.

To do so, right-click on the project in the Project Explorer, and then Configure > Associate with Sonar...:

Figure 13 - Configure / Associate your Eclipse Project with Sonar

In the Sonar project text field, start typing the name of the project and select it in the list box:

Figure 14 - Associate your Eclipse Project with Sonar II

Click Finish. Your project is now associated to one analyzed on your Sonar server.

Analyze and clean up the code violations

Do local analysis and clean the violations

Figure 15 - Configure Modules

Figure 16 - configure sonar modules from Eclipse

Note

Please make sure you have started your local sonar server (as described in Run sonar section) otherwise you would not able to see the right sonar project that you intend to configure

Run Sonar Analysis in Local

Figure 17.a – Set Sonar Analysis on Local Mode

Figure 17:b - Run Sonar Analysis on Local


Figure 18 - sonar violation analysis console

Figure 19 - Sonar violation analysis console II

Figure 20 - Sonar violations Markers


Eclipse

Opinions expressed by DZone contributors are their own.

Related

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • Introducing Graph Concepts in Java With Eclipse JNoSQL
  • Simplify NoSQL Database Integration in Java With Eclipse JNoSQL 1.1.3

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: