cannot run npm grunt bower using maven - java

I have a simple web application that uses npm bower and grunt. I am using this project as a module in a maven project. I searched the internet and found how to define the pom.xml for the project but I am not able to run it. Can anyone tell me the steps on how to build and run the webapp using maven.
the pom.xml
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-bower-install</id>
<phase>generate-sources</phase>
<configuration>
<executable>bower</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-grunt</id>
<phase>process-resources</phase>
<configuration>
<executable>grunt</executable>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The error that I am getting is
[ERROR] Command execution failed.
java.io.IOException: Cannot run program "C:\Program Files\nodejs\npm" (in directory "C:\Users\krs\IdeaProjects\project"): CreateProcess error=193, %1 is not a valid Win32
application
How to build and run this pom using maven ?

The reason why you can't run it is because it's not an executable, it's a batch file or shell script if you're not on windows.
You can still use maven exec plugin to run it. However to do that you'll have to feed the batch file npm to cmd program (or bash or whatever is your favorite shell).
Following is the change that you'll need to make.
Actual command to feed batch to cmd
cmd /c "npm --version"
Following is the change in the plugin configuration.
<configuration>
<executable>cmd</executable> <!-- or bash -->
<workingDirectory>./</workingDirectory>
<arguments>
<argument>/c</argument>
<argument>"npm --version"</argument>
</arguments>
</configuration>
This should work.

Related

Finding files by pattern in Maven

I need to pre-process some of the resource files (*.xsl) in a Java Maven project.
I found the exec-maven-plugin which is able to execute shell commands and thought I can do it in 2 steps:
match a list of files and write it to a file
launch a Java program that pre-processes each file from the list
However I don't get any output from the find command I am trying to execute. The plugin configuration in POM looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>inline-xml-entities</id>
<phase>generate-resources</phase>
<configuration>
<executable>find</executable>
<useMavenLogger>true</useMavenLogger>
<outputFile>xsl-files.txt</outputFile>
<arguments>
<argument>./src/main/webapp/static/com/atomgraph/</argument>
<argument>-type</argument>
<argument>f</argument>
<argument>-name</argument>
<argument>'*.xsl'</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
I can see in the mvn clean install -X log that the command gets executed:
[DEBUG] Executing command line: [find, ./src/main/webapp/static/com/atomgraph/, -type, f, -name, '*.xsl']
The xsl-files.txt file gets created, but it's empty :/
If I go to the project basedir and execute find ./src/main/webapp/static/com/atomgraph/ -type f -name '*.xsl' manually, I get a list of .xsl files as expected:
./src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/admin/acl/imports/acl.xsl
./src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/admin/acl/layout.xsl
./src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/admin/layout.xsl
...
What am I missing?
This seems to have worked:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>find-xsl-files</id>
<phase>generate-resources</phase>
<configuration>
<executable>find</executable>
<workingDirectory>src/main/webapp/static/com/atomgraph/</workingDirectory>
<outputFile>xsl-files.txt</outputFile>
<commandlineArgs>. -type f -name '*.xsl'</commandlineArgs>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>

Using exec-maven-plugin to run npm commands in my pom.xml [duplicate]

When running exec-npm-update in maven , I am getting the following error
CreateProcess error=193, %1 is not a valid Win32 application -> [Help 1]
Below is the snippet from pom file.
<execution>
<id>exec-npm-update</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${uiResourcesDir}</workingDirectory>
<executable>npm</executable>
<arguments>
<argument>update</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
This problem happened because the angular version I am using is 1.5.
changing the executable from npm to npm.cmd solved the problem!
<execution>
<id>exec-npm-update</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${uiResourcesDir}</workingDirectory>
<executable>npm.cmd</executable>
<arguments>
<argument>update</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
I faced the same issue, as answered you need to provide npm.cmd instead just npm
If you like to run the shell or command prompt commands irrespective of environment. I am talking about npm.cmd (windows), npm.sh (linux) parts.
Downgrade the maven-exec-plugin to Version 1.4.0 so that you can just mention (For e.g.)
<executable>npm</executable>
<executable>ng</executable>

