2016-07-13 13 views
1

Hier ist die Ordnerstruktur des Projektes bauen konstruieren:Wie Maven für Web-Anwendung, einschließlich des Aufbaus von UI und Server

src 
| 
|-frontend 
|  |-... 
|  |-dist 
| 
|-java-... 
| 
|-webapp-... 

Ich habe folgende npm Skripte:

"copy": "copyfiles -f ./src/index.html ./src/favicon.ico ./dist" 
"dist": "npm run copy & webpack --env=dist" 

In Jenkins bauen Ich möchte Maven das Frontend zuerst erstellen, npm dist Skript starten, dann Inhalt des Dist-Ordners in Webapp-Ordner kopieren und schließlich das Java-Programm erstellen

Antwort

0

Die Art, wie ich es tue ist, das Front-End und das Back-End in zwei verschiedenen Maven-Modulen in einem Maven-Projekt zu trennen, wenn man bedenkt, dass dies wirklich zwei verschiedene Artefakte sind. Ihre Module werden so bestellt, dass das Front-End zuerst gebaut wird.

<?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>demo</groupId> 
    <artifactId>so-multi-modules</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <name>so-multi-modules</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <modules> 
     <module>front-end</module> 
     <module>back-end</module> 
    </modules> 
</project> 

Die Front-End-Modul meist eine JavaScript-Anwendung mit Ihrem Liebling JS Build-Tool von Maven wie so (ich benutze Grunt) gekickstartet ist:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>grunt-deploy</id> 
        <phase>package</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
        <configuration> 
         <tasks> 
          <exec executable="grunt.cmd"> 
           <arg value="deploy" /> 
           <arg value="--force" /> 
          </exec> 
         </tasks> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

Ihr Back-End würde dann die antrun verwenden Plugin, um das Front-End zu kopieren, wo Sie es brauchen.

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>copy-front-end</id> 
        <phase>package</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
        <configuration> 
         <tasks> 
          <copy file="../front-end/target/path/to/dist" tofile="${project.build.directory}/path/to/dist/dest" overwrite="true" /> 
         </tasks> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build>