Getting up to speed on Trails

October 18th, 2007

Finally getting up to speed on Trails. Once you have everything setup and don’t touch the running system - it is finally paying off - and results can be achieved really quickly….at least as long as you do not want any extras. Extras usually take some additional time and effort - but the more projects you do and the more code, components and services you can recycle, the more productive web development with Trails becomes.

@trails:NewLink example

October 17th, 2007

If you want to create a new object in Trails, using @trails:NewLink …..tbc

HibernatePersistenceService

October 17th, 2007

I have just had a look for an example how to use the HibernatePersistenceService in trails properly….as I could not find any code, I have tried to do the following:

HibernatePersistenceService service = (HibernatePersistenceService)this.getPersistenceService(); if (service != null){

User user = service.getInstance(User.class);

Unfortunately, this is not working as no User instance is returned - and all successive method calls on user lead to a NullPointerException.

The solution 

The solution is: You simply call the constructor of your data object….you do not need the getInstance() method at all.

Another error was, that the generated hibernate.cfg.xml file has not picked up the new data objects and therefore they were missing in the configuration file. So I have simply edited the file in the classes folder. Later I noticed those objects where not included as some setter methods were missing and so they were ignored….

Trails examples finally working!!!! After 3 days !!!!

October 15th, 2007

Yes! The Trials examples are working now. It has never taken be so long to get something running.

If I look back, there was a whole lot of reasons why it didn’t work.  But if you are about to get going with the Trails examples, do the following:

- Make sure you have Maven > 2.0.6 installed

- Make sure you have JDK 1.5.0 installed and that your JAVA_HOME points to something like: H:\java\sun\sdk\jdk\jre  This means, to the Runtime environment inside the JDK inside the SDK.

Inside the Trails-Hibernate there is a maven pom.xml file that references %JAVA_HOME%\..\lib\tools.jar

So if your path is different, Maven will tell you that you should install tools.jar using:

 mvn install:install-file -DgroupId=com.sun -DartifactId=tools -Dversion=1.5.0 -Dpackaging=jar -Dfile=tools.jar

If you do that, Maven will happily tell you it has installed everything - but you won’t find any com.sun folder inside your repository.

- check out the project on: http://svn.codehaus.org/trails/tags/trails-1.1

After that go to the command line and do a:

  • mvn clean
  • mvn clean install -e > log.txt (so you can look at the errors better later on)
  • mvn eclipse:eclipse

Then import an “already-existing project” into Eclipse inside the examples folder, for instance the Roster example project.

Then go to the project and open the .classpath file and edit it and add the following lines near the end of the file:

    <classpathentry kind=”var” path=”M2_REPO/org/trailsframework/trails-core/1.1/trails-core-1.1.jar”/>
<classpathentry kind=”var” path=”M2_REPO/org/trailsframework/trails-hibernate/1.1/trails-hibernate-1.1.jar”/>
<classpathentry kind=”var” path=”M2_REPO/org/trailsframework/trails-security/1.1/trails-security-1.1.jar”/>

Then close the eclipse project, go to the command line and do a mvn clean again, so that Maven will download the correctly compiled dependencies instead of compiling them wrong from the sources.

Then go back to Eclipse and open the project. If there is still some errors do a mvn install from inside Eclipse.

Remember: If you change the environment variables, close all command line windows as it will not activate the changes until the last command line window has been closed. Also restart Eclipse if you fiddle around with the environment variables.

Trails examples - org.trails.validation.ValidateUniqueAspect and DescriptorInternationalization

October 14th, 2007

After:

- uncommenting all references to  DescriptorInternationalization

- installing JDK 1.5.0 and updating the JAVE_HOME environment variable

- setting CLASSPATH to point to the tools.jar

- removing snapshot servers from the Maven settings.xml

- building the whole project from the command line

- importing all sub-projects in Eclipse as new projects (without copying of course)

… everything seems to be find now.
Except for running one of the examples…Jetty complains that is cannot find the class org.trails.validation.ValidateUniqueAspect

Cannot find the class file for java.lang.Object.

October 14th, 2007

The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project.

This problem is often encountered (especially by beginners). The solution is often quite simply: Just right click on the project, select the properties and then click on the the Java Build path tab. Scroll down to the bottom and change the java system library to Java version or add it if it is not included yet.

Upgrading Maven to 2.07

October 13th, 2007

I was just using the command mvn clean install for the first time, and I got the error message that I need Maven 2.0.6….I was still using Maven 2.0.1 So now I have downloaded Maven 2.0.7 (hopefully it doesn’t matter to have a newer and hopefully even better version), changed my classpaths, closed all DOS windows and trying again to successfully get the Trails samples to work. This time I have also checked out Trails 1.1 instead of 1.1.1 - as 1.1 is the real 1.1.1 version or something confusing….

Ok, Maven has now finished its job - but: still the same problem :-( :

Project ID: com.javaforge.tapestry:tapestry-spring:jar:1.0.0

Reason: Cannot find parent: com.javaforge.tapestry:tapestry-javaforge for projec
t: com.javaforge.tapestry:tapestry-spring:jar:1.0.0 for project com.javaforge.ta
pestry:tapestry-spring:jar:1.0.0

Cannot find parent again!!!!!!!!!!!!!!!!!!!!!! AAAAAAAAAAAAAAAAAAARRRRRRGH

Maven wants to access:

\home\me\.m2\repository\com\javaforg
e\tapestry\tapestry-javaforge\1.0.0-SNAPSHOT\maven-metadata-http:\repo1.maven.or
g\maven2\.xml

but the operating system Windows XP says “no”….. :-(

The solution

I had dodgy SnapShot servers in the Maven settings.xml files

com.erinors.tapestry:tapdoc-project

October 13th, 2007

Just trying to build Trials 1.1.1. Of course, Maven has not completed its job:

Project ID: com.erinors.tapestry:tapdoc-maven-plugin:maven-plugin:0.7.0-20070512.100908-1

Reason: Cannot find parent: com.erinors.tapestry:tapdoc-project for project: com.erinors.tapestry:tapdoc-maven-plugin:maven-plugin:0.7.0-20070512.100908-1

Does Maven do more harm then good ?

October 13th, 2007

In theory, Maven is great. In practice you spend an awful lot of time on:

  • learning how to use it
  • learning how to deal with weird errors
  • waiting for it to finish its job

And now, add together all the time from all those Java developers all over the world.

Isn’t that a lot of time being basically wasted ?

Update 

Ok, once you are through with the learning Curve and once you have setup a local repository, things become a lot easier.

The other day I had to compile and “old” Ant based project - and I must admit Maven is more comfortable to use, once your POM.XML files are setup property:

But still: If your Maven project is working properly, this does not mean that it will never make any problems anymore - suddenly it stops working  and classes are not recognized anymore…and you have to clean your whole repository and build everything again from scratch. So it is a BIT unreliable in my opinion…and Eclipse does not like Maven very much and is playing up all the time (so I always use the command line interface instead).

Why does Maven overwrite itself all the time?

October 13th, 2007

Maven is weird. Every time you launch a Maven target, it keeps on downloading the same stuff all over again - without remembering what is has already in its Repository.

Solution

…the SnapShot Servers!