Did this blog help you solve a problem? Tip me with Bitcoins at: 17dQktcAmU4urXz7tGk2sbuiCqykm3WLs6

 

Saturday, May 26, 2012

Maven Project Compiles in Eclipse but Maven Build Fails


Today I ran into a perplexing Eclipse/Maven issue where my Maven project would compile just fine according to Eclipse, but the Maven compile goal would fail. If you are reading this you probably had the same issue and this might help.

Version Information

Maven 3.0.4
Eclipse Indigo

The Error

The following error was produced by the Maven compile goal:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project blah: Compilation failure: Compilation failure:
[ERROR] Blah.java:[6,17] error: package javax.jnlp does not exist

The Solution

The problem was caused by the scope I had defined for the jnlp-api dependency in a child module in a multi-module Maven project. In the parent module inside the distributionManagement tag in the pom.xml, I defined the scope as "provided". The problem occurred when I accidentally defined the scope for that dependency in the child's pom.xml as "runtime". The fix was of course to make the scopes match in both pom.xml files.

I could have saved a lot more time debugging this, if Maven would have produced a more specific error message. Oh well.

Read more...

Friday, May 25, 2012

Introductory Maven and m2eclipse Videos







Read more...

Using Maven Offline


Here's another micro blog intended to help other programmers avoid a very frustrating day of trying to get Maven to work offline. I've only been using Maven for a few months, and today was the first day I worked from home, away from the office, on a new Maven project. I had my laptop with me and assumed I could just tell Maven to work offline out of my local repository. Sounds simple right? I have all the jars I need right here on my local machine. Well, what should have been straight forward was a nightmare, which in the end is very silly and Maven COULD have made this much easier to debug. Hopefully in the next release they will consider improving their error messages.

Version Information

Maven 3.0.4

The Problem

To run Maven offline, you need to use the -o argument or set offline to true in settings.xml. I assumed that would be all that's necessary, but I kept getting the following errors for third-party jars that I added to our Nexus repo at work:

Failure to find blah in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

Failed to execute goal on project blah : Could not resolve dependencies for project

The following artifacts could not be resolved

[WARNING] The POM for blah is missing, no dependency information available

The repository system is offline but the artifact blah is not available in the local repository.

The Reason

After an entire day of tracking down the problem online, I finally stumbled upon the reason for all the issues described in these three articles.

One
Two
Three

To quote the first one:

"Thank you. That was the problem. I had had a setting.xml that pointed to
an internal repo at my company, and then cleared it out. Maven puts a
file named _maven.repositories in with the jar file in the local repo
that keeps track of where the jar came from. If the remote repo isn't
available, the build fails. Deleting _maven.repositories solved the
problem.

This seems like an extrordinarily bad design. If a remote system goes
down, you can't do a build? If you have an internal repo at work, and
you take your laptop home, you can't do a build?"

The Solution

Delete all _maven.repositories files in your local repository. Once I did that, the build worked like it should. There's arguably a good reason for Maven to use these files, but it's pretty weak that Maven couldn't improve the error message for this situation. Please go to the Jira Issue Page for this and upvote this.
Read more...

Monday, May 14, 2012

Install Sonatype Nexus as Windows Service


The following mini-guide takes you through the steps I used to install a Nexus server on a Windows machine.

Step 1: Download and unzip nexus.


Step 2: Move the folder "nexus-2.0.4-1-bundle" to C:\Program Files.

Step 3: Install the nexus Windows Service. Double click the batch file: C:\Program Files (x86)\nexus-2.0.4-1-bundle\nexus-2.0.4-1\bin\jsw\windows-x86-32\install-nexus.bat.

Step 4: Open up Windows Services and start "nexus".


Step 5: Verify it's working. Open up a browser and go to http://localhost:8081/nexus. Login using the nexus default username and password of admin/admin123.


Piece of Cake!!!
Read more...

Thursday, May 3, 2012

Install Sonar Using Oracle as the Database


This short tutorial shows how to setup Sonar with an Oracle 10g database. These instructions and screenshots are

Step 1: Configure Sonar. Open up C:\Program Files\sonar-3.0\conf\sonar.properties

