3 Replies Latest reply on Sep 3, 2004 4:28 PM by vebs

    nukes block example

      Hi All

      i succesfully setup nukes with eclipse. now i want example to create block/module and deploy them on jboss.

      please do not give this url in your response as they are of no use

      http://www.onjava.com/pub/a/onjava/2003/06/04/nukes.html?page=1


      thanks

      Vebs

        • 1. Re: nukes block example
          jae77

          the "template" and "rss" modules are relatively simple and server as good starter examples.

          if you have a general overall understanding of what a sar archive is and how to create one through the build process (look at the build.xml examples in the other modules) you should be ok.

          there is also the project page that has a brief howto and any documentation in the wiki. feel free to contribute back and construct your own simple howto for others who wish to create a module.

          • 2. Re: nukes block example
            chasetec

            That url that you don't want is probably the best howto right now. I'd recomment generating the javadoc html for the core and nukes source code from the Nukes source code and then just looking at the existing modules.

            If you want a basic block example here's one I did when I first was figuring out Nukes. I didn't even use ant much less eclipse so this should apply to anyone.

            Source for a basic block that just displays the current date:

            package org.jboss.nukes.examples;
            
            import org.jboss.nukes.block.BlockSupport;
            import org.jboss.nukes.html.Page;
            
            import java.util.GregorianCalendar;
            import java.util.Calendar;
            
            public class DateBlock extends BlockSupport {
            
             public void render(Page page) {
             GregorianCalendar calendar = new GregorianCalendar();
             String month = null;
             switch(calendar.get(Calendar.MONTH)){
             case 0: month = "January";
             break;
             case 1: month = "February";
             break;
             case 2: month = "March";
             break;
             case 3: month = "April";
             break;
             case 4: month = "May";
             break;
             case 5: month = "June";
             break;
             case 6: month = "July";
             break;
             case 7: month = "August";
             break;
             case 8: month = "September";
             break;
             case 9: month = "October";
             break;
             case 10: month = "November";
             break;
             case 11: month = "December";
             break;
             }
             page.print(month + " " + calendar.get(Calendar.DATE) + " " + calendar.get(Calendar.YEAR));
             }
            }
            


            To compile you'll need to include nukes-lib.jar in your classpath. nukes-lib.jar can be found inside of the nukes.ear.

            You'll also need a xml configuration file called jboss-service.xml. The contents of it should be:

            <?xml version="1.0" encoding="UTF-8"?>
            <server>
             <mbean
             code="org.jboss.nukes.examples.DateBlock"
             name="nukes.blocks:name=date"
             xmbean-dd=""
             xmbean-code="org.jboss.nukes.component.NukesMBean">
             <depends>nukes.modules:name=core</depends>
             <xmbean>
             <attribute name="Title">Current Date</attribute>
             <attribute name="Side">0</attribute>
             <attribute name="Weight">0</attribute>
             <attribute name="Collapsable">false</attribute>
             </xmbean>
             </mbean>
            </server>
            


            You'll need to package both these pieces into a Service ARchive(a .sar file) which can be created with jar. Just put the class file (including the needed directory structure for it's package) into the base of the archive and put the jboss-service.xml into the META-INF folder in the archive. One you've done that just copy the archive to $JBOSS_HOME/server/default/nukes

            • 3. Re: nukes block example

              Hello Chase,

              Yes I got sucesseded in running above example.

              THANKS very much.

              In future i may need ur help.

              thanks,
              vebs