Archive

Archive for November, 2008

JavaFX – Some Clarifications

22 November, 2008 Leave a comment

JavaFX Script, puh! What a hype you might think, as I thought some weeks ago. I have some tears in my eyes while reading that Sun is not really improving good old Swing. Instead they push a lot of energy and money into JavaFX.

Are this bad news?

I will put here some facts, my notes, my thoughts and some links to give you a basis for your next JavaFX program.

Some Facts

  • JavaFX 1.0 is still not released. It should be released on 2nd December (integrated in NetBeans 6.5). (I am a bit confused about the versioning terms but the current version should be 1.0 pre1)
  • You will be happy with the current version of JavaFX only if you use NetBeans 6.1 (!), Java 1.6 and Windows or Max OS for development. But this means: your clients will need a jvm like they do for Swing!
  • The current version of JavaFX is under GPL
  • JavaFX is not Java but you can mix it with Java. See the language introduction. JavaFX is a declarative programming language. E.g. the initialization is in the style of json (->yaml).
  • Be sure you read the migration guide before googling for examples! And use the shipped examples in the current version as starting point. (They switched from interpreter version to OpenJFX compiler)
  • Project Nile tries to exports a layered graphic from Adobe Illustrator (into JavaFX code). The projects offers libraries to import the exported files as well. It also provides a SVG converter.

The first intention of JavaFX is to improve Swing (not only in my opinion, see from page 22). But Swing could be improved only in two ways

  1. improve the library and merge awt, swing, java2d and more (1,2) into one consistent library WITHOUT breaking backward compatibility
  2. and enhance the language to provide such nice features like property binding (via bind)

Nice features in the programming language JavaFX or the API

  • ruby style durations: Duration t = 2m + 20s;
  • C# style operations: insert, delete … and this is nice:
    for (element in group where element.length() < 4) {
    println({element});
    }
  • // localization
    var localizer = StringLocalizer{ key: “Hello, World!” };
    // This prints localized text for “Hello, World!” for the default locale
    System.out.println(localizer.localizedString);
  • javafx can still be used as interpreted language: FXEvaluator().eval(String)
  • … a lot more!

Some drawbacks of JavaFX (only the current version?):

  • GPL
  • no tables or tableNodes!? use this. Where is the Table and TableColumn gone?
  • println(String); does not work although documented in the api. You will need to use System.out.println(String) + import java.lang.System.
  • The Photoshop exporter is not properly working for me. The .fx file does compile and even after I changed some lines the created UI looks damaged.

Conclusion

JavaFX is a great language which offers some nice features. But the current version is far from perfect and you should wait until the final release in December. But then: try it out! Hopefully they will made a linux version for me ;-)

Ressources

  • Download JavaFX bundled with NetBeans 6.1
  • In NetBeans (with the JavaFX plugin) go to help->javadoc references->JavaFX Script Documentation
  • https://openjfx.dev.java.net/JavaFX_Programming_Language.html
  • http://java.sun.com/features/#javafx
  • https://openjfx.dev.java.net/
  • http://javafx.netbeans.org/
  • http://learnjavafx.typepad.com/weblog/2008/08/tablenode-creat.html
  • http://jfx.wikia.com/wiki/Code_Examples
  • http://jfx.wikia.com/wiki/Demos
  • QA: http://java.sun.com/developer/community/askxprt/sessions/2008/jl0818.jsp
  • http://java.sun.com/javafx/tutorials/project_nile_integrating_graphics/
  • clock example: http://java.sun.com/javafx/tutorials/simple_javafx_nb_app/
  • svg to fx: http://www.javaworld.com/javaworld/jw-11-2008/jw-11-jump-into-jfx-1.html?page=5
  • a lot of (outdated!) examples: https://openjfx.dev.java.net/learning.html
  • http://learnjavafx.typepad.com/
  • http://widgetfx.org/

5-Line-Replacement of Apache Ant

20 November, 2008 6 comments
rm -rf build/
mkdir build
jars=$(find ./lib/ -iname "*.jar" | trĀ  '\n' ':')
find ./src -iname "*\.java" > files.txt
$JAVAC_CMD -d build/ -cp $jars @files.txt

Okay, it is a very very unfair blog title – only an eye catcher!

But now you can bookmark this useful code snippet to compile your project without installing ant or even an IDE.

… and you could say: “Hey man – this is not platform independent!”.
But then I would say: “Oh yes it is! For windows you should install cygwin of course!”

Keep smiling ;-)

Update: on windows with cygwin you have to replace the colon : with a semicolon ;

NetBeans 6.5 released

19 November, 2008 Leave a comment

Look here to download the release and here for all the new features.

If you are looking for the early access version for phyton development click here.

good to know about ubuntu (x-mas time)

12 November, 2008 Leave a comment

Did you know that you could run ubuntu directly from windows? No? Then try out wubi!

And check out the following pages if you already are an interested (k)ubuntu user:

  • Playing DVDs, flash etc was a nightmare under suse 10.1. Under ubuntu > 8.04 it is a one-liner:
    sudo apt-get install ubuntu-restricted-extras

    Taken from here.

  • With VirtualBox you could try out new releases of ubuntu (or other OS’s). I used version 1.6.6 from here – the latest .deb package didn’t work for me.
  • Did you ever want your own customized ubuntu? Yes, the the following pages/projects are for you
  • UCK“is a tool that helps you customizing official Ubuntu Live CDs to your needs. You can add any package to the live system, for example language packs, or applications.” – taken from the website.
  • Very good tutorial to create your customized LiveCD. I tried it – really nice. In this way you can ‘present’ somebody with linux software ;-)

