Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
96 views
in Technique[技术] by (71.8m points)

How can I install npm by Maven in java

I need to install npm by maven

and I also use proxy.

I add such build code in my pom.xml

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.11.0</version>
                <executions>
                    <execution>
                        <!-- optional: you don't really need execution ids, but it looks nice
                            in your build log. -->
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <!-- optional: default phase is "generate-resources" -->
                        <phase>generate-resources</phase>
                        <configuration>
                            <nodeVersion>v0.10.33</nodeVersion>
                            <npmVersion>1.3.10</npmVersion>
                            <!-- optional: where to download node and npm from. Defaults to http://nodejs.org/dist/ -->
                            <!-- <downloadRoot>http://myproxy.example.org/nodejs/dist/</downloadRoot> -->
                            <!-- optional: where to install node and npm. Defaults to the working
                                directory -->
                            <!-- <installDirectory>target</installDirectory> -->
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <!-- optional: default phase is "generate-resources" -->
                        <phase>generate-resources</phase>
                        <configuration>
                            <!-- optional: The default argument is actually "install", so unless
                                you need to run some other npm command, you can remove this whole <configuration>
                                section. -->
                            <arguments>install</arguments>
                            <noProxy>true</noProxy>
                            <npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
                        </configuration>
                    </execution>
                    <execution>
                        <id>set-npm-registry</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <arguments>config set registry=</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>gulp build</id>
                        <goals>
                            <goal>gulp</goal>
                        </goals>
                        <!-- optional: the default phase is "generate-resources" -->
                        <phase>generate-resources</phase>
                        <!-- <configuration> optional: if not specified, it will run gulp's
                            default task (and you can remove this whole <configuration> section.) <arguments>homepagejs_minify</arguments>
                            </configuration> -->
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.kelveden</groupId>
                <artifactId>maven-karma-plugin</artifactId>
                <version>1.3</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
                <executions>
                    <execution>
                        <id>unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <configFile>./src/test/resources/karma-e2e.conf.js</configFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

and I also has such settings.xml

where I config my proxy

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 
    <localRepository>C:Usersz1.m2
epository</localRepository>

    <interactiveMode>true</interactiveMode>

    <offline>false</offline>

    <pluginGroups>

    </pluginGroups>

    <proxies>

        <proxy>
            <id>MyProxy</id>
            <active>true</active>
            <protocol>http</protocol>
            <host>myProxyHost</host>
            <port>8080</port>
        </proxy>

    </proxies>

    <servers>

    </servers>

    <mirrors>

    </mirrors>

    <profiles>

    </profiles>

</settings>

but npm cannot be installed by maven I got such error And as far as I understand windows blocks something my proxy cannot work

        [ERROR] npm ERR! System Windows_NT 6.2.9200

        [ERROR] npm ERR! command "C:\Users\abc\git1\q2cngom-partner\aoe_webapp\node\node.exe" "C:\Users\abc\git1\q2cngom-partner\aoe_webapp\node\node_modules\npm\bin\npm-cli.js" "install" "--color=false" "--proxy=http://myProxyHost:8080"

        [ERROR] npm ERR! cwd C:Usersabcgit1\webapp

        [ERROR] npm ERR! node -v v0.10.33

        [ERROR] npm ERR! npm -v 1.3.10

        [ERROR] npm

        [INFO] ------------------------------------------------------------------------

        [INFO] BUILD FAILURE

        [INFO] ------------------------------------------------------------------------

        [INFO] Total time:  02:32 min

        [INFO] Finished at: 2021-02-04T21:05:56+05:30

        [INFO] ------------------------------------------------------------------------

        [ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:0.0.26:npm (npm install) on project aoe_webapp: Failed to run task: 'npm install --color=false --proxy=http://myProxyHost:8080' failed. (error code 1) -> [Help 1]

        org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.eirslett:frontend-maven-plugin:0.0.26:npm (npm install) on project aoe_webapp: Failed to run task

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)

        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)

        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)

        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)

        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)

        at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)

        at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)

        at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)

        at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)

        at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)

        at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)

        at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke (Method.java:498)

        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)

        at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)

        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)

        at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

        Caused by: org.apache.maven.plugin.MojoFailureException: Failed to run task

        at com.github.eirslett.maven.plugins.frontend.mojo.AbstractFrontendMojo.execute (AbstractFrontendMojo.java:69)

        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)

        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)

        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)

        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)

        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)

        at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)

        at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)

        at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)

        at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)

        at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)

        at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)

        at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)

        at sun.refle

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...