Created
August 12, 2011 10:58
-
-
Save bivas/1141858 to your computer and use it in GitHub Desktop.
Running Play Framework Application in CloudFoundry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package plugins; | |
| import java.util.List; | |
| import java.util.Properties; | |
| import org.apache.commons.logging.Log; | |
| import org.apache.commons.logging.LogFactory; | |
| import org.cloudfoundry.runtime.env.CloudEnvironment; | |
| import org.cloudfoundry.runtime.env.MysqlServiceInfo; | |
| import play.Play; | |
| import play.PlayPlugin; | |
| public class CloudFoundryMySqlBootstrap extends PlayPlugin { | |
| private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; | |
| private static final Log LOG = LogFactory.getLog(CloudFoundryMySqlBootstrap.class); | |
| @Override | |
| public void onApplicationStart() { | |
| final CloudEnvironment cloudEnvironment = new CloudEnvironment(); | |
| final List<MysqlServiceInfo> mysqlServices = cloudEnvironment.getServiceInfos(MysqlServiceInfo.class); | |
| if (mysqlServices.isEmpty()) { | |
| LOG.warn("no mysqlServiceInfo found - using existing db settings"); | |
| return; | |
| } | |
| final Properties configuration = Play.configuration; | |
| final MysqlServiceInfo serviceInfo = mysqlServices.get(0); | |
| removeExistingDbSettings(configuration); | |
| configuration.put("db.driver", JDBC_DRIVER); | |
| configuration.put("db.url", serviceInfo.getUrl()); | |
| configuration.put("db.user", serviceInfo.getUserName()); | |
| configuration.put("db.pass", serviceInfo.getPassword()); | |
| } | |
| private void removeExistingDbSettings(final Properties configuration) { | |
| configuration.remove("db"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Application dependencies | |
| require: | |
| - play 1.2.2 | |
| - play -> crud | |
| - org.cloudfoundry -> cloudfoundry-runtime 0.6.1 | |
| repositories: | |
| - spring_milestone: | |
| type: iBiblio | |
| root: http://maven.springframework.org/milestone | |
| contains: | |
| - org.cloudfoundry -> * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 10:plugins.CloudFoundryMySqlBootstrap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| play war path\to\playdemo --output C:\path\to\playdemo\war (additional options omitted) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vmc push playframework-demo --path C:\path\to\playdemo\war --mem 1G |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment