Learning Helianto: deploy to Cloud Foundry

It is easy to deploy your application by adding a Cloud Foundry profile to any Helianto’s project pom.xml, indeed, anywhere you use maven. Here is one example:

<profiles>
<profile>
	<id>yourPaaS</id>
	<build>
		<plugins>
			<plugin>
				<groupId>org.cloudfoundry</groupId>
				<artifactId>cf-maven-plugin</artifactId>
				<version>1.1.0</version>
				<configuration>
					<server>YOUR_SERVER</server>
					<target>https://api.ng.bluemix.net</target>
					<appname>YOUR_APP</appname>
					<org>YOUR_ORG</org>
					<space>YOUR_SPACE</space>
					<instances>1</instances>
					<memory>512</memory>
					<services>
						<!-- Add services you want to create and bind here <service> <name>mycloudant</name> 
							<label>cloudantNoSQLDB</label> <plan>Shared</plan> </service> -->
					</services>
					<env>
						<!-- Set any environment variables <myvar>myvalue</myvar> -->
					</env>
				</configuration>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>push</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-clean-plugin</artifactId>
				<version>2.5</version>
				<executions>
					<execution>
						<id>auto-clean</id>
						<phase>initialize</phase>
						<goals>
							<goal>clean</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</profile>
</profiles>

Of course, you are required to find an appropriate place inside your existing pom.xml file and substitute YOUR_SERVER, YOUR_APP, YOUR_ORG and YOUR_SPACE accordingly, as well as the instance, memory and services parameters. The latter can be adjusted and bound using the vendor’s Cloud Foundry user interface.

You will also need some additions to your settings.xml file:

<servers>
    ...
     <server>
             <id>YOUR_SERVER</id>
             <username>YOUR_USER</username>
             <password>YOUR_PWD</password>        
     </server>
</servers>

Please, remember that the settings.xml file is located outside the project root dir to protect your credentials (check ${user-dir}/.m2/settings.xml).

To deploy, from a terminal in the the project root dir, simply run:

$ mvn clean -P yourPaaS cf:push

1 thought on “Learning Helianto: deploy to Cloud Foundry”

  • I met a similar prlobem here. If my test class name is ****Tests.java it doesn’t work in Maven+Junit4 but works in eclipse+Junit4; I tested in maven2+junit4, I must use such convention:****Test.java, No s added. So I must rename all my test classes to such name convention. It took me many hours to get the point. I thought I’m so stupid.

Leave a Reply

Your email address will not be published. Required fields are marked *