Angular2: Install external library using npm through Maven - java

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.

Related

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

JMeter Maven Bamboo

My Bamboo instance is using Maven version 3.3.3. But I keep getting this error
Failed to execute goal com.lazerycode.jmeter:jmeter-maven-plugin:2.0.3:jmeter (jmeter-tests) on project test: The plugin com.lazerycode.jmeter:jmeter-maven-plugin:2.0.3 requires Maven version 3.1.1
This is an extract from the pom.xml file
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.0.3</version>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<testFilesDirectory>${project.basedir}/src/test/jmeter</testFilesDirectory>
<ignoreResultFailures>true</ignoreResultFailures>
<testResultsTimestamp>false</testResultsTimestamp>
</configuration>
</plugin>

cannot run npm grunt bower using maven

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.

Maven generated-sources/annotations

Hey guy's I'm posting this question having spent a good deal of time researching and not found a detailed answer. Currently I'm having an issue with generating sources from AWS Workflow. I'm using Maven apt-maven-plugin and aspectj-maven-plugin. These plugins both work for generating the client classes for the activities yet fail with the following error when running mvn clean package or mvn clean install against my workflow classes.
Error
[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-
plugin:1.7:compile (default) on project (myproject): Execution default
of goal org.codehaus.mojo:aspectj-maven-plugin:1.7:compile failed:
basedir (myproject)\target\generated-sources\annotations does not exist
-> [Help 1]
Plugins
<groupId>org.codehaus.mojo</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.0-alpha-5</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-flow-build-tools</artifactId>
</aspectLibrary>
</aspectLibraries>
<complianceLevel>1.7</complianceLevel>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<sources>
<source>
<basedir>${basedir}/target/generated-sources/annotations</basedir>
</source>
<source>
<basedir>src/main/java</basedir>
<includes>
<include>**/*.java</include>
</includes>
</source>
</sources>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
I'm not sure how to go about fixing this issue and any help would be great.
The error message is clear- mvn could not find /target/generated-sources/annotations, but in pom it is stated as the source for aspectj-maven-plugin.
Does your code intend to generate sources under /target/generated-sources/annotations? If yes, then there is issue with generation, you'll need to expose more of your pom for me to tell what went wrong. If no, why not remove this part and give it another shot.
<source>
<basedir>${basedir}/target/generated-sources/annotations</basedir>
</source>
ps: I'd rather put this as comment but I'm not able to :(

maven custom plugin not working after download from central repo

I've created custom plugin (http://search.maven.org/remotecontent?filepath=sk/lukasvasek/project-version-dategenerator-mvn/0.0.001/project-version-dategenerator-mvn-0.0.001.pom). When I install it locally (mvn install) i can use goal dateversionoverrider withou problem. Hovewer when I download this plugin from maven central repo I'm getting error:
[ERROR] Could not find goal 'dateversionoverrider' in plugin sk.lukasvasek:project-version-dategenerator-mvn:0.0.001 among available goals
what am I missing?
Thanks in advance
ok so problem was in descriptor, so I changed it to code below and it works.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<goalPrefix>project-version-dategenerator</goalPrefix>
</configuration>
<executions>
<execution>
<id>default-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
<phase>process-classes</phase>
</execution>
<execution>
<id>help-descriptor</id>
<goals>
<goal>helpmojo</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>

Categories

Resources