comment out:

sonar.jdbc.url: jdbc:derby://localhost:1527/sonar;create=true

remove comment:

sonar.jdbc.url: jdbc:oracle:thin:@localhost/XE
sonar.jdbc.driverClassName: oracle.jdbc.OracleDriver
sonar.jdbc.validationQuery: select 1 from dual


Step 2: Create database user. Open up SQL*Plus and run the following commands at the prompt:

connect username/password
CREATE USER sonar IDENTIFIED BY sonar;
GRANT UNLIMITED TABLESPACE, CONNECT, RESOURCE, CREATE SESSION, CREATE TABLE, CREATE VIEW, CREATE SYNONYM, CREATE SEQUENCE, CREATE PROCEDURE, CREATE TRIGGER TO sonar;
EXIT

Step 3: Get the oracle jdbc driver. Download ojdbc6.jar from Oracle's download site and place it in C:\Program Files\sonar-3.0\extensions\jdbc-driver\oracle.


Step 4: Restart Sonar.

Step 5: Verify it's running. Open up a browser and go to: http://localhost:9000/. You should see the following...


Viewing the Sonar System Info should reveal that Sonar is indeed running with Oracle:


Piece of Cake!!!

Relevant Links

SQL*Plus on Wikipedia
Read more...

Wednesday, May 2, 2012

Steve Jobs Inspires


Read more...

Install Sonar on Windows as a Windows Service


This short tutorial shows how to setup Sonar as a Windows Service on Windows.

Step 1: Download Sonar from the Sonar download website.


Step 2: Unzip the .zip file and move the entire 'sonar-3.0' directory to 'C:\Program Files'.

Step 3: Double-click C:\Program Files\sonar-3.0\bin\windows-x86-64\StartSonar.bat to start Sonar. If your machine is 32-bit, run C:\Program Files\sonar-3.0\bin\windows-x86-32\StartSonar.bat instead.

Step 4: Verify it's running. Open up a browser and go to: http://localhost:9000/. You should see the following...


Step 5: Setup Sonar to start as a Windows Service. Double-click C:\Program Files\sonar-3.0\bin\windows-x86-64\InstallNTService.bat. If your machine is 32-bit, run C:\Program Files\sonar-3.0\bin\windows-x86-32\InstallNTService.bat instead.

Step 6: Restart the computer.

Step 7: Verify again that it's running. The Sonar Windows service should start Sonar when the machine boots up. Open up a browser and go to: http://localhost:9000/. For administration features, the Sonar default login/password is admin/admin.

One Small Issue

After restarting the computer and checking if Sonar was running, Sonar was not running. After some digging, I found that you can look in C:\Program Files\sonar-3.0\logs\sonar.log to debug Sonar. The following log messages hinted at the problem:

INFO | jvm 1 | 2012/05/02 12:55:26 | WrapperSimpleApp: Encountered an error running main: java.lang.IllegalStateException: Unable to create file in temporary directory, please check existence of it and permissions: C:\Windows\system32\config\systemprofile\AppData\Local\Temp\
INFO | jvm 1 | 2012/05/02 12:55:26 | java.lang.IllegalStateException: Unable to create file in temporary directory, please check existence of it and permissions: C:\Windows\system32\config\systemprofile\AppData\Local\Temp\
INFO | jvm 1 | 2012/05/02 12:55:26 | at org.sonar.application.StartServer.canCreateTemporaryFiles(StartServer.java:60)

Apparently, Sonar is trying to write to a temp file and Windows is not letting it. After all failed attemps to create the Temp folder manually and remove the write protection, I ended up solving the issue by manually configuring the Windows Service. The Sonar Windows Service's "user" was LocalSystem by default. I had to switch the service over to run under a regular user, and that fixed the issue.

Piece of Cake!!!

Relevant Links

Sonar on Wikipedia
sonarsource.org
Read more...

Sunday, April 29, 2012

Continuous Integration Using Jenkins, Git, and Maven


This tutorial demonstrates how to set up Jenkins, Git, and Maven to work together and provide a smooth continuous integration system. While the examples shown here are on a Windows machine, the concepts are the same for other operating systems such as Linux or Mac OS X, and with slight adjustments, can be adapted accordingly. This article assumes the following is installed and running on the system:

