7 Replies Latest reply on Jul 15, 2010 2:47 PM by Andy Gibson

    Weld Examples, JBoss 6 Milestones and Frustration

    Heiko Kopp Newbie

      Hello everybody,


      as a new project is currently in its early stages I've thought to myself, why not trying out Weld and CDI together with JBoss 6. Now, after about one week of continuously failures, exceptions and errors I'm almost ready to give up the try and give the exciting new technology another year to evolve. This post in the forum is just to summarize the problems I had when trying out to build a VERY simple Weld/CDI based program. Indeed it was not even my idea, I simply tried to adopt the NumberGuess example, well known and already ported to Weld for JSF, Wicket and even Java SE.


      My frustration become even bigger as it currently seems to be impossible to use JBoss 6 (not even the SNAPSHOT version) with Weld/CDI and JSF 2.0, I know it is a milestone release, but the overal examples on the Weld part of this very website suggest it is SOOOOO EASY to use it. I agree, there are a lot of examples, but what does it help if none of them work?

      I'm missing a really step-by-step example, helping somebody like me to learn his first steps with weld. And I would appreciate if not only the code base is fixed but the documentation too. I would even help if thats wanted, not taking myself out of the focus here.


      Let me summarize:


      I implemented a simple EAR and a dynamic Web-Project inside it. I configured the faces-config.xml, the web.xml as well as the application.xml to be appropriate for deployment on JBoss 6.


      My web.xml looks like this:


        <display-name>Numberguess example</display-name>
        
        <context-param>
          <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
          <param-value>.xhtml</param-value>
        </context-param>
        
        <servlet>
          <servlet-name>Faces Servlet</servlet-name>
          <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
          <load-on-startup>1</load-on-startup>
        </servlet>
        
        <servlet-mapping>
          <servlet-name>Faces Servlet</servlet-name>
          <url-pattern>*.jsf</url-pattern>
        </servlet-mapping>
        
        <session-config>
          <session-timeout>10</session-timeout>
        </session-config>
        
        <welcome-file-list>
          <welcome-file>index.html</welcome-file>
        </welcome-file-list>



      I then adapted the NumberGuess example and carefully included them in my web project. Now the problems start:


      Where do I have to put the required libraries in my project for JSF or Weld to compile and what libraries to i need? Weld itself, JSF API and/or IMPL?


      I tried putting JSF API and IMPL into a library of my EAR. This lead to JBAS-8035, raising a nice exception like:


      java.lang.NoClassDefFoundError: javax/faces/application/ApplicationFactory



      Well there is no real solution for this problem, is there? So that means JBoss 6 is not capable of handling any Weld code right now, right? I read something about put them in your Web projects WEB-INF/lib folder. Ok, I did that, guess what, I ended up with the same error message. I put them in both, the EAR and the Web, same problem.


      What would you suggest to do to get familiar with Weld and not with errors in it? Is Glassfish right now maybe a better solution although our current projects all run well on JBoss.


      Would you personally start with Weld right now or continue to stay the old line (especially Seam 2).


      Our project is still a good 6 months away and thus I would be able to say, lets move to CDI, its worth it ... but currently, it is not possible.


      Best regards,


      Heiko


        • 1. Re: Weld Examples, JBoss 6 Milestones and Frustration
          Nicklas Karlsson Master

          What a coincidence I just wrote this today ;-)


          But to some of your problems. Don't include any Weld/JSF libraries in your application. The appserver has them. Including them will result in - yep - strange classloading problems etc.

          • 2. Re: Weld Examples, JBoss 6 Milestones and Frustration
            Ian R Newbie

            If it helps, I'm no Sun/Oracle/JBoss person and I'm about to deploy a JSF/Weld application into the wild! So it can be done. I'm waiting for the next JBoss release (M4) before attempting to do a production release (see below as to why). I won't say it is the most complex application out there, but it is using JSF/JPA/JMS/EJB so it isn't trivial either.


            If you intend to use JBoss 6.0.0-M3 (or M2 - that's what I'm using), here are some caveats:



            • Upgrade the version of JSF included in JBoss. I'm using 2.0.3-SNAPSHOT, just waiting on the final 2.0.3 release. 2.0.2 has fatal bugs in it. M4 might contain 2.0.3 in it, depending on the two release dates.




            • You must upgrade the version of Weld in JBoss to 1.0.1-Final. There is a post that shows how to do this. The next release of M4 should include at least 1.0.1-Final, and may well have 1.0.2 in it (hint hint, Peter etc!!!!!)




            • There are JMS issues with M2 and M3, which have really affected the way I do things. They are very bad in M2, bad in M3 and I'm hoping will be fixed by M4. If you find problems, just log lots of JIRA issues like I have - I know some of them have been fixed.




            • Some of the standard Servlet related components don't have injection enabled. I think that's because the standard doesn't require it. I know that is being worked on too.



            Nicklas' advice is also correct too - don't include the libraries, remember they are part of a JEE6 server.


            And if you have a specific problem, people here have been there/done that - so we'll try to help!


            Regards,


            Ian

            • 3. Re: Weld Examples, JBoss 6 Milestones and Frustration
              Pete Muir Master

              It's looking very unlikely that we will get 1.0.2 in M4, but this will make it into CR1 of AS 6 :-)

              • 4. Re: Weld Examples, JBoss 6 Milestones and Frustration
                Ian R Newbie

                No issue Peter - as long as CR1 is coming out around June 22 there's no problem :-)


                The main thing that kills me at the moment is the JMS issues, but they're part of the integration project so I guess that's part of a different timeline.

                • 5. Re: Weld Examples, JBoss 6 Milestones and Frustration
                  Ian R Newbie

                  Pete, given that there is no definite date on M4 now how's 1.0.2 tracking? Can it make M4, assuming that it's a few weeks away?

                  • 6. Re: Weld Examples, JBoss 6 Milestones and Frustration
                    Cloves Almeida Newbie

                    Everything is too experimental and for a 6-month project, I wouldn't recommend using it. Go for the mature Seam2+JSF1 combination and when the time arrives porting it to Seam3+JSF2 should be a breeze.


                    However, I've been using it for some pet projects and has been working nice with a few adjustments. If you really want to use CDI, I recommend dropping JSF2. IMO, it's the least mature of the technologies and you have very capable alternatives. Check Wicket, Vaadin or even a pure client-side alternative+REST/Remoting.

                    • 7. Re: Weld Examples, JBoss 6 Milestones and Frustration
                      Andy Gibson Novice

                      I agree in general with the sentiments, but it is possible to get apps working with an out of the box Milestone 3 release of JBoss.


                      In general, I find that the more configuration and boilerplate stuff you do yourself means more chance of messing things up and no clues on where the problem is. I think your first problem is trying to structure the app yourself instead of using something like maven.


                      It is a long and frustrating road right now, and even Glassfish is using a broken version of Weld. I have written out some steps for updating Glassfish to Weld 1.0.1 as part of my Knappsack Maven Archetypes project which is based on the Weld Archetypes. Knappsack includes archetypes for demo applications so you can create a new project, deploy to JBoss M3 and run it and play around with it.


                      Even so there are times when JBoss M3 complains about null persistence contexts, but not often, just remove it, clean the project and add it back to the server. Also, Weld doesn't like EJBs without Local interfaces, but we can get around that.


                      No need to sit around for 6 months waiting to get started with Java EE 6, it does work, and while the glitches are being ironed out you can get a feel of how it works,


                      Cheers,


                      Andy Gibson