# Tomcat con Jakarta EE

Guia:

{% embed url="https://www.mvc-spec.org/krazo/docs/install-servlet.html" %}

Dependencias

```markup
<!-- Get the API JARs for Java EE 8 -->
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>8.0</version>
</dependency>

<!-- Weld  -->
<dependency>
    <groupId>org.jboss.weld.servlet</groupId>
    <artifactId>weld-servlet-core</artifactId>
    <version>3.0.5.Final</version>
</dependency>

<!-- RESTEasy -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-cdi</artifactId>
    <version>3.6.1.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>3.6.1.Final</version>
</dependency>

<!-- Bean Validation -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-validator-provider-11</artifactId>
    <version>3.6.1.Final</version>
</dependency>

<!-- MVC + Eclipse Krazo for RESTEasy-->
<dependency>
    <groupId>javax.mvc</groupId>
    <artifactId>javax.mvc-api</artifactId>
    <version>1.0.0</version>
</dependency>
<dependency>
    <groupId>org.eclipse.krazo</groupId>
    <artifactId>krazo-resteasy</artifactId>
    <version>1.1.0-M1</version>
</dependency>
```

#### Configuration files <a href="#configuration_files" id="configuration_files"></a>

Make sure to add an empty `beans.xml` file in your `/src/main/webapp/WEB-INF` folder:

```markup
<?xml version="1.0"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
       version="2.0" bean-discovery-mode="all"
       metadata-complete="true">

</beans>
```

Note that the `metadata-complete` isn’t strictly necessary. It works around an [an issue in RESTEasy](https://issues.jboss.org/browse/RESTEASY-2289) that would otherwise cause RESTEasy (and thus Krazo) to start _twice_.

Please also add a file called `context.xml` to `src/main/resources/META-INF`:

```markup
<?xml version="1.0" encoding="UTF-8"?>
<Context>

   <Resource name="BeanManager" auth="Container"
             type="javax.enterprise.inject.spi.BeanManager"
             factory="org.jboss.weld.resources.ManagerObjectFactory"/>

</Context>
```

This file `context.xml` is essential for the operation of the CDI in Tomcat as described in the [Weld documentation](http://docs.jboss.org/weld/reference/latest/en-US/html_single/#tomcat).

The file to create is called `web.xml` and should be placed in the `src/main/webapp/WEB-INF` directory:

```markup
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

  <listener>
    <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
  </listener>

  <resource-env-ref>
    <resource-env-ref-name>BeanManager</resource-env-ref-name>
    <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
  </resource-env-ref>

  <!--http://docs.jboss.org/resteasy/docs/3.6.1.Final/userguide/html_single/index.html#d4e143 -->
  <context-param>
    <param-name>resteasy.injector.factory</param-name>
    <param-value>org.jboss.resteasy.cdi.CdiInjectorFactory</param-value>
  </context-param>

</web-app>
```
