How to Execute DOS commands through maven? - node.js

I got solution for ant but how can I execute DOS command through maven ?
I am building my script in gruntjs and for run that I use node command prompt but I want to execute that command through maven. Any Idea???

This might be a use case for Maven's Exec Plugin.
Experiment with exec:exec goal in the plugin.
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Script Run</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/<relativepathinyourproject>/yourscript.bat</executable>
</configuration>
</execution>
</executions>
</plugin>

Related

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (npm run build) on project npm

I am trying to deploy my web-app to heroku. To run my app i need to execute
npm run build
So i need to install npm to Heroku. I found maven plugins which does it.And a plugin which executes a script.
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- Use the latest released version:
https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
<version>1.7.5</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>
</execution>
</executions>
<configuration>
<nodeVersion>v11.15.0</nodeVersion>
<npmDownloadRoot>https://nodejs.org/dist/v6.11.3/win-x64/node.exe</npmDownloadRoot>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<id>npm run build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
But when i try to push it to heroku I get this:
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (npm run build) on project vstup: Command execution failed. Cannot run program "npm" (in directory "/tmp/build_6883506630fbb2f73ce1bcb9a5d6cf3d"): error=2, No such file or directory -> [Help 1]
I had a same error today with GitLab-ci and the spring-boot app.
I had to run before script to install the missing npm:
before_script:
- 'apt-get update'
- 'apt-get install -y npm'
script:
- 'mvn deploy'
This will install npm before running the maven exec plugin with the npm executable.
My mvn plugin configuration was:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<workingDirectory>${project.basedir}/src/main/frontend</workingDirectory>
</configuration>
<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>
</executions>
</plugin>
Hint:
maybe you can try to use after_script and before_script to run ls -Ra and see if a file or directory is missing, but it wasn't my case

Add generated sources to classpath

I use maven-jaxb2-plugin. It generate my classes in the correct directory, but on Eclipse Neon.2 Release (4.6.2), the folder is not automaticaly added to the classpath.
Here is my plugin config :
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<addCompileSourceRoot>true</addCompileSourceRoot>
<generateDirectory>${project.build.directory}/generated-sources/jaxb</generateDirectory>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<generatePackage>foo.bar.pojo</generatePackage>
</configuration>
</plugin>
</plugins>
</build>
Is it possible with maven-jaxb2-plugin to define the genearted directory as source folder ? If yes, how ?
Eclipse shows me an error in the pom.xml on <execution> :
Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate: com/sun/xml/bind/api/ErrorListener
To fix my problem, I had to change the version of the plugin.
From :
<version>0.13.1</version>
To :
<version>0.12.1</version>

Maven frontend build runs twice for generate-sources phase

My POM file has plugins that build the front end builds. However, when we run mvn clean install it runs the front end grunt/npm exec twice. How do I avoid multiple executions?
All help is appreciated. Since the grunt build takes time, removing the duplicate runs will shorten the build time.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
<workingDirectory>src/main/raw_ui</workingDirectory>
</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>
<workingDirectory>src/main/raw_ui</workingDirectory>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-grunt</id>
<phase>generate-sources</phase>
<configuration>
<executable>grunt</executable>
<arguments>
<argument>build</argument>
<argument>-f</argument>
</arguments>
<workingDirectory>src/main/raw_ui</workingDirectory>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
I don't really know why this solves the problem, but after changing the phase from 'generate-sources' to 'process-classes' did the thing, it now runs only once.
I've found here: Maven plugin executes multiple times during build that certain goals can execute certain lifecycles, that's why I tried changing the phase to run node scripts.

JAXB2-maven only builds in target

I'm on my first Java-Spring project. I need to communicate with a couple of webservices. I have some WSDL's provided, so i'm using Jax2B to autogenerate classes.
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.9.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>hello.wsdl</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
My project is a web project. The problem here is, my classes are generated in the targets folder, and not in my project. Does somebody have ideas how to fix this? Classes are generated properly, but not at the proper directory. As you can see, i'm using a test wsdl and mockup names at the moment. I followed this tutorial: http://spring.io/guides/gs/consuming-web-service/
Many thanks in advance
Author of the maven-jaxb2-pugin here.
target/generated-sources/xjc IS the proper directory. This is how generated code is handled in Maven builds, you never generate anything into src/main/java.
The maven-jaxb2-plugin also adds this directory to the Maven's sources directories. You just have to make sure that this directory is considered a source directory by your IDE. In Eclipse, m2eclipse plugin does this automatically when you do "Update project".
See this part of the docs.
I use this plugin to add the classes generated to source....
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/xjc</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

Sonar build does not run Cucumber tests

I am trying to run Sonar build on Jenkins. My project contains both Junit and Cucumber tests. I verified the log files after build, the Sonar build kicks off after normal maven build and picks only the Junit tests but not Cucumber tests.
I have the following versions and plugins available in my POM file. Please let me know if any one has come across the similar issue and fixed it. Many Thanks!
Junit version 4.11
Cucumber version 1.1.2
Sonar version 3.5.1
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<id>start-jetty</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>prepare-package</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<stopPort>8999</stopPort>
<stopKey>STOP</stopKey>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8997</port>
<maxIdleTime>3600000</maxIdleTime>
</connector>
</connectors>
<systemProperties>
<systemProperty>
<name>dqs.env</name>
<value>local</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*RunDQSWsTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*RunDQSWsTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
RunDQSWsTest.java is the main file which runs all the .feature files

Resources