Maven – Como iniciar o servidor tomcat


Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /home/feltexco/public_html/felix/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /home/feltexco/public_html/felix/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /home/feltexco/public_html/felix/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /home/feltexco/public_html/felix/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /home/feltexco/public_html/felix/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

Maven – Como iniciar o servidor tomcat

Olá amigos, hoje vamos explicar como iniciar o servidor de aplicação TOMCAT a partir de uma configuração no Maven. Neste momento é importante que vocês já tenham o maven e o Servidor Tomcat instalado.

Instalação do Tomcat e veja também o este artigo: Dica rápida: Instalação do Maven


1. Criação do projeto no padrão Maven

Crie o seu projeto web utilizando o comando abaixo:

1
mvn archetype:generate -DgroupId=br.com.feltex  -DartifactId=projetoweb  -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Isso criará o seu projeto com a estrutura web.

2. Configuração TOMCAT


Adicione as seguintes linhas ao arquivo tomcat-users.xml:

1
2
3
4
5
6
7
8
9
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="manager-script"/>
  <role rolename="manager-gui"/>  
 
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
  <user username="teco" password="teco01" roles="tomcat,role1,manager-script,manager-gui"/>

3. Configuração do Maven


No arquivo settings.xml adicione os dados para acesso ao servidor tomcat:

1
2
3
4
5
<server>
   <id>TomcatServer</id>
   <username>teco</username>
   <password>teco01</password>
 </server>

4. Arquivo POM


No seu arquivo POM é necessário realizar a configuração básica do plugin de deploy.
O Seu arquivo POM deve estar desta forma:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>br.com.feltex</groupId>
	<artifactId>projetoweb</artifactId>
	<packaging>war</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>projetoweb Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<build>
		<finalName>projetoweb</finalName>
		</plugins>
	</build>
</project>

Adicionaremos o plugin de deploy e seu arquivo POM deve estar dessa maneira:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>br.com.feltex</groupId>
	<artifactId>projetoweb</artifactId>
	<packaging>war</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>projetoweb Maven Webapp</name>
	<url>http://maven.apache.org</url>
 
	<build>
		<finalName>projetoweb</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.2</version>
				<configuration>
					<url>http://localhost:8080/manager/text</url>
					<server>TomcatServer</server>
					<path>/projetoweb</path>
				</configuration>
			</plugin>
 
		</plugins>
	</build>
</project>

5. Executando


Por fim vamos fazer a execução do projeto.

1. Quando o servidor estar iniciado podemos fazer os comandos:
mvn tomcat7:deploy
mvn tomcat7:undeploy
mvn tomcat7:redeploy

2. Quando o servidor estar parado podemos iniciar a aplicação com o seguinte comando:
mvn tomcat7:run-war

6. Conclusão

Pronto. Com isso já podemos fazer nossos projetos e criar nossas etapas de compilação, testes e implantação de forma automática. E isso já é um conversa que podemos ter sobre integração Contínua: Jenkins ou Hudson.

Links relacionados


Zip site oficial do Java
Aprenda como Compactar Arquivo com o JavaZip

Não deixe de curtir este post nas redes sociais. Dê a sua contribuição social e ajude o autor:

Deixe um comentário