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

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

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:

&lt;plugin&gt;
    &lt;groupId&gt;com.github.eirslett&lt;/groupId&gt;
    &lt;artifactId&gt;frontend-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;1.3&lt;/version&gt;
    &lt;configuration&gt;
        &lt;nodeVersion&gt;v8.11.3&lt;/nodeVersion&gt;
        &lt;npmVersion&gt;6.3.0&lt;/npmVersion&gt;
        &lt;workingDirectory&gt;src/main/web/&lt;/workingDirectory&gt;
    &lt;/configuration&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;id&gt;install node and npm&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;install-node-and-npm&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
        &lt;execution&gt;
            &lt;id&gt;npm install&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;npm&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
        &lt;execution&gt;
            &lt;id&gt;npm run build&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;npm&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;configuration&gt;
                &lt;arguments&gt;run build&lt;/arguments&gt;
            &lt;/configuration&gt;
        &lt;/execution&gt;
        &lt;execution&gt;
            &lt;id&gt;prod&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;npm&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;configuration&gt;
                &lt;arguments&gt;run-script build&lt;/arguments&gt;
            &lt;/configuration&gt;
            &lt;phase&gt;generate-resources&lt;/phase&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&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文件,添加以下配置:

	<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:

	&lt;properties&gt;
		&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
		&lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
		&lt;maven.deploy.skip&gt;true&lt;/maven.deploy.skip&gt;
	&lt;/properties&gt;


	&lt;build&gt;
		&lt;plugins&gt;

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

		&lt;/plugins&gt;
	&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

我认为你的

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

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

像这样

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

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

英文:

i think your

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

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

like this

&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:

确定