Outils pour utilisateurs

Outils du site


projets:2018:stagejava

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
Prochaine révisionLes deux révisions suivantes
projets:2018:stagejava [2019/01/12 15:53] christian.jacolotprojets:2018:stagejava [2019/03/02 14:33] christian.jacolot
Ligne 334: Ligne 334:
         <version>2.7</version>         <version>2.7</version>
     </dependency>     </dependency>
 +    
 +<dependency>
 +    <groupId>org.glassfish.jaxb</groupId>
 +    <artifactId>jaxb-runtime</artifactId>
 +    <version>2.3.2</version>
 +</dependency>
 +    
 </dependencies> </dependencies>
  
 +
 +Class EntryPoint.java
 +
 +<code>
 +package net.mdl29.test;
 +
 +import javax.ws.rs.GET;
 +import javax.ws.rs.Path;
 +import javax.ws.rs.Produces;
 +import javax.ws.rs.core.MediaType;
 +
 +@Path("/entry-point")
 +public class EntryPoint {
 +
 +    @GET
 +    @Path("test")
 +    @Produces(MediaType.TEXT_PLAIN)
 +    public String test() {
 +        return "Test";
 +    }
 +}
 +</code>
 +
 +
 +Class App.java
 +
 +<code>
 +package net.mdl29.test;
 +
 +import org.eclipse.jetty.server.Server;
 +import org.eclipse.jetty.servlet.ServletContextHandler;
 +import org.eclipse.jetty.servlet.ServletHolder;
 +
 +public class App {
 +    public static void main(String[] args) throws Exception {
 +        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
 +        context.setContextPath("/");
 +
 +        Server jettyServer = new Server(8080);
 +        jettyServer.setHandler(context);
 +
 +        ServletHolder jerseyServlet = context.addServlet(
 +             org.glassfish.jersey.servlet.ServletContainer.class, "/*");
 +        jerseyServlet.setInitOrder(0);
 +
 +        // Tells the Jersey Servlet which REST service/class to load.
 +        jerseyServlet.setInitParameter(
 +           "jersey.config.server.provider.classnames",
 +           EntryPoint.class.getCanonicalName());
 +
 +        try {
 +            jettyServer.start();
 +            jettyServer.join();
 +        } finally {
 +            jettyServer.destroy();
 +        }
 +    }
 +}
 +</code>
 +
 +
 +
 +
 +Ajouter la gestion du manifeste dans pom.xml
 +
 +<code>
 +<build>
 +...
 +
 +<plugins>
 +    <plugin>
 +      <groupId>org.apache.maven.plugins</groupId>
 +      <artifactId>maven-shade-plugin</artifactId>
 +      <version>1.6</version>
 +      <configuration>
 +        <createDependencyReducedPom>true</createDependencyReducedPom>
 +        <filters>
 +          <filter>
 +            <artifact>*:*</artifact>
 +            <excludes>
 +              <exclude>META-INF/*.SF</exclude>
 +              <exclude>META-INF/*.DSA</exclude>
 +              <exclude>META-INF/*.RSA</exclude>
 +            </excludes>
 +          </filter>
 +        </filters>
 +      </configuration>
 + 
 +      <executions>
 +        <execution>
 +          <phase>package</phase>
 +          <goals>
 +            <goal>shade</goal>
 +          </goals>
 +          <configuration>
 +            <transformers>
 +              <transformer
 +                implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
 +              <transformer
 +                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
 +                <manifestEntries>
 +                  <Main-Class>net.mdl29.test.App</Main-Class>
 +                </manifestEntries>
 +              </transformer>
 +            </transformers>
 +          </configuration>
 +        </execution>
 +      </executions>
 +    </plugin>
 +  </plugins>
 + ...
 +
 +</build>
 +
 +</code>
 +
 +pom.xml
 +<code>
 +<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/xsd/maven-4.0.0.xsd">
 +    
 +    <modelVersion>4.0.0</modelVersion>
 +    <groupId>net.mdl29.websocket</groupId>
 +    <artifactId>chatwebsocket</artifactId>
 +    <version>0.0.1-SNAPSHOT</version>
 +    <packaging>war</packaging>
 +    
 +    <properties>
 +        <tomcat.version>9.0.16</tomcat.version>
 +        <websocket.version>1.1</websocket.version>
 +        <jackson.version>2.9.8</jackson.version>
 +    </properties>
 +          
 +    <dependencies>
 +        <!-- Dependency needed by the Web-socket -->
 +        <!-- Tomcat has it, so no need to package into the war file -->
 +        <dependency>
 +            <groupId>javax.websocket</groupId>
 +            <artifactId>javax.websocket-api</artifactId>
 +            <version>${websocket.version}</version>
 +            <scope>provided</scope>
 +        </dependency>
 +        
 +        <!-- Used to serialize the message from the browser -->
 +        <dependency>
 +            <groupId>com.fasterxml.jackson.core</groupId>
 +            <artifactId>jackson-databind</artifactId>
 +            <version>${jackson.version}</version>
 +        </dependency>
 +        
 +        <!-- Sevlet jars for compilation, provided by Tomcat -->
 +        <dependency>
 +            <groupId>org.apache.tomcat</groupId>
 +            <artifactId>tomcat-servlet-api</artifactId>
 +            <version>${tomcat.version}</version>
 +            <scope>provided</scope>
 +        </dependency>
 +    </dependencies>
 +      
 +    <build>
 +        <finalName>${project.artifactId}</finalName>
 +        <plugins>
 +            <plugin>
 +                <artifactId>maven-compiler-plugin</artifactId>
 +                <version>3.1</version>
 +                <configuration>
 +                <source>1.8</source>
 +                <target>1.8</target>
 +                </configuration>
 +            </plugin>
 +                      
 +            <plugin>
 +                <artifactId>maven-war-plugin</artifactId>
 +                <version>2.4</version>
 +                <configuration>
 +                <warSourceDirectory>WebContent</warSourceDirectory>
 +                <failOnMissingWebXml>false</failOnMissingWebXml>
 +                </configuration>
 +            </plugin>
 +        </plugins>
 +    </build>
 +    
 +</project>
 +</code>
  
projets/2018/stagejava.txt · Dernière modification : 2024/04/16 22:26 de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki