Søk i denne bloggen

torsdag 29. september 2011

Password encryption in maven settings.xml

create master encryption in settings-security.xml. use mvn encrypt-master-password <key>
    <settingsSecurity>
      <master>{W8KhSWMsODYH965ChH+0L2ec0aP8BUathXuBPdQTDzc=}</master>
    </settingsSecurity>
    Then use mvn-encrypt-password <password> and use it in the password tags in settings.xml.
You can add custom text outside the braces, i.e. meta info about the password

mandag 26. september 2011

Using deploy:deploy-file goal

Adding 3rd party jar files to nexus with deploy:deploy-file:


If pom file is not provided, use:

mvn deploy:deploy-file -Durl=http://host...:8081/nexus/content/repositories/thirdparty/ \
                       -DrepositoryId=nexus \
                       -Dfile=....sqlworkbench.jar \
                       -DgroupId=com.sql \
                       -DartifactId=sql-workbench \
                       -Dversion=1.0 \
                       -Dpackaging=jar \
                       -DgeneratePom=true \
                       -DgeneratePom.description="SQL workbench by Thomas Kellerer"

torsdag 22. september 2011

Creating executable jar with dependencies


<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>fully.qualified.MainClass</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
    </plugins>
</build>

søndag 18. september 2011

Introduction to Maven

Maven
According to the official maven site at apache, maven is a software project management and comprehension tool. Maven can manage a project's build, reporting and documentation from a central piece of information. 


Main objectives:

  • Making the build process easy
  • Providing a uniform build system
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features
Maven 2 lifecycle phases (By John Ferguson Smart, JavaWorld.com, 12/05/05, javaworld)

Introduction to the POM

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project.


Nexus
Nexus manages software artifacts required for development, deployment, and provisioning. If you develop software, Nexus can help you share those artifacts with other developers and end-users.

søndag 11. september 2011

Uploading artifacts to nexus repository

1) Ensure that snapshot cleaning is turned on in nexus, purging old snapshots at certain intervals.
http://www.sonatype.com/people/2009/09/nexus-scheduled-tasks/

2) add
      <distributionManagement>
        <snapshotRepository>
            <id>nexus</id>
            <name>Nexus staging repo</name>
            <url>http://host:8081/nexus/content/repositories/snapshots/</url>
            <uniqueVersion>false</uniqueVersion>
        </snapshotRepository>
    </distributionManagement>


to your root aggregator pom. Note that snapshotRepository is not a release repository, hence new snapshots can be deployed with mvn deploy goal.


3) Add authentication of nexus host in the settings file.

            <server>
            <id>nexus</id>
            <username>deployment</username>
            <password>password</password>
        </server>

4) Run mvn deploy on the root aggregator. The artifacts are uploaded.

fredag 9. september 2011

Bash script to migrate from Ant to Maven



