Thursday, May 31, 2012

Delete a Branch on GitHub

Deleting a branch on Github or any remote Git repository is very simple and just requires running the following Git command:

git push REMOTENAME :BRANCHNAME

Piece of Cake!!!

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.

Friday, May 25, 2012

Introductory Maven and m2eclipse Videos








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.

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!!!

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

Wednesday, May 2, 2012

Steve Jobs Inspires

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