Tvorba webovych aplikaci s Apache Maven – zdrojaky

Úkol 1.2 - spustte aplikaci v tomcatu

Úkol 1.3 - na index.jsp zobrazte aktualni cas

public class IndexControllerServlet extends HttpServlet {

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

req.setAttribute("time", new Date().toString());

req.setAttribute("user", "pjetensk2345");

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");

dispatcher.forward(req, resp);

}

}

Úkol 2.1 - vypusťte jettyho

<build>

<finalName>TestWebApp</finalName>

<plugins>

<plugin>

<groupId>org.mortbay.jetty</groupId>

<artifactId>maven-jetty-plugin</artifactId>

<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>

</configuration>

</plugin>

</plugins>

</build>

Cargo - Automatická instalace kontejneru z URL

<plugin>

<groupId>org.codehaus.cargo</groupId>

<artifactId>cargo-maven2-plugin</artifactId>

<configuration>

<container>

<containerId>tomcat6x</containerId>

<zipUrlInstaller>

<url>http://websiterra.com/friends/apache/tomcat/tomcat-6/v6.0.26/bin/apache-tomcat-6.0.26.zip</url>

</zipUrlInstaller>

</container>

</configuration>

</plugin>


Deploy více warů

Varianta kontejner z URL

<plugin>

<groupId>org.codehaus.cargo</groupId>

<artifactId>cargo-maven2-plugin</artifactId>

<configuration>

    <container>... kontejner s ZipUrlInstaller ...</container>

    <configuration>

  <deployables><!--Deployables musí byt i dependency pomu -->

      <deployable>

  <groupId>${pom.groupId}</groupId>

  <artifactId>TestWebApp1</artifactId>

  <type>war</type>

  <properties><!-- url bude localhost/test -->

      <context>test1</context>

  </properties>

      </deployable>

      <!-- dalsi wary, ejb nebo eary -->

  </deployables>

    </configuration>

</configuration>

</plugin>

Varianta remote container

<plugin>

<!-- doplnte cargo groupId a artifactId -->

<configuration>

    <configuration>

  <type>runtime</type>

  <properties>  <cargo.tomcat.manager.url>http://localhost:8080/manager</cargo.tomcat.manager.url>

      <cargo.remote.username>admin</cargo.remote.username>

      <cargo.remote.password></cargo.remote.password>

  </properties>

    </configuration>

    <container>

  <containerId>tomcat6x</containerId>

  <type>remote</type>

    </container>

    <deployer>

  <type>remote</type>

  <deployables>

      <!-- doplnte deployables -->

  </deployables>

    </deployer>

</configuration>

</plugin>

Tomcat uživatel pro deploy

<!-- CATALINA_HOME/conf/tomcat-users.xml -->

<tomcat-users>

  <role rolename="manager"/> 

  <user username="admin" password="" roles="manager"/>  <!--  <role </tomcat-users>

Profily

<!-- ukazka pouziti property -->

<cargo.remote.password>${cargo.remote.password}</cargo.remote.password>

<!-- Deploy na localhost pres http - tomcat managera-->

<profile>

    <id>localhost</id> 

    <activation>

  <activeByDefault>true</activeByDefault>

    </activation>  

    <properties>

  <cargo.tomcat.manager.url>http://localhost:8080/manager</cargo.tomcat.manager.url>

  <cargo.remote.username>admin</cargo.remote.username>

  <cargo.remote.password></cargo.remote.password>

    </properties>

</profile>

Výchozí profil - activation/activeByDefault

<!-- Deploy na localhost pres http - tomcat managera-->

<profile>

   <id>localhost</id>

   <!-- mvn cargo:start je nyní stejne jako mvn cargo:start -P localhost -->

   <activation>

     <activeByDefault>true</activeByDefault>

   </activation>  

   ...

</profile>


Spuštění kontejneru v rámci integračního testu

mvn archetype:create -DgroupId=net.jetensky.webandmaven -DartifactId=TestWebApp -DarchetypeGroupId=org.codehaus.cargo -DarchetypeArtifactId=cargo-archetype-webapp-single-module


mvn archetype:create -DgroupId=net.jetensky.webandmaven -DartifactId=TestWebApp -DarchetypeGroupId=org.codehaus.cargo -DarchetypeArtifactId=cargo-archetype-webapp-functional-tests-module