S="/$1/$4"
if [ -d "$S" ]; then
TJ="/$2/src/$3/java"
TR="/$2/src/$3/resources"
mkdir -p $TJ
mkdir -p $TR
echo copying $S/* to $TJ
# clean java and resource directories
find $TJ \( ! -regex '.*/\..*' \) -type f -exec rm {} \;
find $TR \( ! -regex '.*/\..*' \) -type f -exec rm {} \;
# syncronize files
rsync -a -u -m --include="+ *.java" --exclude="- *.*" --exclude=".*" "$S"/* "$TJ" 2>/dev/null
rsync -a -u -m --include="+ *.form" --exclude="- *.*" --exclude=".*" "$S"/* "$TJ" 2>/dev/null
rsync -a -u -m --include="+ *.properties" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.wsmode" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.xml" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.html" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.shadow" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.png" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.PNG" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.jpg" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.JPG" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.gif" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.GIF" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.sql" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
rsync -a -u -m --include="+ *.r" --exclude="- *.*" --exclude=".*" "$S"/* "$TR" 2>/dev/null
# recursively remove empty directories
find $TJ -type d -print | xargs rmdir 2>/dev/null
find $TR -type d -print | xargs rmdir 2>/dev/null
fi

Difference between Ant and Maven project structure

Key differences between Ant and Maven

1) Source directory:
Ant: src
Maven: src/main/java and src/main/resources,
Note: Maven is splitting java files from the resource files(.xml, .png, etc). The form files is is still in the java dir.

2) Test directory
Ant: test/unit/src
Maven: src/test/java and src/test/resources

Setting the build number in a netbeans application

In the branding module, add an installer and append the following line.
System.setProperty("netbeans.buildnumber", "1.0")
1.0 is now replacing the default netbeans.buildnumber. This should allways be overridden, since the default just gives the build number of the IDE. The consequences of this is that the the standard machinery imports the buildnumber into the title place holder {0} of the branding bundle file. The title of your program reflects this.
You should get the build number via the jars manifest file and read it from there.
Have also look how to put the build number onto the manifest file.  

Using maven buildnumber plugin tool to insert build number into the jar manifest.



Add the following script to your branding pom


    <scm>
        <connection>scm:svn:<svnurl></connection>
        <url><svnurl></url>
    </scm>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <phase>validate</phase>        
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <doCheck>false</doCheck>
                    <doUpdate>true</doUpdate>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <useDefaultManifestFile>true</useDefaultManifestFile>
                    <archive>
                        <manifestEntries>
                            <Implementation-Build>${prog.version}.${buildNumber}</Implementation-Build>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

The ${prog.version} can be applied in the parent pom's properties as i.e. 1.0. The ${buildnumber} is fetched from the svn using revision head number, hence the scm tag is required. The result is that the property Implementation-Build:<buildnumber> is appended to the branding modules meta-inf/manifest.mf. 
If you want to use the manifest property in the application (i.e in a title), read this 

Force update of local maven repository .m2 in Netbeans

Sometimes it is necessary to downgrade from a snapshot version to a fixed release, requireing a forced update of the m2 folder. In netbeans choose custom goal and run install -U.

Modifying buildnumber of title in netbeans platform application

The following code replaces the parameter placeholder {0} with "1.0" in the main netbeans application title.
public class Installer extends ModuleInstall {
    @Override
    public void restored() {
        System.setProperty("netbeans.buildnumber", "1.0");
}

Read properties from the netbeans module manifest runtime

Here is how to read the netbeans modules manifest run time:


public class Installer extends ModuleInstall {
    @Override
    public void restored() {
    InputStream manifestStream = this.getClass().getClassLoader()
                                 .getResourceAsStream("META-INF/MANIFEST.MF");
    try {
        Manifest manifest = new Manifest(manifestStream);
        Attributes attributes = manifest.getMainAttributes();
        String impVersion = attributes.getValue("Implementation-Build");
        System.out.println(impVersion);
    }
    catch(Exception ex) {
    }
}

Debugging threaded event handlers from gui components make the X system hang

When event handlers from i.e. a combobox are triggered in a debug session, the java 1.6 doesnt play well together with Gnome X system. The grabbing feature of java causes the whole system to hang. To prevent this, the grabbing must be disabled. In a maven project, this can be done by adding the sun.awt.disablegrab=true as run time parameter. in netbeans the prefix -J-D must precede, so the parameter is -J-Dsun.awt.disablegrab=true. In maven this can be applied to the <netbeans.run.params.ide> in nbatctions.xml. Note that to escape from the hang, a TTY (ctrl+alt+f1) with a ps -A | grep java and kill psid and back with Altf7 is needed

Manifest customizing in Maven2

The maven-jar-plugin can be used to customize the main class attribute in the archive manifest, i.e. to be able to run java -jar <jarfile> from the command line:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.mycompany.mavenproject1.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

Skipping tests from maven build in Netbeans

By adding parameter -DskipTests to maven goal install, all tests are skipped from the build process.

How to fix the java double click time at Ubuntu



n your home directory create a file called .Xresources and add the following line
*multiClickTime: 400
Then from the commandline execute
xrdb ~/.Xresources
to make the changes take effect