The WebSphere Development Tools (WDT) for Eclipse can be used to control the server (start/stop/dump etc.). The tools also support incremental publishing with minimal restarts and works with a debugger to allow you to step through your applications plus many more features including:
- content-assist for server configuration (server configuration is minimal but the tools can help you find what you need)
- automatic incremental publish of applications so that changes can be written and tested locally without doing a build/publish cycle or restarting the server (the server does restart nice and quickly but it's still nice not being forced to do it!)
Installing WDT on Eclipse is a simple drag and drop process as explained on wasdev.net.
If the sample git repository hasn't been cloned yet, WDT has git tools integrated into the IDE:
- Open the Git repositories view
- Window -> Show View -> Other
- Type "git" in the filter box, and select Git Repositories
- Copy Git repo url by finding the textbox under "HTTPS clone URL" at the top of this page, and select Copy to clipboard
- In the Git repositories view, select the hyperlink
Clone a Git repository
- The git repo url should already be filled in. Select Next -> Next -> Finish
- The "sample.microservices.12factorapp [master]" repo should appear in the view
This sample can be built using either Gradle or Maven.
Building with Gradle
This assumes you have the Gradle Buildship tools installed into Eclipse Mars.
- In the Git Repository view, expand the 12factorapp repo to see the "Working Directory" folder
- Right-click on this folder, and select Copy path to Clipboard
- Select menu File -> Import -> Gradle -> Gradle Project
- In the Project root directory folder textbox, Paste in the repository directory.
- Click Next twice
- Three projects should be listed in the Gradle project structure click Finish
- This will create 3 projects in Eclipse: sample.microservices.12factorapp, 12-factor-application, and 12-factor-wlpcfg
- Go to the Gradle Tasks view in Eclipse and navigate to the sample.microservices.12factorapp project
- Double click on the eclipse task to generate all the Eclipse files
- In the Enterprise Explorer view in Eclipse right click on the three projects mentioned in step 7 and click refresh
⭐ Note: If you did not use Eclipse/WDT to clone the git repository, follow from step 3, but navigate to the cloned repository directory rather than pasting its name in step 4.
- Right-click on async-websocket/build.gradle
- Run As > Gradle Build...
- In the Gradle Tasks section enter "build"
- Click Run
Building with Maven
- In the Git Repository view, expand the 12factorapp repo to see the "Working Directory" folder
- Right-click on this folder, and select Copy path to Clipboard
- Select menu File -> Import -> Maven -> Existing Maven Projects
- In the Root Directory textbox, Paste in the repository directory
- Select *Browse..." button and select Finish (confirm it finds 3 pom.xml files)
- This will create 3 projects in Eclipse: sample.microservices.12factorapp, 12-factor-application, and 12-factor-wlpcfg
⭐ Note: If you did not use Eclipse/WDT to clone the git repository, follow from step 3, but navigate to the cloned repository directory rather than pasting its name.
- Right-click on async-websocket/pom.xml
- Run As > Maven build...
- In the Goals section enter "install"
- Click Run
Pre-requisite: Download WAS Liberty Pre-requisite: Create a Cloudant database on Bluemix. Make sure you have set the system environment variables 'dbUsername', 'dbPassword' and 'dbUrl' then you are ready to run your application.
For the purposes of this sample, we will create the Liberty server (step 3 in the wasdev.net instructions) a little differently to create and customize a Runtime Environment that will allow the server to directly use the configuration in the 12-factor-wlpcfg
project.
Before creating a server you need a runtime environment for your server to be based on.
- Open the 'Runtime Explorer' view:
- Window -> Show View -> Other
- type
runtime
in the filter box to find the view (it's under the Server heading).
- Right-click in the view, and select New -> Runtime Environment
- Give the Runtime environment a name, e.g.
wlp-2015.6.0.0
if you're using the June 2015 beta. - Either:
- Select an existing installation (perhaps what you downloaded earlier, if you followed those instructions), or
- select Install from an archive or a repository to download a new Liberty archive.
- Follow the prompts (and possibly choose additional features to install) until you Finish creating the Runtime Environment
- Right-click on the Runtime Environment created above in the 'Runtime Explorer' view, and select Edit
- Click the
Advanced Options...
link - If the
12-factor-wlpcfg
directory is not listed as a User Directory, we need to add it:- Click New
- Select the
12-factor-wlpcfg
project - Select Finish, OK, Finish
- Right-click on the
12-factor-wlpcfg
user directory listed under the target Runtime Environment in the Runtime Explorer view., and select New Server. - The resulting dialog should be pre-populated with the 12FactorAppServer Liberty profile server.
- Click Finish
📌 Note: If the '12-factor-wlpcfg' project does not appear in the dialog to add a project to the User Directory make sure there is a 'shared' folder in the 12-factor-wlpcfg project with an empty .gitkeep file inside it.
- Select the
12-factor-application
project - Right-click -> Run As... -> Run On Server
- Select the "WebShere Application Server under localhost" folder, and select Finish
- Confirm web browser opens on "http://localhost:9082/12-factor-application/" and displays a list of all the databases and the content of the "items" database.
- Alternatively open a browser on "http://localhost:9082/12-factor-application/Test" to see a 'hello world' message from the servlet
- When importing the existing maven project into Eclipse, Eclipse will (by default) "helpfully" add this project to an (extraneous) ear. To turn this off, go to Preferences -> Java EE -> Project, and uncheck "Add project to an EAR" before you import the project. If you forgot to do this, just delete the ear project; no harm.
To push applications to Bluemix from Eclipse you need the [IBM Eclipse Tools for Bluemix][eclipse-bluemix]. In Eclipse go to help -> Eclipse Marketplace and search for Bluemix. Once you have downloaded the tools you should be able to create a Bluemix server by right clicking in the servers tab, selecting new > server, selecting the server type IBM Bluemix and entering your Bluemix credentials. To push the application to Bluemix simply drag and drop the 12FactorApp.zip file into the Bluemix server. WDT will prompt you to enter a name for the application, environment variables and services to bind. Pick a name for the application and under environment variables specify the following:
- dbUsername: 'Cloudant-username-credential'
- dbPassword: 'Cloudant-password-credential'
- dbUrl: 'Cloudant-url-credential'