Uruchomienie aplikacji z użyciem pluginu Cargo
Uruchomienie aplikacji z użyciem pluginu Cargo
Cargo to wtyczka która umożliwia uruchomienie aplikacji z użyciem dowolnego kontenera. W tym artykule pokażę Ci w jaki sposób szybko uruchomić klasyczną aplikację typu Web bez konieczności pobierania zewnętrznego Tomcata. Tworzymy nowy projekt Mavena z użyciem archetypu – maven-archetype-webapp:
Po wykonaniu fazy mvn package zostanie zbudowana wynikowa paczka – war. Uruchomienie tej aplikacji wymaga użycia kontenera servletów np. Apache Tomcat. Celem uruchomienia aplikacji dodajmy do pliku pom.xml następujący plugin:
<plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>1.7.10</version> <configuration> <container> <containerId>tomcat8x</containerId> <type>embedded</type> </container> </configuration> </plugin>
zapis:
<type>embedded</type>
wynika z ograniczenia:
Running multiple Tomcat 7.x / Tomcat 8.x / Tomcat 9.x embedded containers within the same JVM
Tomcat 7.x has introduced a class called
TomcatURLStreamHandlerFactory
where the singleton has a staticinstance
field and a finalregistered
attribute which are not always in sync and cause unexpected exceptions. Due to this, it is not possible to execute Tomcat 7.x, Tomcat 8.x and / or Tomcat 9.x embedded in the same JVM, in addition running one of these Tomcat embedded versions one after the other within the same JVM but different classpaths might also fail.If you want to be safe, prefer using the Installed Container.
[źródło] – https://codehaus-cargo.github.io/cargo/Tomcat+9.x.html
W moim przypadku została zbudowana paczka – cargo.war ponieważ koordynaty projektu to:
<groupId>pl.javaleader</groupId> <artifactId>cargo</artifactId>
Uruchamiamy aplikację:
W logach wyraźnie widać, że aplikacja wystartowała na porcie 8080:
[INFO] [beddedLocalContainer] Tomcat 8.x Embedded started on port [8080] [INFO] Press Ctrl-C to stop the container...
Testujemy:
http://localhost:8080/cargo/index.jsp
wynik:
Hello World!
Leave a comment