Tagged: Eclipse RSS Toggle Comment Threads | Keyboard Shortcuts

  • dunithd 1:49 pm on October 17, 2009 Permalink | Reply
    Tags: Eclipse, Inversion of Control (IOC), Spring, tutorial   

    Write a ‘Hello Spring!’ program in 10 minutes with eclipse 

    Released in the spring of 2003, Spring framework has been doing lot of heavy lifting of developing enterprise Java applications up to now. Compared with J2EE, Spring is very lightweight framework and consist of more elaborate features like Inversion of Control(IOC) container, Aspect Oriented Programming (AOP), Web MVC framework and so on.

    In this tutorial, we are going to create an extremely simple traditional ‘hello world’ application using Spring framework and eclipse IDE. This would be very useful for Spring newbies.

    Step 1: Download and install the Spring framework

    Before we move further download the Spring framework from http://www.springsource.org/download. Spring comes in two flavors, with all dependencies and without dependencies. For beginners, I highly recommend you to choose the ‘with dependencies’ flavor because we don’t want to hunt for the dependencies later and it might take a whole day perhaps.

    After downloading, extract it to a folder of your choice (for example, C:\ on Windows or /opt/ on UNIX)

     

    If you examine the folder structure of Spring distribution, you would see following important folders

    • dist – Contains spring framework.jar
    • docs – Contains documents.
    • lib – Contains all dependent libraries.
    • src – Contains source code.

     

    But don’t get confused with all these .jar files. To create our application, we only need the spring.jar file which resides in the dist folder and commons-logging.jar file in lib/jakarta-commons folder.

    Now we have downloaded the Spring framework libraries. So lets setup a project using eclipse.

    Step 2 : Setting up your project using eclipse

    eclipse is a great IDE for enterprise Java application development. But you don’t have to limit only to eclipse, there are several IDEs out there such as NetBeans, IntelliJ IDEA and even Spring IDE ( a plugin for eclipse that make easier the Spring application development). So the selection is completely up to you. Here I choose d eclipse because I’m a fan of eclipse for a long time.

    I’ll use the latest eclipse release eclipse Galileo for Java EE development. You can download it by visiting http://www.eclipse.org/downloads/

    So lets begin coding our application

     

    Fire up eclipse and go to File > New Java Project. This will bring you the new project creation dialog. Enter HelloSpring as the project name and be sure to set Project Layout as Create separate folders for sources and class files. Leave other options as it is and click on Next.

    New Project Creation Dialog

    New Project Creation Dialog

     

    Then eclipse will show you another dialog and ask you to configure your Java Build Path. Click on the Libraries tab and select Add External Jars. This is place where we can add Spring framework libraries to our project. So browse for the Spring extraction folder and select dist/spring.jar and lib/jakarta-commons/commons-logging.jar.

    This would like the following.

    Set Java Build Path

    Set Java Build Path

     

    Then click on Finish.

     

    Step 3: Create a simple Spring bean.

    Now we’ve setup the project and configured it to get Spring support. All we have to do is start coding the application.

    As the first step, I’m gonna create a simple Java class called “HelloSpring”.

    public class HelloSpring {
    
     private String message;
    
     public void setMessage(String message) {
     this.message = message;
     }
    
     public String getMessage() {
     return message;
     }
    
     public void sayHello() {
     System.out.println(message);
     }
    
    }

    This is a kind of Spring bean which is very similar to simple POJO class. It has a property called ‘message’ and we are going to print a message to the screen using this class. Create the above class using eclipse and place it under com.dunithd.hellospring package.

     

    Step 4: Create beans.xml file

    We need to tell Spring about our HelloSpring bean. For this purpose, Spring uses a bean descriptor file which is a XML file and holds information about all Spring beans in your application.

     

    Create the following XML file in your classpath and name it as beans.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
     <bean id="helloSpring" class="com.dunithd.hellospring.HelloSpring">
     <property name="message" value="Hello Spring!" />
     </bean>
    
    </beans>
    
    

    Step 5 : Create the main program

    I’m gonna create a simple Java program which prints ‘Hello Spring!” to the screen. So I should have main method which invokes the HelloSpring bean.

    Create the following class and place it under the same package.

    package com.dunithd.hellospring;
    
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class Main {
        public static void main(String[] args) {
    
            //load the beans.xml file from the project's classpath
            ApplicationContext context =
                new ClassPathXmlApplicationContext(
                        "beans.xml");
            BeanFactory factory = (BeanFactory) context;    //build the factory
    
            //obtain the bean from factory
            HelloSpring helloSpring = (HelloSpring) factory.getBean("helloSpring");
    
            //Most of the heavy lifting is done by Spring, now use the helloSpring object as your wish
            helloSpring.sayHello();
    
        }
    
    }

    By looking at the main program we can observe that Main class does not directly instantiate the HelloSpring bean, instead it delegates the Creation Responsibility to the Spring container. So in this

     

    case, Spring acts as a kind of Factory object. This is the most important aspect of Spring, which is Ability to Create Objects and this approach leads us to create loosely coupled software components.

    Step 6 : Add logging configuration file to the project

    The Spring framework uses Apache Commons Logging (about which information is available at http://jakarta.apache.org/ commons/logging/) to log container and application information . We’ve add the commons-logging.jar file to our project  because of this reason.

    So create a file called log4j.properties and place it under root of the classpath with following content.

    log4j.rootLogger=FATAL, first
    log4j.appender.first=org.apache.log4j.ConsoleAppender
    log4j.appender.first.layout=org.apache.log4j.PatternLayout
    log4j.appender.first.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

     

    Now we have reached to the end of our application development. If you followed the above steps correctly, your eclipse project would looks like follows.

    Package exploerer view in eclipse

    Package exploerer view in eclipse

    Now right click on the Main.java file and select Run As > Java Application from the context menu.

    Then you’ll see an output like this.

     

    Output of the HelloSpring application

    Output of the HelloSpring application

    You can change the output message by changing the message property in beans.xml.

    What we have done so far?

    Using beans.xml, we’ve told Spring that what types of beans should be instantiated and what properties should be injected to that beans. As you saw, Spring container reads the message property from beans.xml and injected it into the HelloSpring bean.

    Beside these things, Main program is not aware of creating beans and injecting dependencies. So the whole application is well decoupled.

    Thats the power of Spring!

    This is very simple application of Spring and this doesn’t reflects the full Inversion of Control capability of that. But if you are a Spring newbie, this would be a good starting point.

    Download the source code for the HelloSpring application here

     

    Now right click on the Main.java file and select Run As > Java Application from the context menu.Then you’ll see an output like this.You can change the output message by changing the message property in beans.xml.What we have done so far?

    Using beans.xml, we’ve told Spring that what types of beans should be instantiated and what properties should be injected to that beans. As you saw, Spring container reads the message property from beans.xml and injected it into the HelloSpring bean.

    Beside these things, Main program is not aware of creating beans and injecting dependencies. So the whole application is well decoupled.

    Thats the power of Spring!

    This is very simple application of Spring and this doesn’t reflects the full Inversion of Control capability of that. But if you are a Spring newbie, this would be a good starting point.

     
    • Mohamed Aslam 5:37 pm on October 17, 2009 Permalink | Reply

      Nice write up men! and welcome to the blogging world.

    • Shashi 11:03 am on October 21, 2009 Permalink | Reply

      Yeah!Anyone can really learn something from this…. Congradulations….!

    • Abhilasha 11:24 am on September 30, 2010 Permalink | Reply

      Hi , I m new to Spring and tried my first application as you instructed.Tell me what is the meaning of
      “Create the following XML file in your classpath and name it as beans.xml”.
      Bcoz i m getting error
      “Exception in thread “main” org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist
      java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist
      at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:127)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:144)”

      • dunithd 1:51 pm on September 30, 2010 Permalink | Reply

        Hi Abhilasha,

        Make sure you’ve put beans.xml file in your classpath.
        Please refer the figure “Package explorer view in eclipse” to get a better idea about the project layout. Then create the beans.xml file and place it with other .java files that you use to write your application.

    • Amit 6:53 pm on February 20, 2011 Permalink | Reply

      Hi Dunith, I just followed steps told by you in this article…bt m gettin followin error while runing Main.java

      Feb 20, 2011 6:39:09 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
      INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1bf52a5: startup date [Sun Feb 20 18:39:08 IST 2011]; root of context hierarchy
      Feb 20, 2011 6:39:09 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
      INFO: Loading XML bean definitions from class path resource [beans.xml]
      Exception in thread “main” org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
      at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
      at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:509)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:427)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
      at home.saharsh.Main.main(Main.java:11)
      Caused by: java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist
      at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
      … 13 more

    • Amit 6:57 pm on February 20, 2011 Permalink | Reply

      So, can u please help me out with this. My package hierarchy is same as you show above and beans.xml is along with other .java files.
      Thanks in advace…..

      • dunithd 9:59 pm on February 20, 2011 Permalink | Reply

        Hi Amit,
        Can you exactly tell me where did you put the beans.xml file? I suggest you to place it inside src folder.

    • Amit 6:07 pm on February 21, 2011 Permalink | Reply

      Hi Dunith
      thanks for prompt reply……
      It is already in src folder…inside which i hv a package name com.amit and in that package i hv both the java file n xml file n lo4j file.
      bt still not working….i don know why

    • majid 3:15 pm on April 1, 2011 Permalink | Reply

      The same here i got this error :

      Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘helloSpring’ defined in class path resource [beans.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:900)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)

      • dunithd 3:25 pm on April 1, 2011 Permalink | Reply

        Hi Majid,

        Can you post the contents of your beans.xml file here? It would be helpful to sort out this issue.

    • kunal 5:47 pm on May 11, 2011 Permalink | Reply

      I am getting this error:

      Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
      at org.springframework.context.support.AbstractApplicationContext.(AbstractApplicationContext.java:161)
      at org.springframework.context.support.AbstractRefreshableApplicationContext.(AbstractRefreshableApplicationContext.java:90)
      at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.(AbstractRefreshableConfigApplicationContext.java:59)
      at org.springframework.context.support.AbstractXmlApplicationContext.(AbstractXmlApplicationContext.java:61)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:136)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
      at com.dunithd.hellospring.Main.main(Main.java:11)
      Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
      … 7 more

      Pls.help

      • dunithd 2:26 pm on May 12, 2011 Permalink | Reply

        Hi Kunal,
        This happened because of the missing common-logging jar. You can download it from here. Once you’ve downloaded it, put that into to your classpath and try to rebuild the code.

      • shiva 12:33 am on December 28, 2011 Permalink | Reply

        i think u are specified logFactory file inside a package so please remove from the package specify in the src folder in your project

    • kunal 4:08 pm on May 12, 2011 Permalink | Reply

      thanks Dunith..now I rectified the error..but I am now getting this error:

      ay 12, 2011 3:55:49 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
      INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@32fb4f: startup date [Thu May 12 15:55:49 GMT+05:30 2011]; root of context hierarchy
      May 12, 2011 3:55:49 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
      INFO: Loading XML bean definitions from class path resource [beans.xml]
      May 12, 2011 3:55:50 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
      INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@15b0afd: defining beans [HelloSpring]; root of factory hierarchy
      May 12, 2011 3:55:50 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
      INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@15b0afd: defining beans [HelloSpring]; root of factory hierarchy
      Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘HelloSpring’ defined in class path resource [beans.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:900)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)
      at com.dunithd.hellospring.Main.main(Main.java:11)
      Caused by: java.lang.IllegalStateException: No bean class specified on bean definition
      at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClass(AbstractBeanDefinition.java:372)
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:52)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)
      … 13 more

    • kunal 4:34 pm on May 12, 2011 Permalink | Reply

      and beans.xml which is in src folder is this:

    • Gautam De 7:01 am on September 17, 2011 Permalink | Reply

      I am getting error with IllegalStateExceptio.

      This is my Main.java (part):

      ApplicationContext context =
      new ClassPathXmlApplicationContext(“beans.xml”);
      BeanFactory factory = (BeanFactory) context; //build the factory

      //obtain the bean from factory
      HelloSpring hs = (HelloSpring) factory.getBean(“helloSpring”);

      //Most of the heavy lifting is done by Spring, now use the helloSpring object as your wish
      hs.sayHello();

      This is my beans.xml:

      I have the HelloSpring.java, Main.java and beans.xml in same directory and using this as Classpath frm Eclipse GUI Run Configurations. Still getting this error:

      Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘helloSpring’ defined in class path resource [beans.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition
      Caused by: java.lang.IllegalStateException: No bean class specified on bean definition
      at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClass(AbstractBeanDefinition.java:287)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:714)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:386)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:122)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:66)
      at com.dunithd.hellospring.Main.main(Main.java:14)

      Can someone please help me? I am new in Spring.

      Thanks very much for this example. This is small, easy to understand and test – though I am faltering!

      Gautam

      • dunithd 10:06 pm on September 17, 2011 Permalink | Reply

        Hi Gautam,

        Could you please post your beans.xml content here?
        I guess this is due to the mismatching of the bean name definition in the beans.xml file and your calling code.

        -Dunith

        • Gautam De 12:28 am on September 18, 2011 Permalink

        • Gautam De 12:29 am on September 18, 2011 Permalink

          Dunith – I am copy-pasting the beansxml, but they are vanishing!. Sorry to make so many posts. Wish I could delete them.

          Thanks
          Gautam

    • Gautam De 12:27 am on September 18, 2011 Permalink | Reply

      Thanks Dunith. Here it is:

      Regards
      Gautam

    • Gautam De 1:19 am on September 18, 2011 Permalink | Reply

      Dunith

      I have placed ‘//’ in front of all lines. Hope this works, else you are free to delete this post. Thanks.

      //
      //

      //
      //
      //

      //

      Regards
      Gautam

    • Gautam De 1:22 am on September 18, 2011 Permalink | Reply

      I have removed all tags for the last essential 3 lines:

      bean id=”helloSpring”
      property name=”message” value=”Hello Spring!”
      bean

    • dunithd 2:06 am on September 18, 2011 Permalink | Reply

      Hi Gautam,
      When defining a bean in the beans.xml, id and class attributes MUST be set. In my post I forgot to mention that.
      In order to solve your problem, open up your beans.xml file and add the ‘class’ attribute to the helloSpring bean. I’ve updated the beans.xml for that.
      Hope it’ll fix your problem.! :)

      -Dunith

      • Gautam De 3:30 am on September 18, 2011 Permalink | Reply

        Thanks very much Dunith. Sorry to bother you with such dumb question/issue. It’s working.

        Regards
        Gautam

    • Priyanka Dwivedi 1:25 pm on December 28, 2011 Permalink | Reply

      Hi Dunith,

      I m getting this exception on processing above code & i already placed common-loggings.jar at class path, what should i do, please help me, i m new in spring

      Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
      at org.springframework.context.support.AbstractApplicationContext.(AbstractApplicationContext.java:161)
      at org.springframework.context.support.AbstractRefreshableApplicationContext.(AbstractRefreshableApplicationContext.java:90)
      at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.(AbstractRefreshableConfigApplicationContext.java:59)
      at org.springframework.context.support.AbstractXmlApplicationContext.(AbstractXmlApplicationContext.java:61)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:136)
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
      at com.dnit.helloworld.Main.main(Main.java:10)
      Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      … 7 more

      Thanks & Regards,
      Priyanka Dwivedi

  • dunithd 4:15 am on October 16, 2009 Permalink | Reply
    Tags: apt-get, Eclipse, , galileo, OpenJDK,   

    Eclipse 3.5 Galileo on Ubuntu Jaunty 9.04 

    Eclipse 3.5 (AKA Galileo) is the de facto standard for enterprise java development IDE. Eclipse on Linux platform is a perfect match with performance,proficiency and glory :-) .

    In order to begin playing with eclipse, we need to do some configurations.

    1. Install Sun Java JDK

    #sudo apt-get install sun-java6-jdk
    

    2. Make Sun’s Java as your default Java installation

    By default, Ubuntu 9.04 ships with a Java distribution called ‘icedTea’ or Open JDK and its littlebit slow. In order to make sure your system has that installation, open terminal window and type

    #java -version
    

    it’ll print the java version you are using right now. If it is set to Open JDK, then you have to change it to Sun’s JDK.

    #sudo update-alternatives --config java

    Then select the installation with path /usr/lib/jvm/java-6-sun/jre/bin/java.

    3. Search for a pretty icon for eclipse

    Download this one

    http://commons.wikimedia.org/wiki/File:Vista-eclipse.png

    Save it to your desktop

    4. Download Eclipse Galileo

    You can go to official site http://www.eclipse.org/downloads/ and choose your edition, here I choose eclipse for JEE developers edition. This will be nearly 188MB in size.

    Save it to your desktop

    5. Extract eclipse

    Open the terminal and execute

    #cd ~/Desktop
    #tar xzf eclipse-jee-galileo-SR1-linux-gtk.tar.gz (replace your downloaded file name here)
    #sudo mv eclipse /opt/eclipse
    #sudo mv Vista-eclipse.png /opt/eclipse
    #cd /opt
    #sudo chown -R root:root eclipse
    #sudo chmod -R +r eclipse
    #cd /opt/eclipse
    #sudo chmod +x eclipse

    Here I’m gonna install eclipse into /opt, because I want eclipse to be installed for multiple user environment.

    5. Create an executable shell for eclipse

    Open terminal, execute the commands:

    #sudo touch /usr/local/bin/eclipse (this assumes that /usr/local/bin is in the path)
    #sudo chmod 755 /usr/local/bin/eclipse
    #sudo gedit /usr/local/bin/eclipse

    When file is opened with gedit, enter the following:

    #!/bin/sh
    export ECLIPSE_HOME=/opt/eclipse
    $ECLIPSE_HOME/eclipse $*

    6. Create GNOME menu item

    Open Terminal, execute the following commands:

    #sudo gedit /usr/share/applications/eclipse.desktop

    Enter the following contents:

    [Desktop Entry]
    Encoding=UTF-8
    Name=Eclipse
    Comment=Eclipse Galileo IDE
    Exec=eclipse
    Icon=/opt/eclipse/Vista-eclipse.png
    Terminal=false
    Type=Application
    Categories=GNOME;Application;Development
    StartupNotify=True

    7. Initialise eclipse

    Open Terminal, execute:

    #/opt/eclipse/eclipse –clean

    8. From now on, you can choose to run Eclipse from menu Applications->Programming->Eclipse

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel
Follow

Get every new post delivered to your Inbox.