Wednesday Mar 20, 2013

Set Up Couchbase Java Client Sources in NetBeans IDE

The Couchebase Java Client is a library for other clients to implement. The Couchbase team uses Ant to test and create the JAR, while using both Ivy and Maven for dependency related tasks. In other words, a highly customized project structure. How to set it up in NetBeans IDE? The end goal is this:

I.e., no red error marks, and [which you can't see above], code completion working, as well as compilation of the application. Also, the ability to run single test classes is a requirement.

Therefore, use the Java Free-Form Project Type and point to the root folder of the download, once you've got it from Git:

https://github.com/couchbase/couchbase-java-client 

Spend some time configuring the project, with this end result:

Below, for the Source Packages, select all the JARs from build/ivy/lib/couchbase-client/common. Then, for the Test Packages, select all JARs from build/ivy/lib/couchbase-client/common AND from build/jars/*.jar:

Everything below is defined as you see it by default, except for the mapping of "jar" to Build Project and "mvn-install" to Run Project:

What's great is that all these configurations have no impact on the original build.xml file. Nevertheless, one small, but very important, tweak should be done to the 'clean' target in the build.xml file, so that the "nbproject" file is not deleted when clean target is run. 

Next, let's make it possible to, as requested, provide the ability to run individual test classes. In the project.xml file, add this to the ide-actions section:

<action name="test.single">
    <script>nbproject/ide-file-targets.xml</script>
    <target>run-selected-files-in-test</target>
    <context>
        <property>classname</property>
        <folder>src/test/java</folder>
        <pattern>\.java$</pattern>
        <format>java-name</format>
        <arity>
            <one-file-only/>
        </arity>
    </context>
</action>

Then create a new file named ide-file-targets.xml in the same folder as where project.xml is found and define it as follows:

<?xml version="1.0" encoding="UTF-8"?>
<project basedir=".." name="couchbase-client-IDE">
    <target name='run-selected-files-in-test'>
        <fail unless='classname'>Must set property 'classname'</fail>
        <ant antfile="build.xml" inheritall="false">
            <target name="jar"/>
            <target name="srcjar"/>
            <target name="package"/>
            <target name="mvn-prep"/>
        </ant>
        <junit 
            dir='build/test/classes' 
            printsummary='true' 
            showoutput='true'
            fork='true'>
            <classpath>
                <pathelement path="build/ivy/lib/couchbase-client/common/asm-3.3.1.jar:
build/ivy/lib/couchbase-client/common/cglib-2.2.2.jar:
build/ivy/lib/couchbase-client/common/commons-codec-1.5.jar:
build/ivy/lib/couchbase-client/common/easymock-2.4.jar:
build/ivy/lib/couchbase-client/common/easymockclassextension-2.4.jar:
build/ivy/lib/couchbase-client/common/httpcore-4.1.1.jar:
build/ivy/lib/couchbase-client/common/httpcore-nio-4.1.1.jar:
build/ivy/lib/couchbase-client/common/jettison-1.1.jar:
build/ivy/lib/couchbase-client/common/jmock-1.2.0.jar:
build/ivy/lib/couchbase-client/common/junit-4.7.jar:
build/ivy/lib/couchbase-client/common/junit-addons-1.4.jar:
build/ivy/lib/couchbase-client/common/mockito-all-1.9.5.jar:
build/ivy/lib/couchbase-client/common/netty-3.5.5.Final.jar:
build/ivy/lib/couchbase-client/common/spymemcached-2.8.12.jar:
build/ivy/lib/couchbase-client/common/spymemcached-test-2.8.12.jar:
build/jars/couchbase-client-no-version.jar:
build/jars/couchbase-client-test-no-version.jar"/>
            </classpath>            
            <formatter type='brief' usefile='false'></formatter>
            <formatter type='xml'></formatter>
            <test name='${classname}'></test>
        </junit>
    </target>
</project>

Better than the above is to use "Automatic Projects", which works fine in 7.3:

http://wiki.netbeans.org/AutomaticProjects

http://plugins.netbeans.org/plugin/37522/automatic-projects

I will blog about this soon, works perfectly with Couchbase Java Client Library.

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« March 2013 »
SunMonTueWedThuFriSat
     
10
11
12
13
14
15
18
23
24
27
28
      
Today