Maven projekt létrehozása

Telepítsük a VSCode fejlesztőkörnyezetet. Indítás után “Ctrl + Shift + x” és telepítsük az alábbi kiegészítőt:

  • Java Extension Pack

Magát a Maven-t külön kell telepíteni, innen: https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip

Telepítés után

  • ctrl + , megnyomásával állítsuk be a maven.executable.path változót oda, ahová telepítettük a Maven-t: pl: c:\maven\bin\mvn.cmd
  • Nyissuk meg a parancs palettát: Ctrl + Shift + p
  • Majd a következő parancsot indítsuk el: Java: Create Java Project
  • Válasszuk ki a projekt típusnak: “Maven”
  • Válasszuk ki továbbá (keresőbe gépelve): maven-archetype-webapp és a legmagasabb számú verziót
  • A parancssorban interaktív módban adjuk meg a 'csoport' és az 'alkotás' azonosítót:
Define value for property 'groupId': org.ait
Define value for property 'artifactId': simple

A forráskód létrehozása

A létrejövő pom.xml-t cseréljük le a következőre:

<?xml version="1.0" encoding="UTF-8"?>
 
<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>org.ait</groupId>
  <artifactId>simple</artifactId>
  <version>1.0-SNAPSHOT</version>
 
  <name>simple</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>
  <packaging>war</packaging>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
 
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.wildfly</groupId>
      <artifactId>wildfly-spec-api</artifactId>
      <version>19.1.0.Final</version>
      <type>pom</type>
      <scope>provided</scope>
    </dependency>
  </dependencies>
 
  <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <version>2.1.0.Beta1</version>
        <configuration>
          <add-user>
            <users>
              <user>
                <username>wildfly-admin</username>
                <password>wildfly.1234</password>
                <groups>
                  <group>admin</group>
                  <group>user</group>
                </groups>
                <application-user>false</application-user>
                <realm>ManagementRealm</realm>
              </user>
            </users>
          </add-user>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

A src/main/java/org/ait/HelloWorld.java állományba másoljuk be a következőt:

package org.ait;
 
import java.io.IOException;
import java.util.Date;
 
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
@WebServlet("/HelloWorld")
public class HelloWorld extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
    public HelloWorld() {
        super();
    }
 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	response.getWriter().append("Served at: ").append("" + new Date());
    }
 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	doGet(request, response);
    }
 
}

Indítás

A bal oldali explorer-ben alul van egy Maven fül, amiből a következő utasítások elindíthatók:

  • mvn wildfly:start elindítja a wildfly szervert
  • mvn wildfly:deploy telepíti a servletet

Az elkészült servlet a következő url-ről érhető el: http://localhost:8080/simple/HelloWorld

 
tanszek/oktatas/informatikai_rendszerek_epitese/vscode.txt · Last modified: 2021/03/24 11:47 by doku_admin
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki