Appliweb

All dimensions of your web developments

Affichage des articles marqués netbeans

A small think appeared to me today, regarding Netbeans.

I noticed that when I run a test for a single file (Right-click on the file, then Test):

The first time the test was running ok, but the second time, I had a strange error from Datanucleus, telling me my classes are wrong….

That was really annoying, so I checked a little bit further this and set debugging option to Maven and to Ant in the settings dialog.

The first time I test the file, I get this:

1
2
3
4
NetBeans: Executing '/mnt/local/files/apache-maven-2.2.1/bin/mvn -Dtest=BasicTest -Dnetbeans.execution=true -debug test-compile surefire:test'
NetBeans:      JAVA_HOME=/mnt/local/files/jdk16+ Error stacktraces are turned on.Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)Java version: 1.6.0_17Java home: /mnt/local/files/jdk1.6.0_17/jreDefault locale: fr_FR, platform encoding: UTF-8OS name: "linux" version: "2.6.32.8-1-jolicloud" arch: "i386" Family: "unix"
[DEBUG]Building Maven user-level plugin registry from: '/home/gerard/.m2/plugin-registry.xml'[DEBUG]Building Maven global-level plugin registry from: '/mnt/local/files/apache-maven-2.2.1/conf/plugin-registry.xml'
Scanning for projects...

Typicall maven stuff.

Now, the second time:

1
2
3
4
5
6
7
Adding reference: ant.PropertyHelper
Detected Java version: 1.6 in: /mnt/local/files/jdk1.6.0_17/jre
Detected OS: Linux
Adding reference: ant.ComponentHelper
Trying to override old definition of task java
 +Datatype java org.apache.tools.ant.module.bridge.impl.ForkedJavaOverride
parsing buildfile jar:file:/mnt/local/files/netbeans-6.8/java3/ant/nblib/org-netbeans-modules-ant-browsetask.jar!/org/netbeans/modules/ant/browsetask/antlib.xml with URI = jar:file:/mnt/local/files/netbeans-6.8/java3/ant/nblib/org-netbeans-modules-ant-browsetask.jar!/org/netbeans/modules/ant/browsetask/antlib.xml
It’s an ant execution !

I don’t know why, but the second time Netbeans is running the unit test with Ant, and no more Maven. How can it be possible ?

What’s the point ? I wouldn’t care less if that didn’t make my test fail….

As Google App. Engine uses a datanucleus plugin for database access, I’ve now switched to it (and leaved Hibernate).

Datanucleus uses bytecode instrumentation for persistance mapping, but not in real time like Hibernate does. Your classes must be enhanced just after compilation.

With maven, it’s not a problem for me, as described here:
http://www.datanucleus.org

Netbeans + Linux + Maven + datanucleus-plugin = hell

Using datanucleus-maven-plugin 1.1.4 (don’t use version 1.1.3 it will force download of Datanucleus 2.0), I get an error when running the compilation under Netbeans.

1.
2.
Embedded error: Error while executing process.
java.io.IOException: error=2, No such file or directory.

I then enable the log for the plugin to see what’s happening, but get no logs. No logs at all…

Of course, nothing in the doc about this problem, so I finally searched the plugin source code:

I see that the plugin is calling « java » directly to process the enhancements. And it seems that when Netbeans calls Maven for compilation, it doesn’t provide the linux path, so the plugin couldn’t start java.

