GET STARTED WITH JAVA ENTREPRISE EDITION

Did you ever imagine that you only need three files to build your JAVA EE first application

Well it is that easy ! 


Create your maven project :



ignore errors :) 




copy this to POM.XML
<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>com.formation</groupId>
 <artifactId>my-jee-app</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>war</packaging>

 <dependencies>
  <dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-web-api</artifactId>
   <version>6.0</version>
   <scope>provided</scope>
  </dependency>
 </dependencies>

 <build>
  <pluginManagement>
   <plugins>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>3.2</version>
     <configuration>
      <verbose>true</verbose>
      <source>1.7</source>
      <target>1.7</target>
      <showWarnings>true</showWarnings>
     </configuration>
    </plugin>
    <plugin>
     <groupId>org.apache.tomcat.maven</groupId>
     <artifactId>tomcat7-maven-plugin</artifactId>
     <version>2.2</version>
     <configuration>
      <path>/</path>
      <contextReloadable>true</contextReloadable>
     </configuration>
    </plugin>
   </plugins>
  </pluginManagement>
 </build>
</project>

and this file to src/main/java/FirstServlet.java
package app1;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(urlPatterns = "/first")
public class FirstServlet extends HttpServlet {

 @Override
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
  PrintWriter out = response.getWriter();
  out.println("Formation JEE Freeways");
  

 }

}


also this file to src/main/java/WEB-INF/web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 version="3.0">

 

 <welcome-file-list>
  <welcome-file>first</welcome-file>
 </welcome-file-list>

</web-app>


and run it as Maven Built


Tara you have your first app ! what a champion !

هناك 3 تعليقات: