Convert component to servlet module
In this tutorial, you'll build an interactive dialogue with your plugin. When you generated the plugin skeleton, the Atlassian SDK automatically created a class called
MyPluginComponent. However, to better fit your interactive plugin, you'll change your Java code to replace the component with a servlet module.
Learn a bit about about component modules
Component modules define specific Java components. The plugin system then injects these modules into your plugin for you, using the Spring framework of the Atlassian container. A component module is part of a page, while a servlet is an entire server-side page. This makes a servlet more suitable for your interactive plugin.
This tutorial discusses the Atlassian container and relationships in future sections.
Step 1. Create and modify MyPluginServlet.java
In this part of the tutorial you'll create a Java class called
MyPluginServlet.javaServlets run server-side Java, and your servlet is where you'll run your plugin code. Servlets are most often used to run web applications, and your purpose here isn't so different – you'll just use it to run your plugin.
Create an empty class file called
Open the empty file.
You can open the file from the command line, or from your file directory tool like Finder or My Computer. The following command pertains to Textwrangler users with the CLI tools installed.
Add the following code to
HttpServlet, and inherits the
doGet()method. This method allows your class to accept POST requests. In response, it prints "Hello! You did it!" to the screen.
- Save and close the file.
Step 2. Add the servlet module to the atlassian-plugin.xml file
Now that you've written your Java class, you need to define it in the
atlassian-plugin.xml descriptor file as a plugin module. You'll use a
servlet module type. It's possible to add this module to your plugin from the command line, but in this case it's more expedient to add the code directly to the descriptor file.
Add your modified
MyPluginServletclass to the file.
withSee an example of the full file.
atlassian-plugin.xmlshould appear as following:
- Save and close the file.
From your project root in terminal (
atlastutorial/adminUI) run the following command if you made your changes from Eclipse:
- In Eclipse or your IDE, click File > Refresh.
Step 3. View the servlet in RefApp
You've created a skeleton for your add-on and configured a servlet in Eclipse. Now you'll launch RefApp from your project root and confirm you can navigate to the servlet.
Change directory to your project root.
Enter the following command to start up RefApp:
Locate the RefApp URL.
After a few moments your terminal will display a message with the URL of the application. RefApp usually launches on port 5990.
- Copy the URL and paste it into your browser.
The URL will resemble http://localhost:5990/refapp.
- Click Login from the upper right-hand corner.
- Log in with the username
adminand the password
- Navigate to the
The servlet loads. Your screen should display the following message:
If you don't see the message, ensure you ran
atlas-mvn eclipse:eclipseto update your project. If the problem persists, restart the RefApp from terminal with the command
CTRL+D, atlas-clean,and then
Now that your plugin skeleton is built and your servlet configured, run the plugin in JIRA.