Automatically start JavaDB process in Eclipse

In my previous post I’ve mentioned that NetBeans IDE starts a background process with Derby every time when it is required during Glassfish startup. You can have a similar thing in Eclipse. After installing Glassfish AS Adapter for Eclipse, go to Window>Preferences>GlassFish preferences (or type “glass” in filter box), check “Start the JavaDB database process when Starting GlassFish server” and voila!

Global Day of Coderetreat in Poznań

Recently, I had a chance to participate in organisation of Poznań’s part of Global Day of Code Retreat. Poznań JUG together with Poznań GTUG (which stands from Google Technology User Group) have organised 2nd Code Retreat in Poznań. Just to remind you, first one was held in January 2011 and resulted (apart from loads of great code) with this awesome movie (thanks to Zbigniew Wantuch).

But let’s get to the merit, our event was a part of Global Day of Code Retreat (GDCR). The idea is simple, on 3rd of December developers from all around the world joins their local Code Retreats to experiment and improve skills in the area of Test Driven Development, Pair programming and clean object design. Gathering 2000 developers and forcing them to deal with Conway’s Game of Life itself is awesome, but it seems that apart from that, Corey Haines (and others) managed to create a real, interesting community around the idea of Code Retreat – which is ultimately awesome ;-) .

Thanks to courtesy of Poznań University of Technology we had a really nice venue for our Code Retreat. Initially I was hoping to get more than 40 but finally we had 35 registered participants, 20 of them managed to get to the event. What’s interesting, only three or four people were attending our first CR.

Most of people who came to CR were familiar with coding in Java, but there were also a few working in Javascript and Ruby. In an announcement I wrote that knowledge about programming in Java is obligatory (as a common denominator) but pairs can work in whatever language they want. It seems that this requirement is not necessary, because mixed-language pairs had a lot of fun.

As for knowledge about TDD and experience in pair programming, most of participants knew that these techniques exist but did not have a chance to practise them in the past. So, during the first two session (and retrospectives) our great facilitators Wojtek Buras (from PSI Polska), Jakub Milkiewicz (from Poznań JUG) and Paweł Stawicki (from Software Mill) had quite a lot to do.

We had 5 sessions:

  • session #1 – No constraints
  • session #2 – Develop a solution to the problem with the constraint that no computers are to be used in the first 10 minutes
  • session #3 – Develop a solution in which no primitives can be used – the solution must be built on classes;
  • session #4 – TDD as you meant it
  • session #5 – No touchpad/mouse, small methods (<5 lines)

During session everything went very smooth (at least IMHO). Apart from great coding session we had really cool retrospectives (people didn’t have any problems to speak about their problems and discuss).

When we will organise CR next time we will surely add one more session (maybe even two). I have also my personal wish list of constraints ;-) :

  • while reading notes from hosts of other CR I saw that silent session (or Mute Evil Pair) was really funny one. In this exercise developers are not allowed to speak, they can only communicate through code.
  • Another interesting idea is legacy code session. After the previous session ends no one is allowed to delete code (!), instead of swapping pairs, people swap their workstations.
  • No loops/no conditionals because this sounds like a real challenge ;-)

Considering that everyone is asking when we will have next CR it seems that we had really successful workshop ;-) . Pictures from CR are available here.

Big thanks to Łukasz Stachowiak and Daniel Mendalka for their organisational effort – thanks guys!

Sniffers

This is a quite old post, it was not published earlier because I wanted to investigate this topic a bit more. Hope that you will find this useful (and not very misleading).

SEVERE: Exception while deploying the app [arquillian-example] :
  Sniffers with type [connector] and type [ejb] should not claim the archive at the same time.
  Please check the packaging of your archive [/..../arquillian-example]

Maybe some of you’ve experienced this kind of error while working with Glassfish. I had this one when started to work with new project (Maven driven, JEE 6 app with Arquillian/JUnit and Glassfish embedded). Project structure was taken from my previous developments, I’ve added literally one class. First deployment and this quite cryptic error message stopped my work.

While looking for some hints, I’ve learned that sniffers are analyzing archive submitted to application server. If you take a look into domain.xml in your Glassfish instance you will find that applications (applications/application) can have various sniffers associated with them e.g.

<applications>
 <application context-root="/test" location="${com.sun.aas.instanceRootURI}/eclipseApps/test/"
           name="test" directory-deployed="true" object-type="user">
    <property name="appLocation" value="${com.sun.aas.instanceRootURI}/eclipseApps/test/"></property>
    <property name="keepSessions" value="true"></property>
    <property name="defaultAppName" value="test"></property>
    <module name="test">
       <engine sniffer="jpa"></engine>
       <engine sniffer="security"></engine>
       <engine sniffer="web"></engine>
       <engine sniffer="weld"></engine>
    </module>
</application>

This app has JPA/security/web and Weld. From the error message it seems that some sniffers cannot be assigned together with others.

