将Angular作为Maven项目的Maven模块添加进去。

huangapple go评论121阅读模式
英文:

Adding angular as maven module in maven project

问题

我正在工作于一个多模块的Maven项目,该项目分为以下模块:

  • REST层
  • 服务层
  • 存储层

我想要添加另一个名为"视图层"的模块,用于应用程序的用户界面(UI)。唯一的问题是UI是基于Angular的,我需要在Maven项目的模块中集成Angular应用程序。

我创建了一个名为"视图层"的新Maven模块。在"视图层"模块的pom中添加了以下插件配置:

  1. <plugin>
  2. <groupId>com.github.eirslett</groupId>
  3. <artifactId>frontend-maven-plugin</artifactId>
  4. <version>1.3</version>
  5. <configuration>
  6. <nodeVersion>v8.11.3</nodeVersion>
  7. <npmVersion>6.3.0</npmVersion>
  8. <workingDirectory>src/main/web/</workingDirectory>
  9. </configuration>
  10. <executions>
  11. <execution>
  12. <id>install node and npm</id>
  13. <goals>
  14. <goal>install-node-and-npm</goal>
  15. </goals>
  16. </execution>
  17. <execution>
  18. <id>npm install</id>
  19. <goals>
  20. <goal>npm</goal>
  21. </goals>
  22. </execution>
  23. <execution>
  24. <id>npm run build</id>
  25. <goals>
  26. <goal>npm</goal>
  27. </goals>
  28. <configuration>
  29. <arguments>run build</arguments>
  30. </configuration>
  31. </execution>
  32. <execution>
  33. <id>prod</id>
  34. <goals>
  35. <goal>npm</goal>
  36. </goals>
  37. <configuration>
  38. <arguments>run-script build</arguments>
  39. </configuration>
  40. <phase>generate-resources</phase>
  41. </execution>
  42. </executions>
  43. </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:

  1. &lt;plugin&gt;
  2. &lt;groupId&gt;com.github.eirslett&lt;/groupId&gt;
  3. &lt;artifactId&gt;frontend-maven-plugin&lt;/artifactId&gt;
  4. &lt;version&gt;1.3&lt;/version&gt;
  5. &lt;configuration&gt;
  6. &lt;nodeVersion&gt;v8.11.3&lt;/nodeVersion&gt;
  7. &lt;npmVersion&gt;6.3.0&lt;/npmVersion&gt;
  8. &lt;workingDirectory&gt;src/main/web/&lt;/workingDirectory&gt;
  9. &lt;/configuration&gt;
  10. &lt;executions&gt;
  11. &lt;execution&gt;
  12. &lt;id&gt;install node and npm&lt;/id&gt;
  13. &lt;goals&gt;
  14. &lt;goal&gt;install-node-and-npm&lt;/goal&gt;
  15. &lt;/goals&gt;
  16. &lt;/execution&gt;
  17. &lt;execution&gt;
  18. &lt;id&gt;npm install&lt;/id&gt;
  19. &lt;goals&gt;
  20. &lt;goal&gt;npm&lt;/goal&gt;
  21. &lt;/goals&gt;
  22. &lt;/execution&gt;
  23. &lt;execution&gt;
  24. &lt;id&gt;npm run build&lt;/id&gt;
  25. &lt;goals&gt;
  26. &lt;goal&gt;npm&lt;/goal&gt;
  27. &lt;/goals&gt;
  28. &lt;configuration&gt;
  29. &lt;arguments&gt;run build&lt;/arguments&gt;
  30. &lt;/configuration&gt;
  31. &lt;/execution&gt;
  32. &lt;execution&gt;
  33. &lt;id&gt;prod&lt;/id&gt;
  34. &lt;goals&gt;
  35. &lt;goal&gt;npm&lt;/goal&gt;
  36. &lt;/goals&gt;
  37. &lt;configuration&gt;
  38. &lt;arguments&gt;run-script build&lt;/arguments&gt;
  39. &lt;/configuration&gt;
  40. &lt;phase&gt;generate-resources&lt;/phase&gt;
  41. &lt;/execution&gt;
  42. &lt;/executions&gt;
  43. &lt;/plugin&gt;

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文件,添加以下配置:

  1. <properties>
  2. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  3. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  4. <maven.deploy.skip>true</maven.deploy.skip>
  5. </properties>
  6. <build>
  7. <plugins>
  8. <plugin>
  9. <groupId>org.codehaus.mojo</groupId>
  10. <artifactId>exec-maven-plugin</artifactId>
  11. <executions>
  12. <execution>
  13. <id>npm install</id>
  14. <goals>
  15. <goal>exec</goal>
  16. </goals>
  17. <phase>install</phase>
  18. <configuration>
  19. <executable>npm</executable>
  20. <arguments>
  21. <argument>install</argument>
  22. </arguments>
  23. </configuration>
  24. </execution>
  25. <execution>
  26. <id>npm build</id>
  27. <goals>
  28. <goal>exec</goal>
  29. </goals>
  30. <phase>install</phase>
  31. <configuration>
  32. <executable>npm</executable>
  33. <arguments>
  34. <argument>run</argument>
  35. <argument>build</argument>
  36. </arguments>
  37. </configuration>
  38. </execution>
  39. </executions>
  40. </plugin>
  41. </plugins>
  42. </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:

  1. &lt;properties&gt;
  2. &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  3. &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
  4. &lt;maven.deploy.skip&gt;true&lt;/maven.deploy.skip&gt;
  5. &lt;/properties&gt;
  6. &lt;build&gt;
  7. &lt;plugins&gt;
  8. &lt;plugin&gt;
  9. &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
  10. &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
  11. &lt;executions&gt;
  12. &lt;execution&gt;
  13. &lt;id&gt;npm install&lt;/id&gt;
  14. &lt;goals&gt;
  15. &lt;goal&gt;exec&lt;/goal&gt;
  16. &lt;/goals&gt;
  17. &lt;phase&gt;install&lt;/phase&gt;
  18. &lt;configuration&gt;
  19. &lt;executable&gt;npm&lt;/executable&gt;
  20. &lt;arguments&gt;
  21. &lt;argument&gt;install&lt;/argument&gt;
  22. &lt;/arguments&gt;
  23. &lt;/configuration&gt;
  24. &lt;/execution&gt;
  25. &lt;execution&gt;
  26. &lt;id&gt;npm build&lt;/id&gt;
  27. &lt;goals&gt;
  28. &lt;goal&gt;exec&lt;/goal&gt;
  29. &lt;/goals&gt;
  30. &lt;phase&gt;install&lt;/phase&gt;
  31. &lt;configuration&gt;
  32. &lt;executable&gt;npm&lt;/executable&gt;
  33. &lt;arguments&gt;
  34. &lt;argument&gt;run&lt;/argument&gt;
  35. &lt;argument&gt;build&lt;/argument&gt;
  36. &lt;/arguments&gt;
  37. &lt;/configuration&gt;
  38. &lt;/execution&gt;
  39. &lt;/executions&gt;
  40. &lt;/plugin&gt;
  41. &lt;/plugins&gt;
  42. &lt;/build&gt;

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

我认为你的

  1. &lt;workingDirectory&gt;src/main/web/&lt;/workingDirectory&gt;

是不正确的,因为你没有添加模块名

像这样

  1. &lt;workingDirectory&gt;frontend-module/src/main/web/&lt;/workingDirectory&gt;

这就是为什么它无法获取到你的 package.json 文件。

英文:

i think your

  1. &lt;workingDirectory&gt;src/main/web/&lt;/workingDirectory&gt;

is not correcte since you've not added the module name

like this

  1. &lt;workingDirectory&gt;frontend-module/src/main/web/&lt;/workingDirectory&gt;

thats is why it cannot get your package.json

huangapple
  • 本文由 发表于 2020年7月29日 19:46:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/63152906.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定