Posts

Netbeans RCP: external layer.xml

2 min read

A Netbeans RCP application might benefit from an additional layer.xml file stored outside of application bundles. A network directory or a http server may provide some layer.xml with centralized or corporated configuration or user profiles, maintained the network administrator.

This article was first published at techtavern.wordpress.com

There are two solutions to add an additional layer.xml file to your application. Both solutions are provided by Netbeans RCP Toys at github.

LayerProvider

Register a LayerProvider using the @ServiceProvider(service = LayerProvider.class) annotation. The platform calls all LayerProvider.registerLayers(Collection<? super URL>) to populate the collection with URLs to additional layer files. This URL may refer a local file or a remote over HTTP. As this method is called early, your application might not yet know the URL. For example, it does not work for command line argument as they have not been parsed then LayerProvider.registerLayers() is called. This approach is file as long as your URLs are declared as static constants.

SLF4J on Java Google App Engine

1 min read

This article suggest a recipe to configure SLF4J on Google App Engine for Java.

This article was first published at techtavern.wordpress.com

Google App Engine for Java offers a restricted Java 6 API, which includes just the cumbersome Java Utils Logging. Fortunately, SLF4J works as well. The recipe is the standard one. Nearly no configuration is required.

Just add following SLF4J libraries into the applications WEB-INF/lib directory: slfj4-api-1.7.7.jar and slf4j-jdk14-1.7.7.jar (version number may vary). This will redirect all your SLF4J logging statements to the Java Utils Logging controlled by the App Engine.

View TopComponents with icons on Netbeans RCP

2 min read

This article explains an approach to enable tabs with icons to ‘view’ TopComponents.

This article appeared first on techtavern.wordpress.com

The Problem

A typical Netbeans RCP application always displays TopComponents with ‘editor’ mode with their icon and their title, even if the tab runs out of space. Here is an example:

EditorTopComponentTab

Tabs of editor TopComponents

TopComponents with other modes are displayed as ‘views’. Their tabs are extremely simplistic: they never show their icon and their title is shortened or even omitted in case of less space. Here is an example:

Copying from Git to Clearcase

1 min read

This article is about my recent open source project, git-to-clearcase.

There are many old-fashioned IT business that still believe on Clearcase as their software configuration management.

I experienced that Clearcase imposes an extremely complex versioning model, is poorly supported on major IDEs and lacks some elementary features, like simple file undelete. Everything is complicated and slow on Clearcase and crashes happen frequently. Even worse, Clearcase completely fails to support some modern trends, like agile development, lean infrastructure, incremental design and refactoring.

Netbeans Platform: excluding locales from zip and installer distribution

2 min read

This article explains how to prevent Netbeans RCP from packaging unwanted locales into the zip distribution and installers.

This article originally appeared on https://techtavern.wordpress.com

Current situation:

  • The default Netbeans RCP build always includes all localization jars from the harness directory: Russian, Chinese, Japanese and Brazilian Portuguese.
  • Netbeans project properties and branding properties lack configuration to select bundled languages.
  • The build templates did not foresee features to exclude locales.

Problem:

  • Annoying long build times. Proportional to the number of jars, build time increases by five if all default languages are included.
  • Larger distributable artifact size. Localization jars take about 500kB.

Solution:

  • Netbeans Ant build is reasonably organized by build templates. And Ant allows overriding targets inherited from templates.
  • We override the build-zip target. This target generates the .zip distribution artifact, which also serves a input for the installer.

The modified script:

The original build-zip target (netbeans 8.0) is found in the harness directory of your Netbeans installation. We place an adapted copy into the build.xml of your application root directory, thus overriding the behavior of the original target. The red lines were added to prevent adding localization for Russian, Chinese and Japanese.

Google AppEngine on Netbeans 8

2 min read

Even though Google does not officially support Netbeans IDE, it is still possible to develop Google App Engine applications with Netbeans 8.

This article originally appeared on https://techtavern.wordpress.com