To find out what is going on, I took a look at what is placed in the final WAR. I discovered that Maven is adding glassfish-emb-all.jar to WEB-INF/lib. Quick look at pom.xml and it looks that dependency to glassfish-emb was not properly scoped (lack of <scope>test</scope>). Without glassfish-emb in war everything went smoothly, app was properly deployed.

Oh, well just a stupid mistake in pom. But wait. What is especially interesting in this issue, it seems that sniffers assigment is done only once. This means that if you deploy your app with correct dependencies and afterwards you will accidentaly include glassfish-emb-all into your WAR everything will be fine. At least till the next change of application server which might happen when moving to production web server.

24 easy steps to JEE 6 development with Eclipse

As some of you probably know I have a privilege to teach Java related stuff at Poznań University of Technology. During the lab sessions which I am leading we were going through configuration of Eclipse IDE to work with JEE 6. I am using Eclipse since I started to write in Java, some things are obvious for me. We wanted to work with Glassfish, Apache Maven and Subversion which are quite common tools, so it should be quite simple to force Eclipse to work with this setup. Let’s start.

  1. Download Eclipse IDE for Java EE Developers
  2. Unpack and run
  3. Now, I will have to install m2eclipse, I would like to use Eclipse Marketplace because it does not require knowledge about update sites for plugins. So, I choose “Help” and than “Eclipse Marketplace”.
  4. I am searching for m2eclipse… ok, there is something with Install button here [click].
  5. Accept the license agreement
  6. Confirm that I want to install unsigned jars
  7. Installation was sucessful, Eclipse is asking if I want to restart IDE – “ok, if you have to”.
  8. I know that I need also m2eclipse-extras for integration with Eclipse Web Tools Platform.
  9. I am choosing Eclipse Marketplace and searching for m2eclipse-extras – without luck.
  10. It seems that I need an update site for this. From Help menu I am choosing “Install new software”
  11. Starting to work with new Update Site for m2eclipse-extras
  12. I need to choose out of 4 bundles from that site. I cannot click “select all” because I don’t have Sublipse plugin installed, anyway who is using SVN nowadays? ;-)
  13. After choosing right bundles it is time to accept license agreement
  14. Once again I need to confirm that I want to install unsigned jars
  15. Installation was sucessful, Eclipse is asking if I want to restart IDE – “ok, if you have to”.
  16. It is high time to import my project into workspace, choose File>Import>Import existing Maven project (but who knows maybe “Import existing project” would also work ;-) )
  17. At this stage m2eclipse shows warning that my Eclipse is running on JRE not JDK and this may cause some problems
  18. To correct this I have to edit eclipse.ini and add “-vm” parameter with path to JDK (in separate lines – but everyone knows how .ini file works)
  19. Ok, now it is time for Glassfish, I choose Window>Preferences>Server Runtime and click on Add button
  20. There is no Glassfish here, so I choose to download additional server adapters.
  21. Ok, now I can choose out of four different Glassfish types (finally I will choose appropriate).
  22. During creation of new server runtime, I have to remember to point to glassfish-3.1/glassfish, (base glassfish-3.1 directory is not enough).
  23. After creation of new adapter, it should be possible to run imported application using Glassfish. It should be but…
  24. Eclipse says that in order to run Glassfish I need JDK – what the heck, I’ve just changed my eclipse.ini. Someone told me that I have to define new “Installed JRE” which is pointing to my JDK installation.

Only 24 easy steps – great!  ;-)

I’m not a huge fan of NetBeans but please take a look how NetBeans IDE deals with this issue.

  1. Download NetBeans (with Glassfish)
  2. Run NetBeans and Glassfish installer
  3. Run NetBeans IDE
  4. From File menu choose Open project
  5. From Tools menu choose Servers, ensure that Glassfish is in place. (This step is unfortunately necessary :( , without this NetBeans claims that there is no Glassfish defined – you just have to open dialog window, nothing more).
  6. Run Project

NetBeans will even launch Derby network server on its own if you use this DB in your project. I do not have nothing against Eclipse puzzles but it seems that it simply works!

I know why all this have to be done with Eclipse, but the question is who will bother with this if he can just launch Visual Studio ;-) . In fact it is just a matter of reasonable defaults, is it really so hard? Maybe JEE is too new to get proper support in Eclipse?

Tesseract 3.0 installation on Ubuntu 10.10 server

This is a cross-post, original post can be found here.

Tesseract is an optical character recognition (OCR) engine originally developed by Hewlett Packard, in 2005 it was open sourced under Apache license. Its development is now supported by Google. Version 3.0 was released in September 2010 apart from other things this version offers support for Polish language.

Wiki at Tesseract website is a bit messy, that is why I decided to describe my experience with building and installation of Tesseract 3.0. I was working on Ubuntu 10.10 server edition, deployed on virtual machine created using Oracle Virtual Box.

