Before you begin, be sure to setup your project as explained in the previous topic. If you have done that, you can now proceed to the second step in developing the Student Management feature, which is to develop the required components:
...
Update the
org.wso2.carbon.student.mgt → pom.xml
file:Expand title Click here to see the updated pom.xml Code Block <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>student-manager-components</artifactId> <groupId>org.wso2.carbon</groupId> <version>4.2.0</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>org.wso2.carbon.student.mgt</artifactId> <packaging>bundle</packaging> <name>WSO2 Carbon - Student Manager Server Component</name> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> <Bundle-Name>${pom.artifactId}</Bundle-Name> <Export-Package>org.wso2.carbon.student.mgt.*</Export-Package> </instructions> </configuration> </plugin> </plugins> </build> </project>
Note When you export packages for the OSGI bundle, remember that if you are using any API classes or any other dependencies in a separate package, you have to export them as well. In this example, we will have our data classes in the org.wso2.carbon.student.mgt.data package. Exporting the parent mgt package will export everything that is required..
Update the
student-manager-components → pom.xml
file:Expand title Click here to see the updated pom.xml Code Block <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>student-manager</artifactId> <groupId>org.wso2.carbon</groupId> <version>4.2.0</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>student-manager-components</artifactId> <packaging>pom</packaging> <name>WSO2 Carbon - Student Manager Components</name> <modules> <module>org.wso2.carbon.student.mgt</module> <!-- There are 2 more projects to be added here later in this tutorial stub, ui --> </modules> </project>
Adding Java classes to the server component
Now, create two java classes named Student (in src/main/java/org/wso2/carbon/student/mgt/data/
) and StudentManager (in src/main/java/org/wso2/carbon/student/mgt/
) in the org.wso2.carbon.student.mgt project.
The Student class will simply hold a few student details (ID, first name, last name) with getters and setters as follows:
Expand | ||
---|---|---|
| ||
|
The StudentManager class will create an array of students in the constructor and have a public method to return the array as follows:
Expand | ||
---|---|---|
| ||
|
Creating the services.xml file
Finally, the services.xml
file should be configured as shown below to expose the StudentManager service. We have exposed StudentManager as our ServiceClass.
Expand | ||
---|---|---|
| ||
|
...
Info |
---|
We can manually install those 3 OSGI bundles (JAR files) by adding them to the |