Hope you have other ideas/pages for ubuntu and x-mas!

Hints for Mavenization of Java Web Applications

10 November, 2008 Leave a comment

I discovered that it is not that easy to transform a web application from a native eclipse/netbeans project to a maven project.

Here are some hints which can make your life easier:

  1. To create the project structure for the web application use this command:
    mvn archetype:create -DgroupId=de.mycompany.app123 -DartifactId=mywebapp -DarchetypeArtifactId=maven-archetype-webapp
    Be sure you replaced the 2.3 header with
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    this was helpful for fixing this issue:
    "The selected Java EE version does not support selected JavaServer Faces version" + restart netbeans!
  2. To use jdk 1.6 do
    <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.1</version>
    <configuration>
    <source>1.6</source>
    <target>1.6</target>

    <encoding>UTF-8</encoding>
    </configuration>
    </plugin>
    Maybe for you it is necessary to use tomcat 5.5 for myfaces 1.1. Therefor you probably have to change the <source> element to 1.5 … Here you can determine the class format version
  3. use
    <repositories>
    <repository>
    <id>java.net</id>
    <name>java.net</name>
    <url>http://download.java.net/maven/2/</url>
    </repository>
    </repositories>
    for the missing dependency in hibernate org.hibernate:hibernate:jar:3.2.1.ga: javax.transaction:jta:jar:1.0.1B
  4. All libraries which you need at compile time but not on the server (like the following) should get an scope=provided
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
    </dependency>
  5. All libraries which you need for your tests (e.g. junit or hsqldb) should get an scope=test
    <dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>1.1.102</version>
    <scope>test</scope>
    </dependency>
  6. If your tests are temporarly broken or if you want to speed up testing do:
    <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.4.3</version>
    <configuration>
    <skip>true</skip>
    </configuration>
    </plugin>
    (See this post for a better solution.)
  7. To invoke the tomcat plugin (‘mvn tomcat:run’) the following code can be necessary
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>tomcat-maven-plugin</artifactId>
    <configuration>
    <url>http://localhost:8080/webapp/</url>
    </configuration>
    </plugin>
    This plugin uses tomcat5.5, to use tomcat 6.0 compile it for yourself or run the project from within your IDE with maven plugins.
  8. To invoke the jetty plugin (‘mvn jetty:run’) the following code can be necessary
    <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.10</version>
    </plugin>
  9. You get an exception like the following in NetBeans??
    [ERROR]Runtime Exception thrown during execution
    [ERROR]null

    Solution 1 -> use external maven (command line)
    Solution 2 -> try to recompile the project from command line
    Solution 3 -> try to recompile another maven project + restart the IDE (works only sometimes)

  10. if you want to mavenize jar files -you can use this
  11. to set up you own maven repository you can try this tutorial
  12. And last but not least: Be Warned!

Read the following hints if you are an IDE-guy

  • Install the NetBeans plugin. Installation of this is easy -> Options->Plugins->Install Maven Plugin. To use this plugin simply open the pom.xml directly.
  • Installation of the EclipsePlugin:
    • install tomcat 6.0 server (>6.0.16)
    • you will need WTP >2.0.2
    • add http://m2eclipse.sonatype.org/update/ to your update pages; I didn’t tried q4e
    • and install m2eclipse
    • select the necessary packages (scm and mylyn didn’t worked for me …)
    • if not already done add a jdk as default virtual machine to eclipse
    • specify the same java exe in the eclipse.ini file:
      -vm
      C:\Program Files\Java\jdk1.6.0_07\jre\bin\javaw.exe
    • restart eclipse

Some people want to avoid the stuff related to IDEs – they can!

  • Install maven2
    • Under debian you can simply ‘apt-get install maven’.
    • Under windows you have to add the bin folder of maven to the PATH variable.
  • Type the following in the root directory
    1. mvn install
    2. mvn tomcat:run
  • Then go to http://localhost:8080/yourapp/ with you favorite firefox ;-)

Now, my two questions to the readers are:

  • How can change the default tomcat-users.xml under target/tomcat? (for the command ‘mvn tomcat:run’)
    If I would require the user to login (security-constraints in the web.xml) I cannot login …
  • How can I use a master (or parent) module with web applications? I need an example! I already have one for a desktop application.

Skip Executing the Tests of Mavenized Projects

10 November, 2008 1 comment

In my project I want to skip that the tests are running on every execution. I know this is not ‘good style’, but I want to execute the tests when I want. I do not recommend this technic on you build server …

One way to achieve this behaviour is to disable the tests in the

<build><plugins>

</plugins><build>

section via

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

But now even if we want to run the tests explicitly they will be skipped. Is there a solution for this?

I found a better and very simply solution for NetBeans. Right click the mavenized project in NetBeans, then click on Actions. Now click on an entry; e.g. Run project and select “Skip tests”. This cheat you can apply on all the listed actions (even customized one …).

Do you have a more IDE-independend solution for this?