This is a "ClickStart" that gets you going with a Maven - Jetty 9 "seed" project starting point. You can launch it here:
This will setup a continuous deployment pipeline - a CloudBees Git repository, a Jenkins build compiling and running the test suite (on each commit). Should the build succeed, this seed app is deployed on a Jetty 9 container.
Jetty 9 container is available on CloudBees thanks to the jetty9-clickstack. Documentation is available here.
You can deploy your web application on the jetty9 clickstack using the CloudBees SDK "app:deploy
" command.
bees app:deploy -a my-account/jetty9-maven-clickstart -t jetty9 -Rjava_version=1.7 ./target/jetty9-maven-clickstart-1.0-SNAPSHOT.war
- "
-a my-account/jetty9-maven-clickstart
": name of the CloudBees account and of the application. The application will be accessible on the URL http://jetty9-maven-clickstart.cyrille-leclerc.cloudbees.net/ - "
-t jetty9
": identifier of the jetty9 clickstack - "
-Rjava_version=1.7
": optional parameter to use the version 7 of the Java runtime (JVM). Jetty 9 supports both JVM 6, 7 and 8. JVM 7 is the default. - "
./target/jetty9-maven-clickstart-1.0-SNAPSHOT.war
": path to the war file. You only need to set the "-R
", "-t
" and "-D
" settings once - they will be remembered for subsequent deploys.
db:create --username my-username --password alpha-beta jetty9-maven-clickstart-db
bees app:bind -a jetty9-maven-clickstart -db jetty9-maven-clickstart-db -as mydb
- "
-a jetty9-maven-clickstart
": the name of your application - "
-db jetty9-maven-clickstart-db
": the name of your CloudBees MySQL Database - "
-as mydb
": the name of the binding which is used to identify the binding and to compose the name of the environment variables used to describe this binding (always prefer '_' to '-' for bindings because '-' is not supported in linux environment variable names).
This binding will create
- A JNDI DataSource with name "
java:comp/env/jdbc/mydb
" (also available at "jdbc/mydb
") - The following System Properties
DATABASE_URL_MYDB
: url of the database starting with "mysql:" (e.g. "mysql://ec2-1.2.3.4.compute-1.amazonaws.com:3306/jetty9-maven-clickstart-db"). Please note that this URL is not prefixed by "jdbc:".DATABASE_USERNAME_MYDB
: login of the databaseDATABASE_PASSWORD_MYDB
: password of the database
Details on bindings are available in Binding services (resources) to applications.
You can now use your "java:comp/env/jdbc/mydb
" JNDI DataSource in your application.
Please note that "jdbc/mydb
" is also available.
Java code sample:
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/mydb");
Connection conn = ds.getConnection();
ResultSet rst = stmt.executeQuery("select 1");
while (rst.next()) {
out.print("resultset result: " + rst.getString(1));
}
rst.close();
stmt.close();
conn.close();
JSP / JSTL code sample:
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<sql:query var="rs" dataSource="jdbc/mydb">
select 1 as col1
</sql:query>
<h1>Datasource JSTL Demo</h1>
<c:forEach var="row" items="${rs.rows}">
Row: ${row.col1}<br/>
</c:forEach>