1 2 Previous Next 22 Replies Latest reply on Dec 17, 2009 10:34 PM by dan.j.allen

    Weld and Glassfish v3

    andygibson.contact.andygibson.net

      I'm trying out the Weld release in Glassfish V3 with a simple example.


      I started with a JSF bean as follows :



      @ManagedBean
      @SessionScoped
      public class MessageBean implements Serializable {
      
          public String getMessage() {
              return "Message From Bean";
          }
      }



      In my page, I have  :


      My Message Is #{messageBean}



      This works, I get the message appearing in my page.


      If I am correct, all I need to do is remove the @ManagedBean and scope annotation and add the @Named annotation to make it a weld bean and add an empty beans.xml file into my project to make the app use Weld with JSF?


      I've done this, and Weld appears to start up so it found the beans.xml file ok, but my page doesn't show the message.


      Something weird is going on within Netbeans/Glassfish (build 70) since the IDE thinks the @Named annotation is in package javax.annotation.Named and there are no scope annotations available within the IDE. The IDE compiles and deploys the app just fine.


      Looking within Glassfish, the weld-osgi-bundle.jar file has the Named annotation in the correct place (javax.inject).


      I have done nothing else to Glassfish, netbeans or my project, this is a fresh install of each, new application, create the bean, create the page and no additional jars added.


      I'm not sure if it is a weld thing since the jars in Glassfish appear OK, even if they are not running correctly, or a Glassfish deployment thing.


      Anyone have any suggestions or experiences getting things running on Glassfish?


      Cheers,


      Andy Gibson


        • 1. Re: Weld and Glassfish v3
          gavin.king

          All you should need to do is:



          1. Delete @ManagedBean

          2. use @javax.enterprise.context.SessionScoped

          3. Add @javax.inject.Named

          4. Add a beans.xml file



          • 2. Re: Weld and Glassfish v3
            andygibson.contact.andygibson.net

            Thank you sir for confirming, by default, that doesn't work on Glassfish, but when I added the weld-servlet.jar to my project it worked fine.
            I'm assuming that adding the jar shouldn't be necessary, and I guess something funky is going on in that release of Glassfish but Weld appears to be working fine.


            Cheers,


            Andy Gibson

            • 3. Re: Weld and Glassfish v3
              sboscarine

              Hello Andy,

              How do the examples work?


              You can check them out from http://anonsvn.jboss.org/repos/weld/examples/trunk or download them with weld. 


              I'd first try something simple like the numberguess example. 


              Thanks,

              Steven

              • 4. Re: Weld and Glassfish v3
                andygibson.contact.andygibson.net

                Hey Steven, Good Point...


                I used the examples in the weld CR1 distribution, and the JSF Number Guess works fine. So I did exactly the same test with my code in Eclipse and similarly, it thinks the @Named annotation is in the javax.annotations package and there are no scope annotations.


                So, I added the weld-servlet.jar file to the project to get it to compile with the correct annotations, and exported a war from eclipse without the weld jar file, deployed it and it ran just fine.


                So, it looks like the problem is in the way Glassfish reports the server run time libraries to the IDE (both in Eclipse and Netbeans).


                Cheers,


                Andy Gibson

                • 5. Re: Weld and Glassfish v3
                  sboscarine

                  Hello Andy,

                  Suggestion:  use Maven.


                  If I understand your question correctly, you're asking about which jars go where.  That's the problem Maven was designed to solve. 


                  You can even launch an embedded Glassfish v3 without installation (instructions).


                  If you just want to test out weld, I've had the best luck with Tomcat in Eclipse WTP for regular development.  Are you actually deploying to Glassfish v3 or v2?  V3 hasn't been released yet.


                  Thanks,

                  Steven

                  • 6. Re: Weld and Glassfish v3
                    asookazian
                    • 7. Re: Weld and Glassfish v3
                      asookazian

                      Maintain session state on application re-deploy.
                      When an application is re-deployed, the developer simply refreshes the browser to test the code changes. With Netbeans 6.5, Eclipse, and the GlassFish plugin, developers edit the code, save the code, and refresh the browser. The IDEs will auto- compile and auto-redeploy the code. The iterative Java Web development cycle is simplifed to edit-save-refresh browser

                      http://java.dzone.com/articles/what-you-can-expect-from-glass


                      So anybody using this edit-save-refresh browser with Weld or Seam?


                      Does Weld have the special classloader that Seam 2.x has for hot incremental deployment or is that outside the scope/functionality of CDI/Weld?

                      • 8. Re: Weld and Glassfish v3
                        asookazian

                        Where are instructions on how to use/configure Glassfish V3 prelude to deploy Weld examples?


                        here's the readme.txt contents from Weld-1.0.0-CR1:


                        Weld
                        -----
                        
                        Java Contexts and Dependency Injection (JSR-299) is a new Java standard for 
                        dependency injection and contextual lifecycle management. Weld is the
                        reference implementation of JSR-299.
                        
                        This distribution, as a whole, is licensed under the terms of the Apache Public
                        License (see apl.txt).
                        
                        This distribution consists of:
                        
                        doc/
                           -- The Reference guide, take a look at doc/en-US/html/index.html for getting 
                              started using Weld and the facilities offered by JSR-299.
                        
                        ****** DOCS NOT INCLUDED IN THIS RELEASE ******
                         
                        examples/
                           -- The Weld examples, the examples are described in more detail in the 
                              reference guide 
                           
                        jboss-as/
                           -- Installer for JBoss AS, change into this directory, and run ant update
                              There are more details in the reference guide
                        
                        lib/
                           -- Libraries,  for building the examples
                           
                        lib/weld
                           -- Weld binary, source and javadoc jars

                        • 9. Re: Weld and Glassfish v3
                          pmuir

                          GlassFish V3 prelude doesn't support CDI/Weld. You need one of the promoted builds of V3 (not V3 prelude), such as the one Andy is using.


                          As for instructions, you need to look at the GlassFish V3 documentation or readmes. I've asked the GlassFish team to contribute instructions back into Weld examples and reference guide, but so far they haven't got to this.


                          We're quite happy to help you with Weld here, but I would suggest posting to the GlassFish forums as well - the GlassFish team have been responsible for the Weld integration into GlassFish so will be able to comment on the status and problems much better than I can.


                          Arbi, no Weld does not have the hot-redeploy feature yet, and it's not a feature of the CDI spec. We need to discuss how this is done for Seam 3.

                          • 10. Re: Weld and Glassfish v3
                            andygibson.contact.andygibson.net

                            Thanks Pete,


                            I already filled in an Issue over on the Glassfish project. I don't know where the problem lies since it seems to be in the IDE plugins while the Weld libraries and Weld setup in Glassfish v3 build70+ appears correct. I posted here to confirm my assumptions about changing it from a JSF bean to a Weld Bean (?) is correct.


                            FYI, in Glassfish, changes are hot deployed to the server, but I do get an error because of weld :



                            INFO: PWC2785: Cannot serialize session attribute org.jboss.weld.context.SessionContext#org.jboss.weld.bean...org.jboss.weld.conversation.ServletConversationManager for session a11f4c81e62c830a6d7ef5bdddf9
                            java.io.NotSerializableException: org.jboss.weld.literal.DefaultLiteral





                            Is this an issue you want me to create a jira for or is it not Serializable for a reason? Regardless, changes to my app are still hot-deployed on Glassfish so yes, the edit-save-refresh cycle does appear to work with Weld with Glassfish build 70+.


                            Steve, the problem isn't so much which jars go where, the problem is that the jars are supposed to be in glassfish v3 build 70+ already and they are but according to the IDE that uses the server runtime for compilation, Weld is only half there and the half that is there is wrong. At run time though, everything is fine.


                            As it is, you can't use Netbeans or Eclipse for Weld development on Glassfish without including additional jars to get it to compile which aren't and shouldn't be necessary. It's not so much about fixing my problem, I already have an solution, it's about fixing it for everyone else that wants to try their hand at Glassfish and Weld who creates a bean or two with Weld annotations and a JSF page and then ponders why the thing doesn't work for 2 minutes before they give up and use something else.


                            At this point, I'm waiting for a response from the glassfish devs, I don't even know whether it is the Glassfish team that handles IDE integration, so it might not even be their problem. However, since the same problem is identical in Netbeans and Eclipse plugins, I'm guessing that there must be some common factor to it, I just don't know enough about the IDE integration stuff to know what or where.


                            • 11. Re: Weld and Glassfish v3
                              andygibson.contact.andygibson.net

                              Oh, Steven, thanks for the tip on Tomcat / WTP for testing out Weld. I'm not stuck on Glassfish v3 right now for anything other than playing around with it, and I like the new super hot deployment as you develop. I took at a look at JBoss 5.2 Beta, but ran into issues on the nightly builds. If anyone knows of a good fairly stable nightly build for it, that would be great. I hope we can get a similar hot deploy feature in JBoss, especially since I just took a look at the Jopr administration tool and it looks fantastic and  it's a Glassfish feature missing from JBoss for a while.


                              Tomcat, I could use it for testing out Weld until the other pieces fall into place, but I'd like to focus on JBoss/Glassfish mid-longer term.


                              Cheers,


                              Andy Gibson

                              • 12. Re: Weld and Glassfish v3
                                sboscarine

                                Andy Gibson wrote on Nov 09, 2009 19:36:


                                FYI, in Glassfish, changes are hot deployed to the server, but I do get an error because of weld :


                                INFO: PWC2785: Cannot serialize session attribute org.jboss.weld.context.SessionContext#org.jboss.weld.bean...org.jboss.weld.conversation.ServletConversationManager for session a11f4c81e62c830a6d7ef5bdddf9
                                java.io.NotSerializableException: org.jboss.weld.literal.DefaultLiteral





                                Is this an issue you want me to create a jira for or is it not Serializable for a reason? Regardless, changes to my app are still hot-deployed on Glassfish so yes, the edit-save-refresh cycle does appear to work with Weld with Glassfish build 70+.


                                Andy,

                                I was getting that error in Tomcat.  Here's a JIRA, https://jira.jboss.org/jira/browse/WELD-231.  It was very recently closed by JBoss.  I haven't had a chance to confirm yet. 


                                I'd personally test it with the next release and reopen the ticket if it's unresolved.

                                • 13. Re: Weld and Glassfish v3
                                  gavin.king
                                  java.io.NotSerializableException: org.jboss.weld.literal.DefaultLiteral



                                  I recently fixed AnnotationLiteral to make it serializable. That change may fix this problem.

                                  • 14. Re: Weld and Glassfish v3
                                    ludoch

                                    The Weld jar filenames changed recently, (after NetBeans 6.8 beta)
                                    To use the latest runtime from GlassFish v3 (b70 or after), you need to use a nightly build of NetBeans 6.8, not the beta version.


                                    Same for Eclipse plugin, you might need to update it to the latest version.


                                    Hope this helps,


                                    Ludo

                                    1 2 Previous Next