Thursday, December 10, 2009

Struts2 ActionErrors not being cleared Validation error messages

phew!

This is one of the hardest problems I've ever faced. The sad part it it does not deserve to be there.

 If the action errors or error messages that you are adding for validation purposes or error indication purposes are not getting cleared, this solution may just get you out of the hole. This is valid only if you are using Spring with Struts2


Solution:

In the action class's Spring configuration make the scope as prototype for Action classes! If Action classes are Singleton which by default the instantiation mode in Spring, error messages stick to the action and you will never get rid of it. You've got problems with that behaviour? Ask the Workflow interceptor.

One of the banes of working on a framework with a beginner's/intermediate knowledge.

cannot find symbol location: org.apache.maven.ProjectBuildFailureException

This is another wierd error I faced while trying to debug on of the other hardest problems I've faced(whose entry will surely be here when I solve it).

I am using m2eclipse with appfuse(struts2+Hibernate + Spring) modular application. After adding a new action class (into the web module)and a new Model class(into the core module), eclipse did not show me any compiler errors. Everything was as fine as it could get untill I invoked the mvn clean install using m2eclipse.

Unwittingly Maven was not able to find my model class that was referenced from the Action class. These are the kind of errors which you know the moment you see it that it is very weird.

Solution:

Well, my solution may not work for you, all I did was:

invoke the command I was trying from m2eclipse(i.e mvn clean install -Dmaven.test.skip) from command line. It went fine from the command line after which i tried through m2eclipse and it worked fine there asl well. Inexplicable, but thank god!

Tuesday, December 8, 2009

m2eclipse The project was not built since its build path is incomplete. Fix the build path then try building this project

There could be several reasons for the occurence of this error message. It happened to me when I switched from using mvn eclipse:eclipse to m2eclipse.

Solution:

Go to the project directories and delete:
1) .setting folder
2).project file
3).classpath file

Import the project again afresh.

m2eclipse Error starting Sun's native2ascii java.lang.ClassNotFoundException: sun.tools.native2ascii.Main

In my case tolls.jar was not accessible to Maven/Eclipse.

Solution(which worked for me):

1)GoTo Eclipse configure build path
2)edit Jre library
3)Add external jars
4) select tools.jar which should be present in Java_home/lib

Before you do this I would suggest you to check your JAVA_HOME variable if it is pointing to a jre, make it point to a JDK. That should do the trick. 


Other helpful links:

http://markmail.org/message/szty6nkfdxmkadyc#query:m2eclipse%20Error%20starting%20Sun%27s%20native2ascii%20java.lang.ClassNotFoundException%3A%20sun.tools.native2ascii.Main+page:1+mid:6gxxf3jvbaaxnbtf+state:results

http://johnjianfang.blogspot.com/2009/03/orgappfusearchetypes.html

Friday, December 4, 2009

java.lang.IllegalArgumentException: can only set expectations on mock objects

This is a wierd error which really does not have a prescriptive solution. When it occured to me I just meddling with the Test Code adding the @After annotation along with a tearDown method which was not there earlier. Magically it worked. It now works even without a @After method.

My environment is a class that extends BaseManagerMockTestCase from Appfuse. Other threads that are out there do not give a complete solution either:

http://markmail.org/thread/wuom2q6mshwz247y#query:java.lang.IllegalArgumentException%3A%20can%20only%20set%20expectations%20on%20mock%20objects+page:1+mid:pzyjgutuwksexjxe+state:results