英文:
Adding angular as maven module in maven project
问题
我正在工作于一个多模块的Maven项目,该项目分为以下模块:
- REST层
- 服务层
- 存储层
我想要添加另一个名为"视图层"的模块,用于应用程序的用户界面(UI)。唯一的问题是UI是基于Angular的,我需要在Maven项目的模块中集成Angular应用程序。
我创建了一个名为"视图层"的新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"目录中使用Angular CLI生成了一个Angular应用程序。
不幸的是,构建失败了,它找不到package.json文件。
我将感激任何帮助。
问候,
Darth Bato.
英文:
I am working in multi maven project which is separated in the following modules:
- rest layer
- service layer
- repository layer
I want to add another module called view layer, ui of the application. The only problem is that ui is angular, and i need somehow to integrate angular app in maven module for this project.
I created a new maven module called view layer. Added the following plugin it maven module pom of view layer like below:
<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>
And generated an angular app with angular cli inside src/main/web directory of view module.
Unfortunately the build is failing, it is not finding the package.json.
I will appreciate any help.
Regards,
Darth Bato.
答案1
得分: 0
我这样做是为了将Angular作为一个Maven模块添加到多模块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文件。我删除了src文件夹、test文件夹等,在创建Maven模块时自动生成的内容。
之后,我使用Angular CLI创建一个新的Angular应用程序。然后,我将Angular应用程序的所有内容(src、dist、node_modules等)移动到Maven模块项目中。
最后,为了检查是否一切正常,我运行Maven构建到父Maven项目,以查看是否一切都成功编译。
英文:
I do it this way to add angular as a maven module, in a multi maven project.
First thing I add a simple maven module by skipping the archetype selection. I modify the pom by adding the following configurations:
<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>
Next, I delete all the content in the module I created only leaving the pom file. I delete the src folder, test folder, etc that are creating when we create a Maven module.
After that, I create a new angular app by using ANGULAR CLI. I move all the content of the angular app(src, dist, nodes_modules, etc) to the maven module project.
In the end, to check if everything is ok, I run a maven build to parent maven project to see if everything compiles successfully.
答案2
得分: 0
我认为你的
<workingDirectory>src/main/web/</workingDirectory>
是不正确的,因为你没有添加模块名
像这样
<workingDirectory>frontend-module/src/main/web/</workingDirectory>
这就是为什么它无法获取到你的 package.json 文件。
英文:
i think your
<workingDirectory>src/main/web/</workingDirectory>
is not correcte since you've not added the module name
like this
<workingDirectory>frontend-module/src/main/web/</workingDirectory>
thats is why it cannot get your package.json
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论