Tuesday, March 22, 2011

Maven auto increment build number

Recently I have been working on auto incrementing build number and generating build artefact name containing build number for application build with maven. Here is how it was done.

In the pom.xml file add following plugin:

<plugins>
         <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>true</doCheck>
<doUpdate>false</doUpdate>
<format>${version}.{0,number}</format>
<items>
<item>buildNumber</item>
</items>
</configuration>
</plugin>

Now the $buildNumber value can be used from inside the pom file e.g. this way:


<build>
<finalName>
${project.artifactId}-${buildNumber}
</finalName>



Every time build gets to the maven validate phase, there is a buildNumber.properties file created or updated with current build number. However there is a catch.

This solution is good if the buildNumber.properties file is not being moved or deleted  and I have learned that if the file is gone, the build number will be reset to 1 again, making this not usable, especially on dynamically created build agents, as it is used in my organization (Teamcity and Amazon EC2 integration).

More information about the build number plugin: http://mojo.codehaus.org/buildnumber-maven-plugin/

Tuesday, February 22, 2011

Parsing XML time value with java SimpleDateFormat

I have encountered a problem with parsing following string as a date object

2011-02-21T07:00:00.000+01:00

if the only interesting part is getting date and time following date time pattern is enough
yyyy-MM-dd'T'hh:mm:ss

assuming there is following xml node
<startTime>2011-02-23T08:00:00.000+01:00startTime>

//initialization with correct date time pattern
SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");

//timeParam is type of XMLElement

if (timeParam.getName().equals("startTime")) {
Date dateTime = dateTimeFormat .parse(timeParam.getContent());

//dateTime now can be used to set time for GregorianCalendar object
time.startTime = new GregorianCalendar();
time.startTime.setTime(dateTime );

Monday, February 21, 2011

Embedded mule ESB Java web services deployment and configuration to Tomcat server

Tomcat setup:

  1. Install Tomcat server (e.g. version 6.0 - requires Java 1.6 installed)

Deployment or upgrade of web services

  1. Place the war file (WebApplicaton_War_File_Name.war) file in Tomcat_Home\webapps 
  2. Start / Restart Tomcat

After starting tomcat web archive gets unpacked

Service url configuration

Service url (webserviceUrl) can be configured by making changes in mule-config.xml
(Tomcat_Home\webapps\WebApplicaton_War_File_Name\WEB-INF\classes\mule-config.xml)
by changing endpoint address value
 
-After configuration changes restart Tomcat server.

Testing if correctly deployed

Ensure that application runs correctly by navigating to:http://webserviceUrl?wsdl
e.g.http://localhost:8080/MyWebService?wsdl
WSDL sescription should be correctly displayed (NOTE: Chrome sometimes does not display wsdl file content- try in FireFox or IE)

Troubleshooting

In case of any problems log files can be found here:
Tomcat_Home\logs
Using war file greatly simplifies applications distribution, instead of many files there is only one file required, place it in correct place, start server, done. Simply great.

Resolving invalid target release error, java maven build

After running mvn install -DskipTests=true command
I got following error:

[INFO] Scanning for projects...
[INFO] -------------------------------------------------------------------------
---
[INFO] Building visitplanning
[INFO]    task-segment: [install]
[INFO] -------------------------------------------------------------------------
---
[INFO] Ignoring available plugin update: 2.3.2 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.3.1 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.3 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.2 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.1 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.7.2 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.7.1 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.7 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.6 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.5 as it requires Maven version 2.0.9
[INFO] [resources:resources]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Workspace\XXXXXXXX\src\main\resourc
es
[INFO] [compiler:compile]
[INFO] Compiling 37 source files to D:\Workspace\XXXXXXXX\target\classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.6

The solution was pretty simple. Maven uses JAVA_HOME environment variable and by changing it to point to JDK 1.6 the error was resolved.

Friday, January 7, 2011

Attaching debugger to .NET Compact Framework on mobile device (or emulator)

How to attach debugger to .NET Compact Framework running on the mobile device emulator

Enable Managed debugging on the mobile device - by default it is disabled to not affect performance.

Run Visual Studio Remote Tools> Remote Registry Editor and choose the Mobile Device/Emulator

Add/Change following key in registry

Go to the :
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETCompactFramework/Managed Debugger/ and set the AttachEnabled value to 1

if the 'Managed Debugger' key does not exist just create it, the same with AttachEnabled value (new DWORD Value with name: AttachEnabled and value: 1)

In the Visual Studio go to Debug > Attach to Process
In the Transport choose Smart Device
Browse for your Device/Emulator
Choose the application and attach debugger ( if an application have been opended before making changes in the Device Registry you may have to restart the application )

Right now (if the symbols are loaded) you can start debugging application. Voila!

Eclipse conditional breakpoints

Here is how to set a conditional breakpoint in Eclipse IDE:

1) on the Debug perspective go to Breakpoints view
2) Right-click the breakpoint and choose "Breakpoint properties" (or select the breakpoint and press Alt+Enter)
3) On the properties window enable checkbox "Enable condition" and type a condition expression, breakpoint can be hit when condition becomes true or the condition value changes-it is all configurable.

That's all, although setting conditional breakpoint is not as intuitive as in Visual Studio, it works and does the job!