|
1 |
| -# How to Run and Deploy the Java PostgreSQL Upload App # |
| 1 | +# How to Run and Deploy the Java ElephantSQL Upload App # |
2 | 2 |
|
3 | 3 | ## Overview of the app ##
|
4 | 4 |
|
5 | 5 | This is a Java app that uses the following cloud services:
|
6 | 6 |
|
7 |
| -- PostgreSQL Database |
| 7 | +- ElephantSQL Database |
8 | 8 |
|
9 |
| -This app demonstrates how to connect to a PostgreSQL database on BlueMix from a Java app. |
10 |
| -Simply upload a line-separated file of text (e.g. tweets), and it will add each line to PostgreSQL database. |
| 9 | +This app demonstrates how to connect to an ElephantSQL database on BlueMix from a Java app. |
| 10 | +Simply upload a line-separated file of text (e.g. tweets), and it will add each line to the ElephantSQL database. |
| 11 | +This tutorial is intended to deploy a pre-compiled warfile through the command line. If you would like to |
| 12 | +use Eclipse and modify the source code, see [development](#development). |
11 | 13 |
|
12 | 14 | ## Prerequisites ##
|
13 | 15 |
|
14 | 16 | Before we begin, we first need to install the [**cf**](https://github.com/cloudfoundry/cli/releases) command line tool that will be used to upload and manage your application. If you've previously installed an older version of the cf tool, make sure you are now using v6 of cf by passing it the -v flag:
|
15 | 17 |
|
16 | 18 | cf -v
|
17 |
| - |
| 19 | + |
18 | 20 | ## Download ##
|
19 | 21 |
|
| 22 | +If you would like to modify the source code and work in development, see [development](#development). |
| 23 | + |
20 | 24 | Download the latest WAR file 'release' from https://github.com/ibmjstart/bluemix-java-postgresql-upload/releases
|
21 | 25 |
|
22 |
| -## Deploy to BlueMix and Binding the PostgreSQL Service via the Command Line Interface ## |
| 26 | +## Deploy to BlueMix and Binding the ElephantSQL Service via the Command Line Interface for Production## |
23 | 27 |
|
24 | 28 | From the command line, navigate to the directory of the app and run the following commands.
|
25 | 29 |
|
26 | 30 | 1. Login to Bluemix.
|
27 | 31 |
|
| 32 | + |
28 | 33 | | *usage:* | `$ cf login [-a API_URL] [-o ORG] [-s SPACE]`|
|
29 | 34 | |------------|:---------------------------------------------|
|
30 | 35 | | *example:* | `$ cf login -a https://api.ng.bluemix.net` |
|
31 | 36 |
|
32 |
| -2. Create an instance of the PostgreSQL service, giving it a unique name in the last argument. The application is written to assume that the service instance name will begin with "postgresql". |
| 37 | +2. Create an instance of the ElephantSQL service, giving it a unique name in the last argument. The application is written to assume that the service instance name will begin with "elephantsql". |
| 38 | + |
33 | 39 |
|
34 | 40 | | *usage:* | `$ cf create-service SERVICE PLAN SERVICE_INSTANCE`|
|
35 | 41 | |------------|:---------------------------------------------------|
|
36 |
| - | *example:* | `$ cf create-service postgresql 100 postgresql_JPU`| |
| 42 | + | *example:* | `$ cf create-service elephantsql turtle elephantsql_JEU`| |
| 43 | + |
| 44 | +3. From the directory you placed your WAR file in, push the app with the -p flag to specify the WAR file |
| 45 | +path and the --no-start option so we can bind our required service before starting our app. Give your |
| 46 | +app a unique app name to be used as its hostname; for instance, if you replace `<YOUR-NAME>` |
| 47 | +with 'user1' then the example below would be hosted at http://jeu-user1.mybluemix.net. |
37 | 48 |
|
38 |
| -3. From the directory you placed your WAR file in, push the app with the -p flag to specify the WAR file path and the --no-start option so we can bind our required service before starting our app. Give your app a unique app name to be used as its hostname; for instance, if you replace `<YOUR-NAME>` with 'user1' then the example below would be hosted at http://jpu-user1.ng.bluemix.net. |
39 | 49 |
|
40 | 50 | | *usage:* | `$ cf push APP [--no-manifest] [--no-start] [-p PATH]` |
|
41 | 51 | |------------|:----------------------------------------------------------------|
|
42 |
| - | *example:* | `$ cf push jpu-<YOUR-NAME> -b https://github.com/cloudfoundry/java-buildpack --no-manifest --no-start -p PostgreSQLUpload.war`| |
| 52 | + | *example:* | `$ cf push jeu-<YOUR-NAME> -b https://github.com/cloudfoundry/java-buildpack --no-manifest --no-start -p ElephantSQL-Uploader.war`| |
| 53 | + |
| 54 | + *Note* : `-p elephantSQL.war` assumes you are running these commands from within the same directory that |
| 55 | + this file resides. |
43 | 56 |
|
44 |
| - *Note* : `-p PostgreSQLUpload.war` assumes you are running these commands from within the same directory that this file resides. |
| 57 | +4. Bind the elephantSQL service instance to the new app |
45 | 58 |
|
46 |
| -4. Bind the postgreSQL service instance to the new app |
47 | 59 |
|
48 | 60 | | *usage:* | `$ cf bind-service APP SERVICE_INSTANCE`|
|
49 | 61 | |------------|:----------------------------------------|
|
50 |
| - | *example:* | `$ cf bind-service jpu-<YOUR-NAME> postgresql_JPU`| |
| 62 | + | *example:* | `$ cf bind-service jeu-<YOUR-NAME> elephantsql_JEU`| |
51 | 63 |
|
52 | 64 | 5. Start the app
|
53 | 65 |
|
| 66 | + |
54 | 67 | | *usage:* | `$ cf start APP`|
|
55 | 68 | |------------|:----------------|
|
56 |
| - | *example:* | `$ cf start jpu-<YOUR-NAME>`| |
57 |
| - |
58 |
| -## Import the App into Eclipse ## |
| 69 | + | *example:* | `$ cf start jeu-<YOUR-NAME>`| |
| 70 | + |
| 71 | +## <a name="development"></a>Import the App into Eclipse for Development ## |
| 72 | + |
| 73 | +To view and edit the application, simply import the project into Eclipse. If you don't have an Eclipse instance with Java EE support, you may download it from http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/lunar |
59 | 74 |
|
60 |
| -To view and edit the application, simply import the project into Eclipse. If you don't have an Eclipse instance with Java EE support, you may download it from https://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/keplersr2 |
| 75 | +### Download the Source Code ### |
61 | 76 |
|
62 |
| -Once you have Eclipse running, you can Import the WAR file as a new project via |
| 77 | +Once you have Eclipse running, you can Import the WAR file as a new project via (this does not give access to the source code, as it is already compiled into the war.) |
63 | 78 | 1. File->Import...
|
64 | 79 | 2. Scroll down to the "Web" section, expand that section and click WAR File then click Next.
|
65 | 80 | 3. Deselect the 'Add project to an EAR' checkbox
|
66 | 81 | 4. Click next and then Finish and the project should be imported into Eclipse
|
67 | 82 |
|
68 |
| -Now that you have the project in Eclipse, you can edit the source and re-deploy to BlueMix by either: |
69 |
| - |
| 83 | +If you would like to edit the source code of the project, you will have to clone the git URL. |
| 84 | + |
| 85 | + 1. Open Eclipse |
| 86 | + 2. Select File->Import |
| 87 | + 3. Under the header labeled "Git", click "Projects from Git" and click `Next` |
| 88 | + 4. Select `Clone URI` and click `Next` |
| 89 | + 5. Copy paste the git clone URL into the next page. Hit `Next` |
| 90 | + 6. Select the Branch to clone (you should only need Master). Click `Next` |
| 91 | + 7. Name the destination directory. click `Next` |
| 92 | + 8. Check `Import Existing Projects` and click `Next` |
| 93 | + 9. Check the project, and click `Finish` |
| 94 | + |
| 95 | +### Modify the Source Code and Deploy to Bluemix ### |
| 96 | + |
| 97 | +With access to the source code, you may modify the application, add functionality, or deploy it straight |
| 98 | +to Bluemix. When you push source code to Bluemix, Eclipse first compiles it into a war file, and then |
| 99 | +pushes that war file to Bluemix. Alternatively, you may select File->Export and export the war file. Then, |
| 100 | +you may push the war file using the same methods above. |
| 101 | + |
| 102 | +Now that you have the project in Eclipse, and have modified the source code, re-deploy to BlueMix by either: |
| 103 | + |
70 | 104 | A. Exporting your updated project as a WAR file and push it from the command line as before
|
71 |
| - |
72 |
| - -OR- |
73 |
| - |
74 |
| - B. Installing the [Eclipse Cloud Foundry Plugin](https://marketplace.eclipse.org/content/cloud-foundry-integration-eclipse), defining the BlueMix endpoint (https://api.ng.bluemix.net), and deploying your application right from Eclipse. |
| 105 | + |
| 106 | + -OR- |
| 107 | + |
| 108 | + B. Installing the [IBM Eclipse Tools for Bluemix Plugin](http://marketplace.eclipse.org/content/ibm-eclipse-tools-bluemix#.VAiRPbywIRI), |
| 109 | + defining the BlueMix endpoint (https://api.ng.bluemix.net), and deploying your application right from Eclipse. To deploy to Bluemix: |
| 110 | + |
| 111 | + |
| 112 | +#### • Set up Bluemix Server #### |
| 113 | + |
| 114 | +Make sure you are in the Java EE [perspective](http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fconcepts-4.htm) in Eclipse. |
| 115 | + |
| 116 | + 1. In the bottom window section, select the **Servers** tab. (Alternatively, you can click: `Window > Show View > Servers`) |
| 117 | + 2. Right-Click inside the Servers panel and select `New > Server` |
| 118 | + 3. Select, `IBM > IBM Bluemix` and click `Next`. |
| 119 | + 4. Enter your login information for Bluemix in the email and password sections. |
| 120 | + 5. From the URL dropdown menu, choose: `IBM Bluemix` |
| 121 | + 6. Hit `Next` and Bluemix will automatically validate your account credentials. |
| 122 | + 7. Optional: Select the Organization within your Bluemix account that you would like to deploy to. |
| 123 | + 8. Click: Finish |
| 124 | + |
| 125 | +#### • Push the app #### |
| 126 | + 1. Right-Click on the Bluemix server and click: `Connect` (Optional) |
| 127 | + 2. Right-Click on the Bluemix server and select: `Add and Remove...` |
| 128 | + 3. Select your ElephantSQL project from the window on the left and click: `Add >` |
| 129 | + 4. Click: `Finish` |
| 130 | + 5. Enter a Name for your app and select: `Next` |
| 131 | + 6. Specify a unique subdomain for your application. Similar to the command line tools, you can pick |
| 132 | + something like <jeu-yourUser> so that your app is located at `http://jeu-yourUser.mybluemix.net`. Hit `Next` |
| 133 | + 7. Create and bind the elephantSQL service by selecting either an existing elephantSQL service or creating one by selecting the icon in the top right. Search for ElephantSQL, and you can bind the application through the plugin GUI. |
| 134 | + 8. Hit `Next` and `Finish`. Your app should deploy to Bluemix and be available at the URL you gave it. This can be viewed in the ACE UI. |
75 | 135 |
|
76 | 136 | ## License ##
|
77 | 137 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
|
0 commit comments