First, I’ve install build-essential and autoconf:

sudo apt-get install build-essential
sudo apt-get install autoconf

Next, step according to Tesseract wiki is to install dependencies:

sudo apt-get install libpng12-dev
sudo apt-get install libjpeg62-dev
sudo apt-get install libtiff4-dev
sudo apt-get install zlib1g-dev

Please note, that the name of zlib1g-dev package is misspelled in the wiki.

I have downloaded sources of Leptonica 1.6.7 from its Google Code website and than followed rather standard build process (you may also try to install libleptonica-dev package instead):

./configure
make
sudo make install
sudo ldconfig

The next step was downloading tesseract-3.00.tar.gz from Tesseract project website. Uncompress archive, go to tesseract-3.0 directory and invoke:

./runautoconf
./configure

After invoking ./configure you should check config_auto.h if dependencies were recognized correctly by ./configure script. Header file should contain #define for HAVE_LIBLEPT, HAVE_LIBPNG, HAVE_LIBTIFF, HAVE_LIBJPEG and HAVE_ZLIB.

make
sudo make install
sudo ldconfig

Without ldconfig you might experience problems with launching Tesseract.

Download languages of your choice from Tesseract website and place them (uncompress first) in your tessdata folder (by default /usr/local/share/tessdata).

Now run the OCR using:

tesseract phototest.tiff out.txt -l eng
more out.txt

Hope that this was helpful.

Update (19th of October 2011):
I was trying to complie revision 627 of Tessearct on my Ubuntu 11.04, after compilation of Leptonica, and invoking ./configure for Tesseract source code I was still getting “leptonica library missing” error. Everything went smoothly after adding, these two lines in the beginning of the configure file.

CPPFLAGS="-I/usr/local/include"
LDFLAGS="-L/usr/local/lib"

This solution was found here – thank you.

Videos from Poznań NetBeans Platform Training 2010

It took me a while, but finally I managed to publish two videos from NetBeans Platform Training which was held in January 2010 in Poznań. If you are interested in NetBeans Platform Services Architecture take a look at these two great lectures delivered by Toni Epple:

  • NetBeans platform Service Architecture (1) – Lookups
  • NetBeans platform Service Architecture (2) – Registry

More details about this remarkable event can be found at Poznań JUG website.

Algorithms of the intelligent web – review

Thanks to MEAP and Poznań JUG I had a chance to read “Algorithms of the intelligent web” by Haralambos Marmanis and Dmitry Babenko. Content is organized into seven chapters, starting with general introduction which gives a broad overview of state-of-art in the field of modern web application. Second chapter offers a few bites of theory and finally practical example of building simple search engine. You can also find information about using classifiers, creation of recommendation systems and document clustering. Final chapter presents complete example of news portal which incorporate all introduced techniques in neat working solution.

Chapters from two to six have similar structure, starting with some theory necessary to understand presented concepts, then some clear examples presenting real word usage. Examples are extended with some additional more advanced features but everything is still perfectly understandable. Readers would learn how to adopt existing APIs (eg. digg.com), how to aggregate and transform content in order to create innovative mashups. After practical part, readers will find some notions about usage of presented solution in production. Authors describes common mistakes which leads to dead ends during implementation of modern intelligent web applications and this is definitely one of the biggest advantages of this book. What is also worth to mention, Marmanis and Babenko emphasize the role of quality of results and show general ways in which one can evaluate obtained outcome. At the end of each chapter readers can find TODOs, a section with tasks that maybe done in order to utilize presented solutions better.

All examples are delivered in BeansShell and Java. Nowadays, in the age of frameworks like Grails or Ruby on Rails the choice of BeanShell is quite unexpected. Examples in JRuby or Groovy could simplify adoption of presented solutions in real life web applications. But this is a minor thing, BeanShell is very similar to Java, so none Java developer should have problems with understanding examples. In MEAP-copy of book which I have evaluated there was also no information about how to run presented examples nor that knowledge about Java or BeanShell are required. I hope that would be improved in final release of book (from that what I’ve read in answer to my feedback those issues were addressed in final version). Authors presents quite a few open source libraries which can be easily use not only during creation of intelligent web applications but also in everyday work of Java developer.

What’s missing? I would love to read more about OpenSocial API which is only mentioned in first chapter of the book. Another thing that is missing are some references to so called Web 3.0, I’m constantly looking for a comprehensive overview of semantic web applications (eg. OpenCalais, Hakia). Creating a small semantic enabled application would definitely be a plus.

„Algorithms of the intelligent web” is definitely worth to recommend to all developers who want to gain knowledge about some useful Information retrieval and Machine learning techniques. Those techniques are presented in a very clear and understandable way. Book contains universal methods and algorithms, knowledge like this does not get old so fast (like for example web frameworks). I would definitely come back and read this book again.