Wednesday, June 27, 2012

NetBeans Platform customize app.conf in maven build

This short tutorial describes how to customize the app.conf file of a NetBeans Platform based application in the maven build environment.

Every application developed on top of the NetBeans Platform has a file called app.conf
You will find this file in the generated target folder: app/etc

This file describes some startup and runtime parameter of your NetBeans Platform based application.
Here is a simple example how the generated standard app.conf file could look like:

# ${HOME} will be replaced by user home directory according to platform src/main
default_userdir="${HOME}/.${APPNAME}"
default_mac_userdir="${HOME}/Library/Application Support/${APPNAME}"

# options used by the launcher by default, can be overridden by explicit
# command line switches
default_options="--branding platonframework -J-Xms24m -J-Xmx256m"
# for development purposes you may wish to append: -J-Dnetbeans.logger.console=true -J-ea

# default location of JDK/JRE
#jdkhome="/path/to/jdk"

# clusters' paths separated by path.separator (semicolon on Windows, colon on Unices)
#extra_clusters=
By edditing this file you could for example specify a new jdkhome or start the application with more ore less memory. But when you build your application next time all changes will get lost because the NetBeans Platform build system will update this file too and override it with the default values...

But how to customize this file and tell the build-system not to use the defaults?

The easiest way to customize the file is to copy the current content to a new file called e.g. customized.conf - within this file you can change everything you want to. Then you have to tell the nbm-maven-plugin to use your customized.conf file. Just declare the following in the pom of your app-Module inside the build section:

  
    org.codehaus.mojo
    nbm-maven-plugin     
    true
    
      PATH/TO/customized.conf 
    
  
The nbm-maven-plugin will use your file as copy template when building the application. At the end it will still be called app.conf - but with your custom code inside ;-) Very easy but sometimes hard to google that out...

Tuesday, June 26, 2012

Enable Oracle-Featues in HSQLDB

If you are using HSQLDB for rapid development there is an easy way to enable Oracle-specific features like:
  • DUAL 
  • ROWNUM 
  • NEXTVAL 
  • CURRVAL 
  • ... 
 Just set the Property sql.syntax_ora to true or false (if you would like to disable)
SET DATABASE SQL SYNTAX ORA { TRUE | FALSE }

Without this property you will get a:
java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: DUAL
when executing for example:

SELECT SYSDATE FROM DUAL;

Defining this property in your persistence.xml your javax.persistence.jdbc.url could look like this:

There are of course properties to enable some other vendor-specific database featues for:
  • DB2: sql.syntax_db2 
  • MySQL: sql.syntax_mys
  • MS SQL: sql.syntax_mss 
  • PostgreSQL: sql.syntax_pgs