MyEclipse is based on the Eclipse free platform platform and in fact combines new business capabilities with the Eclipse open source features, which has happened many times in the open source world, for example some of the Linux commercial distributions that focus on the free core platform. Introduces MyEclipse, the #1 commercial Eclipse-based IDE, and provides valuable knowledge and helpful tools to help begin and deploy projects.
Here, we are going to create the struts 2 application using myeclipse ide. We don't need to care about the jar files because MyEclipse provides these jar files.
You need to follow these steps to create struts 2 application.
- Create a web project
- Add struts 2 capabilities
- Create input page (index.jsp)
- Create the action class (Product.java)
- Map the request with the action in (struts.xml) file and define the view components
- Create view components (welcome.jsp)
- start server and deploy the project
1) Create a web project
To create web project, click on the file menu - new - project - web project - write the project name e.g. firststruts - finish.
2) Add struts 2 capabilities
To add struts 2 capabilities, select you project - click on the myeclipse menu - add project capabilities - add struts capabilities.
Select the 2.1 and /* as the url pattern - finish.
3) Create input page (index.jsp)
It uses struts core tags to create a form with fields.index.jsp
4) Create the action class (Product.java)
It is the simple action class containing properties with setters and getters. It contains the execute method also for defining the business logic.Product.java
5) Map the request in (struts.xml) file and define the view components
This xml file registers the action and view components.struts.xml
6) Create view components (welcome.jsp)
This jsp page displays the information set in the action object.welcome.jsp
7) start server and deploy the project
To start the server and deploy the project, right click on your project - Run As - MyEclipse server application.
Creating spring application in myeclipse IDE is simple. You don't need to be worried about the jar files required for spring application because myeclipse IDE takes care of it.Let's see the simple steps to create the spring application in myeclipse IDE.
- create the java project
- add spring capabilities
- create the class
- create the xml file to provide the values
- create the test class
Steps to create spring application in Myeclipse IDE
Let's see the 5 steps to create the first spring application using myeclipse IDE.
1) Create the Java Project
Go to File menu - New - project - Java Project.Write the project name e.g. firstspring - Finish. Now the java project is created.
2) Add spring capabilities
Go to Myeclipse menu - Project Capabilities - Add spring capabilities - Finish.Now the spring jar files will be added. For the simple application we need only core library i.e. selected by default.
3) Create Java class
In such case, we are simply creating the Student class have name property. The name of the student will be provided by the xml file. It is just a simple example not the actual use of spring. We will see the actual use in Dependency Injection chapter.To create the java class, Right click on src - New - class - Write the class name e.g. Student - finish.Write the following code:
This is simple bean class, containing only one property name with its getters and setters method. This class contains one extra method named displayInfo() that prints the student name by the hello message.
4) Create the xml file
In case of myeclipse IDE, you don't need to create the xml file as myeclipse does this for yourselves. Open the applicationContext.xml file, and write the following code:
The bean element is used to define the bean for the given class. The property subelement of bean specifies the property of the Student class named name. The value specified in the property element will be set in the Student class object by the IOC container.
5) Create the test class
Create the java class e.g. Test. Here we are getting the object of Student class from the IOC container using the getBean() method of BeanFactory. Let's see the code of test class.
The Resource object represents the information of applicationContext.xml file. The Resource is the interface and the ClassPathResource is the implementation class of the Reource interface.The BeanFactory is responsible to return the bean. The XmlBeanFactory is the implementation class of the BeanFactory. There are many methods in the BeanFactory interface. One method is getBean(), which returns the object of the associated class.
Now run the Test class. You will get the output Hello: Vimal Jaiswal.