Embed tc Server

As of tc Server 2.9.1, you can create an embedded server application with tc Server. In an embedded server application, the application is deployed and run as a JAR; the JAR file launches a main() method which in turn starts the server and deploys itself on it.

This section contains general instructions for embedding tc Server. For a worked example, see https://github.com/vFabric/tcs-embed-example.

Prerequisites

Procedure

  1. Create an account at repository.cloudfoundry.com

  2. Configure the repository in your project's pom.xml (in the root of your project directory).

    <repository>  
          <id>tcserver-embed-release-repo</id>  
          <name>TC Server Embedded Runtime</name>  
          <snapshots>   
          <enabled>true</enabled>   
          <updatePolicy>always</updatePolicy>   
          <checksumPolicy>fail</checksumPolicy>   
          </snapshots>  
          <url>http://repository.cloudfoundry.com/data2/maven/bundles/release</url>  
    </repository> 
  3. Configure dependencies in your project's pom.xml file.

    See Example pom.xml below.

  4. Configure credentials for accessing the tcruntime-release package at build-time, as a server stanza in the Maven settings file (.m2/settinEgs.xml) .

    <settings>   
         <servers>   
            ...   
            <server>   
               <id>tcserver-embed-release</id>
               <username>UserName</username>   
               <password>DecryptedPassword</password>   
            </server>   
            ...   
         </servers>  
    </settings> 
  5. Run the following command to build the application with embedded tc Server and install it in your local Maven repository (.m2), located in your home directory.

    mvn clean compile assembly:single 
  6. Start the application with a command like this:

    java -jar target/example-0.0.1-SNAPSHOT-jar-with-dependencies.jar 

Embedded Jars

Table 11. tc Server Embedded Jars

Group IdArtifact IdDescription
com.springsource.vfabric.tcruntime.embedcom.springsource.org.apache.tomcat.embed.coreContains all of the core jars for tc Server embedded: catalina.jar, tomcat-coyote.jar,annotations-api.jar, tomcat-api.jar, tomcat-util.jar, servlet-api.jar
com.springsource.vfabric.tcruntime.embedcom.springsource.org.apache.tomcat.embed.jasperContains all of the JSP classes: jsp-api.jar, jasper-el.jar, jasper.jar, el-api.jar
com.springsource.vfabric.tcruntime.embedcom.springsource.org.apache.tomcat.embed.logging.juliContains the Juli logging classes: tomcat-juli.jar
com.springsource.vfabric.tcruntime.embedcom.springsource.org.apache.tomcat.embed.logging.log4jContains the log4j logging classes: log4j.jar
com.springsource.vfabric.tcruntime.embedcom.springsource.org.apache.tomcat.embed.clusterContains classes for clustering: catalina-ha.jar, catalina-tribes.jar
com.springsource.vfabric.tcruntime.embedcom.springsource.org.apache.tomcat.dbcpContains classes for DBCP: tomcat-dbcp.jar
com.springsource.vfabric.tcruntime.embedcom.springsource.org.apache.tomcat.jdbcContains classes for Tomcat JDBC: tomcat-jdbc.jar
com.springsource.vfabric.tcruntime.embedcom.springsource.org.eclipse.jdt.compilerContains classes for Eclipse compiler: ecj-<version>.jar
com.springsource.vfabric.tcruntime.embedcom.springsource.tcserverContains the tc Server classes: tcServer.jar

Example pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.springsource.tcruntime.embeddedexample</groupId>
	<artifactId>example</artifactId>
	<version>0.0.2-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>example</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<build>
		<plugins>
			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<mainClass>com.springsource.tcruntime.embeddedexample.example.App</mainClass>
						</manifest>
					</archive>
					<descriptorRefs>
						<descriptorRef>jar-with-dependencies</descriptorRef>
					</descriptorRefs>
				</configuration>
				<executions>
					<execution>
						<id>make-assembly</id> <!-- this is used for inheritance merges -->
						<phase>package</phase> <!-- bind to the packaging phase -->
						<goals>
							<goal>single</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
       
	</build>
	<repositories>
	<repository>
	       <id>tcserver-embed-release-repo</id>
	       <name>TC Server Embedded Runtime</name>
	       <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
	       <url>http://repository.cloudfoundry.com/data2/maven/bundles/release</url>
	   </repository>
	</repositories>
	<dependencies>
		<dependency>
			<groupId>com.springsource.vfabric.tcruntime.embed</groupId>
			<artifactId>com.springsource.org.apache.tomcat.embed.core</artifactId>
			<version>7.0.37.B.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>com.springsource.vfabric.tcruntime.embed</groupId>
			<artifactId>com.springsource.org.apache.tomcat.embed.logging.juli</artifactId>
			<version>7.0.37.B.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>com.springsource.vfabric.tcruntime.embed</groupId>
			<artifactId>com.springsource.org.apache.tomcat.embed.logging.log4j</artifactId>
			<version>7.0.37.B.RELEASE</version>
		</dependency>
        <dependency>
            <groupId>com.springsource.vfabric.tcruntime.embed</groupId>
            <artifactId>com.springsource.org.apache.tomcat.embed.jasper</artifactId>
            <version>7.0.37.B.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.springsource.vfabric.tcruntime.embed</groupId>
            <artifactId>com.springsource.tcserver</artifactId>
            <version>2.9.1.RELEASE</version>
        </dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
</project>