I noticed then a hidden or not-so-documented option, fork, that if set to false, will call directly the bytecode enhancer with no calls to « java ».
Here is the maven configuration to use:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
<plugin>
  <groupId>org.datanucleus</groupId>
  <artifactId>maven-datanucleus-plugin</artifactId>
  <version>1.1.4</version>
  <configuration>
    <fork>false</fork>
    <mappingIncludes>**/*.class</mappingIncludes>
    <api>JPA</api>
    <log4jConfiguration>
      ${basedir}/src/test/resources/log4j.properties
    </log4jConfiguration>
    <verbose>true</verbose>
    <enhancerName>ASM</enhancerName>
    <props>
       ${project.build.testOutputDirectory}/datanucleus.properties
    </props>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.apache.derby</groupId>
      <artifactId>derbyclient</artifactId>
      <version>10.5.3.0_1</version>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.12</version>
    </dependency>
  </dependencies>
</plugin>

So I tried, and this worked like a charm.
PS: The other plugin, schema-create doesn’t have this option, so I have to run it from command line.

My work really consist in making different tools and java framework work together. I need to find solutions so that any developper can understand and use them afterwards.

This time the project involves developing lots of web services, and some batch treatments accessing to a single and complete business model. The business model is defined by an XSD file. This file will often change during the lifetime of the projet, so I need some automatic solutions. I decided to have a library containing the Java classes of the Business Model, and this library will be used by the web services and the batches. I’m using Maven, jaxb2 and jaxws, all under Netbeans, and I will explain how I managed to do that.

Generating jaxb2 beans using Maven:

First, I use the maven jaxb2 plugin to generate the corresponding Java Classes. Netbeans doesn’t support Jaxb2 mapping with Maven (only with ant), so I had to find and modify the pom.xml file manually. Once properly configured (with generated classes under target/generated-sources/xjc), the generated source code is automatically recognized by Netbeans (and greyed so that you know it’s generated, like in the screenshot below).

Creating the WebService:

Next, I create the .wsdl files, I’m not really expert in web services, so I create a web service using Netbeans (with the option to generate a wsdl from java classes), this was an easy way to get the .wsdl. Then I discard the other generated files from Netbeans, and told it to generate again the web service, this time using the .wsdl tweaked to import my Business Model .xsd.

The nice thing with Netbeans 6.7 and Maven, is that Netbeans modifies your maven project when you create a web service. The web service generation is really done by the maven project (using jax:ws plugin) and so is not dependent at all of Netbeans. Using other IDEs, you’ll have to create the web service using the wizards, and then manually modify the Maven project. Below is the modification made by Netbeans to the maven project file:

The problem:

When generating the Java source from the wsdl, the imported xsd is mapped again to Java classes. With the same files than the ones generated by Jaxb2. So I tried to tell the jaxws plugin that the .xsd file was already mapped. Documentation says you can use « episode » files, but this only works if the namespace of the webservice is different from the namespace of the XSD. That was not the case.

One solution is be to re-generate the source code, and delete the duplicated source so that only the classes in the business model project are used. That should work, but I need to keep some generated java classes: The ones from the Web Service itself. So I want to generate the .xsd classes in another package than the classes from the .wsdl (all with the same namespace !!)

The solution:

After lots of trials and errors, I eventually managed to do this by carefully crafting two files: one for jaxb and the other for jaxws, like this:

The content of  bindings-jaxb.xml:

And the content of bindings-jaxw.xml:

I get the web service interface and factory generated  in com.xxx.xxx.ws.mediation.service, and the source code from the business model in com.xxx.xxx.sas.data. It was then really easy to tell maven project to delete duplicates generated source code before compilation.

And as Netbeans compiles using maven, I get this behavior completely integrated into my IDE.

GC.

Following the first post about « using Netbeans for an IDEA user », I would like to add some more informations about maven support.

Skipping unit tests:

Each time I compile my maven project in Netbeans, it runs the unit tests, even for small changes. Fortunately, you can easily tell Netbeans to avoid unit test during compilation. Simply right-click on the project, then select Properties. You can check the « Skip tests » control like in the dialog above:

Importing a maven Web project:

I have successfully opened a Maven project that generates a .war file into Netbeans. It is recognized as a web project, you simply by sets the target application server, and then you can run and debug your web application.

It generates the .war file using Maven, and deploys it automatically to the application server.

The neat feature with Web projects:

It’s easy to use, and great for day-to-day web development: It’s tedious to wait for Maven to generate the war and deploys it each time you modify a .jsp or a .xhtml page. So Netbeans automatically deploy the webapp resources files when you save them. Great ! And IDEA does it too.

s you may know, I was using the trial version of IntelliJ IDEA to develop Appliweb.

Alas, the version expired, so I decided to switch to Netbeans 6.5.1. No I’m not using Eclipse, because I don’t like how it is organized.

I will try to highlight the differences I see between the 2 IDEs.I’ll try to stay neutral, so that you can choose which you prefer.

Today we talk about Maven support:

  • IDEA imports maven pom.xml files to recreate it’s own project, whereas netbeans uses directly the maven files. Netbeans compiles using maven, not IDEA. It imports correctly sub-projects, and sub-sub-projects.
  • Completion in pom.xml file seems to be the same. Maybe Idea completes a little more data.
  • Changes you made in pom.xml files are faster to import in Netbeans. Almost immediate.
  • Netbeans uses Maven when building or Running a Unit test. That’s a good and a bad thing.
  • Good thing: More often than not, you get the unit tests running in your IDE and not in Maven. With Netbeans, you’re sure that it works in maven, hence in the Integration servers.
  • Bad thing: In netbeans, each build runs all the unit tests by default (sloooow), and running a unit test class takes a long time because it is run with maven.

I’m really pleased for now by the overall behavior of Netbeans, kudos for the maven support.

GC.

The Appliweb project will involve lots of Javascript development.

I’m not really a fan of Javascript coding, because:

- I used to do some in 1997-1998, where it was impossible to write javascript compliant with I.E. and Netscape. Even between same versions of I.E. on different desktop you had a different behavior

- No debugger at that time, and very light ones years after.

I really code-as-you-think, so I really need a good debugger to see what’s going on.

I hope that now, years after my previous experiences, I will find some good ones. Here is a list I’ve found:

- FireBug: Waouw, seems to be a great tool, with html and css editor, maybe close to what I would like to do with Appliweb GUI editor. I will try that one first

- Venkman debugger:  I used it in 2005 to fix some hard to find javascript bug in a web application developped in Java Server Faces. It has worked great, but the tool was not pleasant to use.

- Yaldex: Seems only working in Windows, as my development computer is Linux…. It has a free edition though….

- Netbeans: Yep, netbeans, the java IDE. Last version has support for  javascript debugging. As a Java developper I know netbeans well, it’s free, and if the editor/ debugger is ok, maybe I’ll use it. It seems to support debugging under firefox and I.E. A Nice feature for crazy compatibilities issues between these two browsers.

- IntelliJ IDEA: My favourite Java IDE. It now supports javascript debugging too ! I’m sure they’ve done first class support for that, and I would be happy to use it, but it’s not free, and my current company don’t want to buy it…. Too bad really.

Here is a short roundup of the javascript debuggers I stumble upon. If you have any advice (I’m considering myself as a new guy in javascript development), please feel free to insert your remarks. I will test them and give the result in next post….

Bye.

GC.