Thursday, October 14, 2010

Maven troubles on Helios

I created a new working environment on my laptop and checked out my source via clone. After setting up everything i still had troubles deploying my application on glassfish:

|WARNING|glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=23;_ThreadName=http-thread-pool-4848-(1);|java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

Searching in the net i found out that maven on helios has a bug deploying dependencies on helios.
Here the Link:
http://www.eclipse.org/forums/index.php?t=msg&goto=544809&

I installed and checked everything, in the end i had to change this file:
${PROJECT_HOME}/.settings/org.eclipse.wst.common.component
consumes

Saturday, October 09, 2010

Moving from MySQL to Derby

Developing locally i wanted to move my Database from MySQL to Derby on my laptop. Since i use JPA Entities i thought it's an easy task just clicking some menus.

Unfortunately triing to create the Tables from Entities were not as easy as i hoped.

Constraints 'SQL101008073950601' and 'SQL101008073950600' have the same set of columns, which is not allowed.

This was the first Problem i had to fix. Since google (or any other search engine) is the developers best friend i found this bug information:
https://issues.apache.org/jira/browse/DERBY-789?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

This Link is also very informative:
https://forum.hibernate.org/viewtopic.php?f=1&t=998193

In the end it was this little Attribute in Column (unique = true)
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "hi_id", unique = true, nullable = false)
derby column, or type mapping 'VARCHAR(65535)' is not valid
I found this link:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1501
@Column(name = "hi_text", length = 65535)
I had to cut the length to 32000.

Tuesday, August 17, 2010

Hamcrest 1.1 Security Error on Eclipse Gallileo With JMock

Finally i started working on unit tests and already got a gotcha on eclipse galileo with jMock 2.5.1.
Galileo Ships with jUnit 4 but unfortunately without org.hamcrest.TypeSafeMatcher which is needed by jMock.

Adding jMock through Maven still leaves the Problem with Classpath and who comes first.

I tried the following links with no luck:
http://www.southsearepublic.org
http://cedar715.wordpress.com/2009/10/20/86/

Then i removed jUnit Libraries in Project Properties under Java Build Path => Libraries and added jUnit through Maven Dependencies.

Works like a charm now.

Tuesday, July 27, 2010

jPitfalls - Enums in Hibernate

In Hibernate you have two ways defining the association between database fields and Java properties. You can use xml definitions or Annotations.

I for example started with xml and later changed everything to Annotations. Either way, i used jBoss Hibernate Tools in Eclipse for generating the Java Class Files and xml Configuration.

Fortunately both Database and Java have Enums. Unfortunately the Hibernate Tool does not. (don't get me started on Hibernate at this point) So while you may think "Hey, i used Enums in my Database Design because i am a genius" and "That's great, now i can use them in Java" you can't. (Who is the genius).

Using Annotations it's easier. Creating Enums, adding them into the Hibernate Class Files and voila, you have Enums. (But don't forget to maintain them = meaning if you change the Enum in Java or the Database you have to change the other Part two by hand).

Using xml is a complete different Story. You have to Define the Type and adjust it by Hand. There is even a GenericEnumUserType explained in the jBoss Community.

In the end i still think that it should also be possible to create Enums automatically and some day it might, but in the meantime stay sharp and check you Enums.

Linktipps:
http://community.jboss.org/wiki/Java5EnumUserType
http://weblog.dangertree.net/2007/09/23/mapping-java-5-enums-with-hibernate/

Wednesday, July 07, 2010

jPitfalls - log4j adding through maven

One of the first thing a developer want to add is logging. Without logging there is no development. And i mean it... no development.. seriously!

Therefore i looked up in the net which logging Facility i should use and ended up with log4j. (And because all the Tutorials and Books i looked up used it as well). It's really great and flexible. (Enough advertising.)

But being not accustomed to Maven and Dependency Management and everything automatic, i had to learn another hard lesson.

The Thing with log4j is, there are several ways the output can be collected. Console, File, Database, you name it. The Thing with Maven and log4j is, if you add a plugin, it's automatically included and you don't even have to do much more work.

Being accustomed that every little peace has to be configured by hand i was unprepared for the *automaticallywedoeverythingforyou* world. Adding more than one log4j plugin i ended up with no output at all.

Nothing worked and i was starting to gave up my hopes. Fortunately a colleague of mine helped me out (we were sitting together, no clue at all) and found the reason for the misbehavior.

Use only the one output you need, no more than that and everything worked like a charm.

So today's Mantra is "Only use what you need, no more than that" (young grasshopper)

Thanks again

PHP Programmers Way to Java Heaven .. or jPitfalls

That's a nice Title.. or "Typical Java Pitfalls if your a PHP Programmer" or something like that .. in short Java Pitfalls or jPitfalls. (That's a nice short word!)

In short: i started programming in java/eclipse a while ago and decided to write all my troubles down so it might help someone else getting a clue what's happening...

And because my college urged me to do it over half a year.. so here it comes. A complete Series about all my troubles with the Name jPitfalls.

Now i need to tell you a little about the environment of the project i am working on. It's a typical WebShop with Database connectivity serving a handful of people so it's not a big deal. But this are my first baby steps into the wonderful world of compilation, debugging and so much more.

Without any help it's not as easy as it sounds when you need to find the right peace of software for your work. Frameworks, Database Connection, Template System... learn everything from scratch. So i worked my way through Struts 1,2, Spring, Hibernate, Plugins for that Frameworks and of course Eclipse and it's Plugins, unsure where it ends.

Also there was/is the question where will it be hosted. Finding a decent and pricable Hoster isn't easy if you know what technology you are working for. But now it's also a Question if you want an EJB 3 Container or not. Is Tomcat enough or do we need something more extravagant. (Glassfish?)

I ended up in several discussions with myself about the way i should go. (I am still having these discussions, but man, i have gone a long road already) For example the Framework: First i decided to use Struts1 because i thought it's old, so you find a lot of helpful information and it's really complete, nothing beta.

After working hard on the project for several weeks i thought that upgrading to Struts2 would be a good Idea, but not yet. Don't change something important as the Framework in the middle of the implementation cycle. Remember: You want to complete the project asap.

But then some Problems occurred which led to the decision to refactor everything and use Struts2 instead. (It was after all the right decision). In the meantime i use Spring for some parts (as they really work great together) and Hibernate as Database Layer.

My Intention was always to keep it as small as possible and as simple as possible. And for christs sake: Get the job done, will you!

Thursday, January 07, 2010

Could not open the Visual Page Editor: No more handles [Could not detect registered XULRunner to use]

If you have installed the struts tools from the jboss development update site in eclipse under windows and get hit by that error you might want to check if you also installed the xul runner from the jboss update site.

Might save you a lot of troubles and hours of searching what's been happening.

cheers