Why CI?

Continuous integration attempts to automate building and testing of source code at regular intervals in order to alert a team as early as possible about problems and merging issues.

From Wikipedia: Continuous Integration, "In software engineering, continuous integration (CI) implements continuous processes of applying quality control — small pieces of effort, applied frequently. Continuous integration aims to improve the quality of software, and to reduce the time taken to deliver it, by replacing the traditional practice of applying quality control after completing all development."

From Martin Fowler: "Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly."

Configure Jenkins

Step 1: Enable security. From the Jenkins dashboard, navigate to 'Manage Jenkins' and then 'Configure System'.

1.a. Check 'Enable security'

1.b. Choose 'Jenkins's own user database'

1.c. Uncheck 'Allow users to sign up'

1.d. Choose 'Matrix-based security'

1.e. Enter an admin username next to 'User/group to add:'

1.f. Check all rights for the user.


1.g. Click 'Save'

1.h. Enter log in information for the admin user in the form that appears.


Step 2: Add a JDK. From the Jenkins dashboard, navigate to 'Manage Jenkins' and then 'Configure System'.

2.a. Click 'Add JDK' and enter Name and JAVA_HOME.


2.b. Click 'Apply'

Step 3: Add Maven information.

3.a. Click 'Add Maven' and enter Name and MAVEN_HOME.


3.c. Click 'Save'

Step 4: Add Git information.

4.a. From the Jenkins dashboard, navigate to 'Manage Jenkins' and then 'Manage Plugins'.

4.b Click on the 'Available' tab and search using the browser (CTRL+F) for 'git plugin'.

4.c. Check 'Git Plugin' and click 'Download now and install after restart'. The install can take a while.

4.d. From the Jenkins dashboard, navigate to 'Manage Jenkins' and then 'Configure System'.

4.e. Add Git information.


4.f. Click 'Save'.

Step 5: Configure a Jenkins Job.

5.a. From the Jenkins dashboard, navigate to 'New Job'.

5.b. Enter a 'Job Name' and select 'Build a maven2/3 project'. Click 'OK'.


5.c. Enter a 'Description'.

5.d. Select 'Discard Old Builds'.

5.e. Enter an amount by 'Max # of builds to keep'.


5.f. Select 'Git' and enter a 'Repository URL'. If you wanted to track a git repo on Github, this is where you would enter the git URL.


5.g. Check 'Poll SCM' and add '* * * * *' to 'Schedule'. '* * * * *' is a cron expression which means 'every minute'.

5.h. Under 'Build' add a Maven goal in 'Goals and options'.


5.i. Click 'Save'.

Step 6: Run the Job.

6.a. From the Jenkins dashboard, run the new job by clicking the clock with arrow icon on the far right. If everything is set up correctly, the job should run and a blue ball should appear. You may have to refresh the page after the job runs to refresh the ball.


If you need to debug a Jenkins job either while it is running or after it is finished, you can view console output. From the dashboard, click on the job name. Once on the job's page, hover over a link in the 'Build History' section and select 'Console Output'.


Also, when you push new commits to the git repo, Jenkins should recognize that and start the job automatically.

Piece of Cake!!!

Helpful Links

Install Jenkins on Windows as a Windows Service
Hello World - Maven, M2Eclipse and Eclipse
Setup Git on Windows
Read more...

Saturday, April 28, 2012

Wingsuit Flying




Wingsuit Flying on Wikipedia Read more...

Install Jenkins on Windows as a Windows Service


Installing Jenkins on Windows and setting up a Jenkins Windows Service, which starts Jenkins automatically whenever Windows is restarted is now easier than ever since there is a Jenkins Windows install wizard for it. This short tutorial shows how to setup Jenkins on Windows.

Step 1: Download the Windows native package from the Jenkins main website.


Step 2: Unpack the .zip file.

Step 3: Click through the install wizard.





Step 4: Verify that Jenkins is running. Open up a browser and go to: http://localhost:8080/. You should see the following:


Piece of Cake!
Read more...