| --- |
| Executable War |
| --- |
| Olivier Lamy |
| --- |
| 2011-01-10 |
| --- |
| |
| ~~ Licensed to the Apache Software Foundation (ASF) under one |
| ~~ or more contributor license agreements. See the NOTICE file |
| ~~ distributed with this work for additional information |
| ~~ regarding copyright ownership. The ASF licenses this file |
| ~~ to you 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 |
| ~~ |
| ~~ http://www.apache.org/licenses/LICENSE-2.0 |
| ~~ |
| ~~ Unless required by applicable law or agreed to in writing, |
| ~~ software distributed under the License is distributed on an |
| ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| ~~ KIND, either express or implied. See the License for the |
| ~~ specific language governing permissions and limitations |
| ~~ under the License. |
| |
| ~~ NOTE: For help with the syntax of this file, see: |
| ~~ http://maven.apache.org/doxia/references/apt-format.html |
| |
| Build an Executable War/Jar |
| |
| Starting with Version 2.0 of the plugin you can build an executable war/jar with an embedded Apache Tomcat7. |
| |
| This is only supported with the tomcat7 plugin. |
| |
| <<Note>> Your project must have a packaging value of <<<pom>>> or <<<war>>>. |
| |
| * Artifact to add to your war module: |
| |
| +-- |
| <project> |
| ... |
| <packaging>war or pom</packaging> |
| ... |
| <build> |
| ... |
| <plugins> |
| ... |
| <plugin> |
| <groupId>org.apache.tomcat.maven</groupId> |
| <artifactId>tomcat7-maven-plugin</artifactId> |
| <version>${project.version}</version> |
| <executions> |
| <execution> |
| <id>tomcat-run</id> |
| <goals> |
| <goal>exec-war-only</goal> |
| </goals> |
| <phase>package</phase> |
| <configuration> |
| <path>foo</path> |
| <!-- optional, needed only if you want to use a preconfigured server.xml file --> |
| <serverXml>src/main/tomcatconf/server.xml</serverXml> |
| <!-- optional values which can be configurable --> |
| <attachArtifactClassifier>default value is exec-war but you can customize</attachArtifactClassifier> |
| <attachArtifactClassifierType>default value is jar</attachArtifactClassifierType> |
| </configuration> |
| </execution> |
| </executions> |
| </plugin> |
| ... |
| </plugins> |
| ... |
| </build> |
| ... |
| </project> |
| +-- |
| |
| * Artifact to add to your pom module: |
| |
| +-- |
| <project> |
| ... |
| <packaging>war</packaging> |
| ... |
| <build> |
| ... |
| <plugins> |
| ... |
| <plugin> |
| <groupId>org.apache.tomcat.maven</groupId> |
| <artifactId>tomcat7-maven-plugin</artifactId> |
| <version>${project.version}</version> |
| <executions> |
| <execution> |
| <id>tomcat-run</id> |
| <goals> |
| <goal>exec-war-only</goal> |
| </goals> |
| <phase>package</phase> |
| <configuration> |
| <!-- optional only if you want to use a preconfigured server.xml file --> |
| <!-- |
| <serverXml>src/main/tomcatconf/server.xml</serverXml> |
| --> |
| <warRunDependencies> |
| <warRunDependency> |
| <dependency> |
| <groupId>a groupId</groupId> |
| <artifactId>and artifactId</artifactId> |
| <version>version</version> |
| <type>war</type> |
| </dependency> |
| <contextPath>/</contextPath> |
| </warRunDependency> |
| </warRunDependencies> |
| <!-- naming is disabled by default so use true to enable it --> |
| <enableNaming>true</enableNaming> |
| <!-- extra dependencies to add jdbc driver, mail jars, etc. --> |
| <extraDependencies> |
| <extraDependency> |
| <groupId>org.apache.derby</groupId> |
| <artifactId>derby</artifactId> |
| <version>10.1.3.1</version> |
| </extraDependency> |
| <extraDependency> |
| <groupId>javax.mail</groupId> |
| <artifactId>mail</artifactId> |
| <version>1.4</version> |
| </extraDependency> |
| </extraDependencies> |
| </configuration> |
| </execution> |
| </executions> |
| </plugin> |
| ... |
| </plugins> |
| ... |
| </build> |
| ... |
| </project> |
| +-- |
| |
| * Generated executable jar/war |
| |
| With the above configuration you can execute the generated jar due to its embedded Tomcat container |
| |
| +------ |
| java -jar yourjar |
| +------ |
| |
| Help output |
| |
| +------ |
| usage: java -jar [path to your exec war jar] |
| -ajpPort <ajpPort> ajp port to use |
| -clientAuth enable client authentication for |
| https |
| -D <arg> key=value |
| -extractDirectory <extractDirectory> path to extract war content, |
| default value: .extract |
| -h,--help help |
| -httpPort <httpPort> http port to use |
| -httpProtocol <httpProtocol> http protocol to use: HTTP/1.1 or |
| org.apache.coyote.http11.Http11Nio |
| Protocol |
| -httpsPort <httpsPort> https port to use |
| -maxPostSize <maxPostSize> max post size in bytes to use |
| -keyAlias <keyAlias> alias from keystore for ssl |
| -loggerName <loggerName> logger to use: slf4j to use slf4j |
| bridge on top of jul |
| -obfuscate <password> obfuscate the password and exit |
| -resetExtract clean previous extract directory |
| -serverXmlPath <serverXmlPath> server.xml to use, optional |
| -X,--debug debug |
| |
| +------ |
| |