-1

我正在从事多 Maven 项目,该项目分为以下模块:

  • 休息层
  • 服务层
  • 存储层

我想添加另一个名为视图层的模块,即应用程序的 ui。唯一的问题是 ui 是有角度的,我需要以某种方式将 angular 应用程序集成到这个项目的 maven 模块中。

我创建了一个名为 view layer 的新 maven 模块。在视图层的 maven 模块 pom 中添加了以下插件,如下所示:

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <version>1.3</version>
    <configuration>
        <nodeVersion>v8.11.3</nodeVersion>
        <npmVersion>6.3.0</npmVersion>
        <workingDirectory>src/main/web/</workingDirectory>
    </configuration>
    <executions>
        <execution>
            <id>install node and npm</id>
            <goals>
                <goal>install-node-and-npm</goal>
            </goals>
        </execution>
        <execution>
            <id>npm install</id>
            <goals>
                <goal>npm</goal>
            </goals>
        </execution>
        <execution>
            <id>npm run build</id>
            <goals>
                <goal>npm</goal>
            </goals>
            <configuration>
                <arguments>run build</arguments>
            </configuration>
        </execution>
        <execution>
            <id>prod</id>
            <goals>
                <goal>npm</goal>
            </goals>
            <configuration>
                <arguments>run-script build</arguments>
            </configuration>
            <phase>generate-resources</phase>
        </execution>
    </executions>
</plugin>

并在视图模块的 src/main/web 目录中生成了一个带有角度 cli 的角度应用程序。不幸的是,构建失败了,它没有找到 package.json。

我将不胜感激。

问候,达斯·巴托。

4

2 回答 2

0

我这样做是为了在多 Maven 项目中添加 Angular 作为 Maven 模块。

首先,我通过跳过原型选择来添加一个简单的 Maven 模块。我通过添加以下配置来修改 pom:

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.deploy.skip>true</maven.deploy.skip>
    </properties>


    <build>
        <plugins>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>install</phase>
                        <configuration>
                            <executable>npm</executable>
                            <arguments>
                                <argument>install</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm build</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>install</phase>
                        <configuration>
                            <executable>npm</executable>
                            <arguments>
                                <argument>run</argument>
                                <argument>build</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

接下来,我删除了我创建的模块中的所有内容,只留下了 pom 文件。我删除了创建 Maven 模块时创建的 src 文件夹、测试文件夹等。

之后,我使用 ANGULAR CLI 创建了一个新的 Angular 应用程序。我将 Angular 应用程序(src、dist、nodes_modules 等)的所有内容移动到 maven 模块项目中。

最后,为了检查一切是否正常,我对父 maven 项目运行了一个 maven 构建,以查看是否一切编译成功。

于 2020-07-29T11:58:30.400 回答
0

我认为你的

 <workingDirectory>src/main/web/</workingDirectory>

不正确,因为您尚未添加模块名称

像这样

<workingDirectory>frontend-module/src/main/web/</workingDirectory>

这就是为什么它无法获取您的 package.json

于 2020-07-29T14:32:26.420 回答