Hello currently I have a parent git repo that houses two separate microservices written in Quarkus. For the ease of use within a CI/CD in the parent root folder I created a pom.xml that when I run a mvn package I want to be able to copy it into the parent/target/ path.
So the folder structure for instance is like this currently.
parent
target
pom.xml
/microservice1
- microservice1.jar
/microservice2
- microservice2.jar
but I want it to look like
parent
target
- microservice1.jar
- microservice2.jar
pom.xml
/microservice1
/microservice2
Since the parent folder/git repo doesn't have a pom.xml I generated one and this is what it looks like and I tried to use the maven-dependency-plugin suggestion that I found here
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>parent-service</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>microservice1</module>
<module>microservice2</module>
</modules>
<name>parent-service</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-artifact</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>${project.packaging}</type>
</artifactItem>
</artifactItems>
<!--<outputDirectory>../Main/target/dependencies</outputDirectory>-->
<!--CHANGE IS HERE -->
<outputDirectory>target</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
After running a mvn package at the parent folder the individual microservices are still packaging their own respective jars into microservice/target/ folders. Another weird interaction seems to be that the parent will just package it's own pom into it's own target/ folder. I could post the sub-microservices pom.xml files but those are quite long. What am I doing wrong? Did the way I create the pom not work well?
Related
I'm trying to add the web3j library ( version 5.0.0 ) into the generated .jar of a java project, but for some reason I keep getting the error :
Failed to parse plugin descriptor for org.web3j:core:5.0.0 (C:\Users\...\.m2\repository\org\web3j\core\5.0.0\core-5.0.0.jar): No plugin descriptor found at META-INF/maven/plugin.xml -> [Help 1]
( Tried different versions , same error )
The pom.xml file content is the following :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>BMarketMC-v2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>4.8.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
This error occurs when I run the package operation of the lifecycle , e.g :
Where exactly should be this META-INF folder? Because it's not in the project directory.
Please some help, any idea how can I fix this?
I'm not sure how much is this gonna help but I've solved my problem by giving up on using maven and add it as jar to project modules.
I have created a web application based on angular 8 and spring boot. I implemented the codebase locally and it is working fine.
My Angular code(client) is running on localhost:4200 and spring boot(server) is running on localhost:8080.
Till here everything is working as expected.
Now I want to deploy this whole web application as a single bundle so that I can deploy it as a single war on tomcat.
I am creating the war file using maven.
But when I deploy this war file on tomcat and start the tomcat I am not able to see the expected login page on the browser.
Basically, I don't have much understanding of maven and was following resource available in below link on the internet to generate the war file.
https://dzone.com/articles/building-a-web-app-using-spring-boot-angular-6-and
So I am not able to figure out whether the issue is with my build or the URL through which I am trying to access the resources.
if I deploy only the UI build, then if I hit localhost:8080, I am able to see the login page.
I am having three pom files as mentioned in the tutorial.
1. parent-pom
2. server-pom
3. ui-pom
Below are my pom files
parent-pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dzs.licenseGenerator</groupId>
<artifactId>lg-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath />
</parent>
<modules>
<module>LicenseGenerator_Backend</module>
<module>LicenseGenerator_UI</module>
</modules>
</project>
server-pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.dzs.licenseGenerator</groupId>
<artifactId>lg-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- lookup parent from repository -->
</parent>
<artifactId>LicenseGenerator_Backend</artifactId>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.dzs.licenseGenerator</groupId>
<artifactId>LicenseGenerator_UI</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals><goal>copy-resources</goal></goals>
<configuration>
<tasks>
<echo>Displaying value of pom.xml element</echo>
<echo>[project.build.directory] ${project.build.directory}</echo>
<echo>[project.parent.basedir] ${project.parent.basedir}</echo>
</tasks>
<outputDirectory>${project.build.directory}/classes/resources/</outputDirectory >
<resources>
<resource>
<directory>${project.parent.basedir}/LicenseGenerator_UI/dist/lg-app/</directory >
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
<warName>lg-app</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
UI-pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.dzs.licenseGenerator</groupId>
<artifactId>lg-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>LicenseGenerator_UI</artifactId>
<name>LicenseGenerator_UI</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<nodeVersion>v10.16.0</nodeVersion>
<npmVersion>6.9.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>
</plugins>
</build>
</project>
Just to ensure whether my code structure is correct or not I am posting a screenshot of my Project Explorer in Eclipse.
Use ng build –prod command for generating production build artifacts.
Run this command in your UI project folder.
Post generation of production build you should see new folder named ‘dist’.
You have to use Maven resource plugin to package as single jar. As i can see you already have the plugin in you pom, just verify the directory folder to pint to dist folder.
After this just run maven clean install . After running this you should see jar with both Angular 6 & Spring Boot application on the target folder.
Execute with Java –jar command to launch the application, you should see the Angular application served from static folder.
You can use frontend-maven-plugin for kicking off your frontend build. Once the frontend build is completed, it will generate the resource files in dist directory.
After that you can use the maven-resources-plugin to copy the files from dist to the required location in the target directory.
I am trying to find a good example on how you would build multiple zip files for a multi-module project with several runnable components using the maven-assembly-plugin.
My end result would hopefully have a single "dist" component that is capable of building all the necessary zip files.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xyz.exampleproject</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<name>Project Distribution</name>
<artifactId>dist</artifactId>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>component1-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>component2-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-bundles</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I would add one extra module per zip file that you want to create and configure the assembly plugin in there.
I'm working on a maven multi module application, which consists of two modules:
Common
Webapp
My project structure is as follow:
-(root)pom
-Common
-Webapp
We're using openshift web console with S2I (source to image) deploy. The image that we choose is Jboss Eap. After providing git repository, Openshift starts to create required resources. It successfully compile and install our modules using maven, however it does not deploy it on standalone folder for Jboss. Looking at the build log, we can check all dependencies being retrieve and BUILD SUCCESS at end of log. But no artifact deployed on image jboss folder. We can confirm this either by looking at the log or using console to check pod files.
This project is on bitbucket
Root pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>:: Parent ::</name>
<description>Parent POM for some app</description>
<modules>
<module>Common</module>
<module>Webapp</module>
</modules>
</project>
Common pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.test.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.test.common</groupId>
<artifactId>Common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Common module</name>
<description>Module for common elements that exist between projects</description>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Compiler plugin enforces Java 1.8 compatibility and activates annotation
processors -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
...
</dependencies>
</project>
And finally, the web pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.test.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.test.external</groupId>
<artifactId>Webapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name> Web</name>
<description>web module</description>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- JBoss dependency versions -->
<version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
<version.jboss.spec.javaee.7.0>1.0.3.Final</version.jboss.spec.javaee.7.0>
<!-- other plug-in versions -->
<version.war.plugin>2.1.1</version.war.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<build>
<!-- Set the name of the WAR, used as the context root when the app
is deployed -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
...
<dependency>
<groupId>com.test.common</groupId>
<artifactId>Common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
Does anyone manage to achieve this?
There is a better way I think, which is to use the openshift profile in your web pom. This goes back to the way it was done in V2. In the openshift profile, which will get invoked during the build, copy the .war file into the deployment directory. The only difference I noticed was the deployments directory was named target instead of webapps, but I didn't do any detailed test since target seems to work. E.g.:
<profiles>
<profile>
<!-- When built in OpenShift the openshift profile will be used when invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your app will need. -->
<!-- By default that is to put the resulting archive into the deployments folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different environments.html -->
<id>openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<outputDirectory>target</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
I end up using maven-antrun-plugin to copy war into jboss standalone folder.
<profile>
<id>openshift</id>
<properties>
<axis2.repo.path>/opt/eap/custom_modules</axis2.repo.path>
<ssl.cacerts.java.path>${java.home}/lib/security/cacerts</ssl.cacerts.java.path>
</properties>
<build>
<resources>
<resource>
<directory>/src/webapp/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy todir="${jboss.deploy.path}">
<fileset dir="${compiled.war.location}"/>
</copy>
<echo>war copied to ${jboss.deploy.path}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
I want to build a package and install it to my local repo. My pom file is:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.me</groupId>
<artifactId>MyApp</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<!-- This block declare a dependencies for this project -->
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<!-- This block declare a plugins -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
</plugin>
<!-- Installing to local repo -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<groupId>com.me</groupId>
<artifactId>MyApp</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<file>/Users/me/MyApp/target/MyApp-1.0.0.jar</file>
<generatePom>true</generatePom>
</configuration>
<executions>
<execution>
<id>install-jar-lib</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
But when I run "mvn package" comand I get a error that there is no file: /Users/me/MyApp/target/MyApp-1.0.0.jar So I comment install plugin, run "mvn package", uncoment install plugin and run "mvn package". Could I do this thing in one step? Without this comment-uncomment thing?
It's not clear why you need to invoke the install-file goal of maven-install-plugin but the problem lies in the phase. You configured it with <phase>validate</phase> when it should be <phase>package</phase> instead.
Take a look at the Introduction to the Build Lifecycle: phase validate is the first phase that is executed by Maven. At this time, the jar was not built so it can't work.
If you really want the artifact to be installed on the package phase (when running mvn package) then the phase should be set to package.
Note that instead of running mvn package, you should just call mvn install without the need of configuring the maven-install-plugin. The artifact will be automatically installed in your local repo with this command.
from what i know, mvn clean install, put the package in the local repo, without any need of any plugin