There has been a Netbeans plugin for Google App Engine hosted at Kenai, which seems to have been left on its own since June 2009. Fortunately, the project was forked by Gaelyk and who updated the plugin for Netbeans 7.4. I was pleased to confirm that his plugin also works for Netbeans 8.0 and for Google App Engine 1.9.x. And I assure that it work better than that dumb Eclipse Web Tools Platform.

Git Ignore file for Netbeans RCP projects

1 min read

This article suggest a .gitignore file for GIT repositories that keep Netbeans RCP suite and module projects.

For short:

nbproject/private/
build/
dist/

As explained:

  • nbproject/private/ Matches the local, per-user configuration directories, which are suite/nbproject/private for suites and module/nbproject/private for module projects.
  • build/ Matches the module/build and suite/build directories. Modules store their compiled classes within the module/build directory. Suites write shareable artifacts into the module/build directory.
  • dist/ Matches the suite/dist directories, where suites store distributable artifacts like installation programs and java webstart.

If you prefer Eclipse EGit, then add following lines:

Ant task to remove signature from jar file

1 min read

This article suggest an Ant macro that removes the publisher signature from an java .jar file, also known as to ‘unsign’ a jar.


    <macrodef name="unsignjar">
        <attribute name="jarFile" />
        <sequential>
            <jar update="yes"
                 jarfile="@{jarFile}.tmp">
                <zipfileset src="@{jarFile}">
                    <include name="**"/>
                    <exclude name="META-INF/*.SF"/>
                    <exclude name="META-INF/*.DSA"/>
                    <exclude name="META-INF/*.RSA"/>
                </zipfileset>
            </jar>
            <move file="@{jarFile}.tmp" 
                  tofile="@{jarFile}"
                  overwrite="true" />
        </sequential>
    </macrodef>

An example how to call the macro.

Portable Java 8 JDK on Windows

2 min read

Yes, it is possible to extract the Java 8 JDK without administration privileges (a portable Java 8 JDK), although Oracle only provides an installer for windows. This recipe also works for Java 7.

Recipe for JDK 8 (update 93 and newer)

Prerequisite: Install 7-Zip file archiver (or its portable alternative).

  1. Download the Java 8 SDK for Windows from Oracle. You will get a file named like jdk-8u101-windows-x64.exe.
  2. Open the downloaded file with 7-Zip, which will show a a list of files and folders.
  3. Open folder ‘.rsrc’ (select and double click this folder within 7-Zip).
  4. Open folder ‘1033’ (or the folder of greatest size).
  5. Open folder ‘JAVA_CAB10’ (or the folder of greatest size).
  6. Open file ‘111’ (or the folder of greatest size).
  7. Open file ‘tools.zip’.
  8. Extract its contents to a directory where own write permissions, for example: C:\Users\Daniel\Documents\jdk-8u102-x64. To prevent issues, I recommend a directory without spaces.
  9. From within this directory, search for all .pack files and extract them using unpack2000.exe command line tool found in the bin subdirectory. Following windows prompt command does the trick when executed from within the extracted directory: for /r %i in (*.pack) do .\bin\unpack200.exe %i %~pi%~ni.jar

The downloaded .exe file also contains the JDK sources. Navigating through the folders ‘.rsrc’, ‘1033’, ‘JAVA_CAB9’, ‘110’.

Compiling your abstract syntax tree transformation with Netbeans IDE

2 min read

This article explains how to configure the Netbeans IDE to recognize java code the uses compiler internal classes. These classes are not part of the standard JDK and are not recognized by IDEs such as Netbeans, which will refuse to compile the correct code.

The compiler internal classes are used mainly as a hack to define annotations that automatically generate code. The most significant example is the Project Lombok, which transparently generates getters, setters and other code bload. Under the hood, the “Pluggable Annotation Processing API”  (JSR 269) provides a mechanism that exposes internal classes from the java compiler. These classes provide methods that allow us change the abstract syntax tree.