Maven not building reactjs files into my jar file - java

I am using exec-maven-plugin to run my maven build to build my reactjs project into my jar file, however, it executes fine but when I go into my jar file, none of the reactjs files are present - only my java classes are present.
My pom.xml looks like the following:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}src\main\app</workingDirectory>
<executable>npm.cmd</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec npm build</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}/src/main/app</workingDirectory>
<executable>npm.cmd</executable>
<arguments>
<argument>run-script</argument>
<argument>build</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>

Related

Maven do not execute script extern in clean phase but only in compile or install

With maven I set up a plugin that runs an external script.
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>3.0.0</version>
<executions>
<execution>
<id>Execute External Command</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>
${basedir}/external.sh
</executable>
</configuration>
</execution>
</executions>
</plugin>
The problem is that it also starts with the mvn clean command. Is it possible not to start the plugin in clean phase? or is it possible to parameterize my external script with a parameter that makes me understand that I am in the clean phase?
Something like:
<executable>
${basedir}/external.sh ${phase}
</executable>
Can you try to change the phase in your plugin, for exmple:
<phase>install</phase>
full plugin:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>3.0.0</version>
<executions>
<execution>
<id>Execute External Command</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>
${basedir}/external.sh
</executable>
</configuration>
</execution>
</executions>
</plugin>
you can choose any of the other suitable phases.

Adding angular as maven module in maven project

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:
<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>
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.
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:
<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>
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.
i think your
<workingDirectory>src/main/web/</workingDirectory>
is not correcte since you've not added the module name
like this
<workingDirectory>frontend-module/src/main/web/</workingDirectory>
thats is why it cannot get your package.json

ScalaBuff is giving an error while parsing protobuf file

I am getting the below error:
[INFO] --- exec-maven-plugin:1.2.1:exec (protobuf-sources) # structure-idl ---
<unknown>:1:1: string matching regex `\z' expected but `s' found
syntax = "proto3";
The below dependency is there and what I am trying to achieve is generate both Scala and Java file from protobuf file
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>initialize</phase>
<configuration>
<tasks>
<mkdir dir="target/generated-sources/scalabuff" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>protobuf-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
also adding the project build directory -->
<classpath/>
<argument>net.sandrogrzicic.scalabuff.compiler.ScalaBuff</argument>
<argument>--proto_path=src/main/protobuf</argument>
<argument>--scala_out=target/generated-sources/scalabuff</argument>
</arguments>
<sourceRoot>target/generated-sources/scalabuff</sourceRoot>
</configuration>
</plugin>

maven download plugin to add downloaded resource to jar

I am using download-maven-plugin to download some of resources to be used in my project. The download is successful and I can use the downloaded file.
However, what I want is to include the downloaded file in the JAR.
Note : The resource file will be included in the JAR when it was pre-downloaded before running the build, but if it is not present (e.g. deleted or I want to update it perhaps) the resource file is not included in the JAR.
Basically what I want is to include the recently downloaded file (from mvn clean install) in the output JAR.
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://downloadurl</url>
<outputFileName>error.json</outputFileName>
<outputDirectory>${project.resources.dir}/commons</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Same thing happens when I use maven-ant-run plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>download-files</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<get src="https://downloadurl"
dest="${project.resources.dir}/commons/data.json"
verbose="true"
usetimestamp="true"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Just download it to ${basedir}/target/classes before packaging phase. You don't need it to be in sources in order to include it to JAR.
Solved!
I changed the phase to process-resources..
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>download-files</id>
<phase>process-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<get src="https://downloadUrl"
dest="${project.resources.dir}/commons/error.json"
verbose="true"
usetimestamp="true"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>

Create symlink to the current jar package after mvn package

My jar file name is configured in pom.xml like this:
<finalName>MyApp-${project.version}</finalName>
I would like Maven ('mvn package') to create a symlink to the current jar file every time I run it, so that I have two files:
MyApp-1.0.3.jar
MyApp.jar (which is "ln -s MyApp-1.0.3.jar MyApp.jar")
You can use Exec Maven Plugin as below to achieve this goal:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.6.0</version>
<executions>
<execution>
<id>Version Calculation</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>ln</executable>
<arguments>
<argument>-fnsv</argument>
<argument>target/MyApp-${project.version}.jar</argument>
<argument>MyApp.jar</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Use below goals to execute it:
mvn clean verify
You can use symlink task/goal of ant-run plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<symlink link="${project.build.directory}/${project.artifactId}.jar"
resource="${project.build.directory}/${project.artifactId}-${project.version}.jar"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
If you want the symlinks to have relative path, you can give relative path in resource like below
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<symlink link="${project.build.directory}/${project.artifactId}.jar"
resource="./${project.artifactId}-${project.version}.jar"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Categories

Resources