I'm trying to learn and use Struts 2 (actually migrating from Struts 1 to 2) and I have written lots of java and xml code, which should be working. I just can't run the application! When I try to, I get this exception:
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - jar:file:/C:/Sun/AppServer/domains/domain1/applications/j2ee-apps/Extract_to_cv_2/struts2-core-18.104.22.168.jar!/struts-default.xml:30:72 - bean - jar:file:/C:/Sun/AppServer/domains/domain1/applications/j2ee-apps/Extract_to_cv_2/Extract_to_cv_2-war_war/WEB-INF/lib/struts2-core-22.214.171.124.jar!/struts-default.xml:30:72
As the exception said, I found that the struts-core-126.96.36.199.jar file was located in two places under my application on the server. I tried to remove the topmost copy of the file but when I tried running the app. again I got the same exception, and found that the file had been put back there. Then I tried to remove the struts-core.. file that was further down, but the same thing happened! (the same exception and the file had been returned to that location as well).
I'm using NetBeans 5.5.1 and Sun Java System Application Server 9 and my application is an enterprise application with a web module and an ejb module. I'm wondering whether this problem is due to that I have the struts2 jars in both the lib directory of the ejb module and the lib directory of the web module. This might be stupid, but I needed the ejb module to know about the struts classes as well and didn't know how to make them visible to the whole application.
But then again, this (having struts jars in both modules) actually worked when I was using Struts 1.
I'm really confused about this and I'm hoping that someone can help me! Maybe this is mostly a NetBeans issue so if someone who has used NetBeans could answer it would be great.
I feel completely lost when it comes to this kind of things (what's happening "behind the scenes" in NetBeans and the app. server) but I'm willing to learn from anyone who wants to explain it to me. But please explain it very thoroughly then.
To me the ideal solution would be to refactor your application to remove the dependency on Struts in the EJB layer. The EJB layer is part of the model and in an MVC architecture, the model shouldn't have a dependency on a view framework such as Struts.
If you're not willing to do that, I'd suggest putting the Struts 2 jar files in the EAR file. You can then create a dependency for both the EJB and the web modules on those jar files.
You're right. I shouldn't have a Struts dependency in the EJB layer, so I managed to remove it (and removed all the struts related jars from the lib).
Though, that didn't help (which I was afraid would be the case). I still get the same exception, about the struts2-core-188.8.131.52.jar being in two places and I still can't remove it from either place.
Is there some sort of configuration file somewhere which has a redundant specification of the location of the struts2-core.. file?
Please help me with this!! I have no clue what to do and I really need to move on with and finish this project soon (for financial reasons)!
Joined: Feb 15, 2005
The only other thing I can think of is to look in the Sun App Server's shared libraries and see if any of the struts jar files are declared there.
Joined: Feb 12, 2008
Thanks again, Merrill!
I actually solved that problem. I had been stupid enough to only "Build Main project" and never do "Clean and Build..". When I did that the problem with the two places disappeared. (The struts2-core.. file disappeared from the topmost place on the server)
Now I have run into new Struts problems, but I think that has to be a new thread.