Angular2: Install external library using npm through Maven

Am building an Angular2 SpringBoot application which I need to deploy directly to a container like tomcat like a war file. Am able to successfully do that by install npm pluging in maven like:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<workingDirectory>${angular.project.location}</workingDirectory>
<installDirectory>${angular.project.nodeinstallation}</installDirectory>
</configuration>
<executions>
<!-- It will install nodejs and npm -->
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v9.2.0</nodeVersion>
<npmVersion>5.6.0</npmVersion>
</configuration>
</execution>
<!-- It will execute command "npm install" inside "/e2e-angular2" directory -->
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<!-- It will execute command "npm build" inside "/e2e-angular2" directory
to clean and create "/dist" directory -->
<execution>
<id>npm build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
Now, am also using Ng2Charts library to build highcharts on UI. I can simply run npm install ng2charts and would be good to go but I want to install these during mvn clean install because I don't want to create an added npm dependency on production.
Is there a way I can install these libraries using maven?
I tried something line:
<execution>
<id>ng2charts</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
But it gives me error saying:
[ERROR] [0m[1m[31mERROR in src/app/app.module.ts(48,5): Error during template compile of 'AppModule'[39m[22m[0m
[ERROR] [0m[1m[31m Could not resolve ng2-charts relative to /Users/user/Documents/workspace/MyPortal/src/frontend/src/app/app.module.ts..[39m[22m[0m
[ERROR] [0m[1m[31msrc/app/chart/chart.component.ts(5,20): error TS2307: Cannot find module 'jquery'.[39m[22m[0m
[ERROR] [0m[1m[31msrc/app/app.module.ts(23,30): error TS2307: Cannot find module 'ng2-charts'.[39m[22m[0m
[ERROR] [0m[1m[31m[39m[22m[0m.............
Please guide.
After a lot of research, i figured out a way to include external dependencies in Angular. We just need to update package.json file:
"dependencies": {
"ng2-charts": "^1.1.0",
"jquery": "^3.3.1"
}
This loads the libraries.

How to Rmic and Rmiregistry

I need to know how can I run Rmic. I have programmed my app in Java Eclipse and now I need to run Rmic. I tried it by running CMD, changing directory to Bin folder of my eclipse project and then typing command Rmic class name. It shows error unrecognised command. Is I am doing something wrong?
I use Maven and this is what I have in my pom file. It works quite well.
<groupId>org.codehaus.mojo</groupId>
<artifactId>rmic-maven-plugin</artifactId>
<executions>
<execution>
<id>rmi package</id>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<includes>
<include>**/*_Stub*</include>
</includes>
</configuration>
</execution>
<execution>
<id>rmi compilation</id>
<goals>
<goal>rmic</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</configuration>
</execution>

How to create JavaDoc documentation by using command mvn install?

I have a question concerning the maven javadoc plugin? I have configured that plugin with this values:
<build>
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<configuration>
<noqualifier>all</noqualifier>
<reportOutputDirectory>${basedir}/MyDoc/javadoc</reportOutputDirectory>
<destDir>javadoc</destDir>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>javadoc</goal>
</goals>
</execution>
</executions>
</plugin>
...
</build>
Is there a way to create some kind of documentation, if I use the command mvn clean install? I donĀ“t want to create a Jar File with my JavaDoc documentation, I need a way to create the JavaDoc and put the created source file directly in my maven project.
Thanks !
Greetz
Marwief
To execute plugin during certain phase, add <phase> to <execution>. Plugin should be fired:
<executions>
<execution>
<id>attach-javadocs</id>
<phase>install</phase> <------ HERE
<goals>
<goal>javadoc</goal>
</goals>
</execution>
</executions>
More on maven lifecycle here

Categories

Resources