Point to the sub folder Pom.xml from root pom.xml - java

I am working on spring boot application(with rest calls included) and i want to host it on heroku. Application works perfectly in my local machine.
Below is the Project Structure
.git
foldera
|
Mainclass
Pom.xml
folderb
|
other javacode
pom.xml
folderc
|
other javacode
pom.xml
Pom.xml(within root folder)
pom.xml of root folder is shown below
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>
<groupId>root</groupId>
<artifactId>pomroot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Server Spring Boot</name>
<description>Spring boot server for svmapp</description>
<properties>
<java.version>1.8</java.version>
</properties>
<modules>
<module>./foldera</module>
</modules>
</project>
I am using ./foldera to refer to subfolder using module tag. but this is not working.
All the folders are maven folders and added to the classpath. Now what i need is that from parent folder i want to refer to the Pom.xml of folder a.
How to achieve this?

Related

Probleme with Spring application, maven multi module and intelliJ Comunity

I'm working on a project with a parent maven module that contains no sources and 4 child modules.
It's supposed to be a Spring Application, the class having SpringApplication.run(XXX.class, args); is in a child module.
As I work with intelliJ community I don't have the spring plugin that could help me launch easely the application.
If I clean install the project everything builds correctly.
To start the application i try to right click on the class booting Spring and then click on run.
As intelliJ tries to build the app i get the following message :
Failed to execute goal on project XXX : Could not resolve dependencies
for project XXX:XXX:jar:0.0.28: Failed to collect dependencies at
XXX:XXX:jar:0.0.28: Failed to read artifact descriptor for
XXX:jar:0.0.28: Could not transfer artifact XXX:YYY:pom:${ZZZ_version_module} from/to
releases (http://nexus...): Authorization failed for
http://nexus.../.../.../$%257BZZZ_version_module%257D/...-$%257BZZZ_version_module%257D.pom
403 Forbidden
From what i understand the problem is that when building, intelliJ only build the child module, so it cannot turn the variablized version in my pom.xml ${ZZZ_version_module} into the right version using properties from the parent pom.
Because of my work, I cannot use any plugin in intelliJ or any other dependency in my pom that could help me.
Do any one have any solution to run the SpringApplication ?
Parent 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
</parent>
<groupId>ABC</groupId>
<artifactId>XYZ</artifactId>
<version>${ZZZ_version_module}</version>
<packaging>pom</packaging>
<name>...</name>
<description>...</description>
<properties>
<ZZZ_version_module>0.0.28</ZZZ_version_module>
...
</properties>
</project>
Child 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ABC</groupId>
<artifactId>XYZ</artifactId>
<version>${ZZZ_version_module}</version>
</parent>
<artifactId>...</artifactId>
<name>...</name>
<description>...</description>
</project>
(Sorry for the broken english)

Add source of my project A to my project B maven

I have 2 maven projects, Faction and Games.Games depends of Faction, so there's the dependency in my pom.xml.
<dependency>
<groupId>net.onima</groupId>
<artifactId>onimaFaction</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
They both are a project of my workspace.
Whenever I change the code in Faction, I would like to have the changes also in API and not install every changes, do you know how to do?
EDIT:
This is working for one project, but not for the other see :
Screenshot:
I think you describe a situation when you work on one project that has two modules,
In maven its called a multi-module project.
So basically you need to create a module with a packagine 'pom' that will list two modules:
- Games
- Faction
Each module will have its own 'src/main/....' layout as well as its own pom.xml.
All in all the project will look like this:
my-project
|___ pom.xml
|___ [ games ]
| |___ pom.xml
| |___ src/{main/test} etc.
|___ [ faction ]
|___ pom.xml
|___ src/{main/test} etc.
The 'root' pom.xml should look like this (snippet that illustrates the multi module only):
<groupId>...</groupId>
<artifactId>...<groupId>
<packaging>pom</packaging>
<modules>
<module>games</module>
<module>faction</module>
</modules>
The poms for games and faction modules should be like you have now.
Then, open the 'root' pom as a project in an IDE and you should be set.
I think what you'r trying to do is make Games a Module of Faction:
<?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.yourdomain</groupId>
<artifactId>faction</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>games</module>
</modules>
</project>
where Games has its own pom.xml/project and can be in a subdirectory in the Faction directory.
<?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.yourdomain</groupId>
<artifactId>games</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies.../>
</project>

way too long maven url

I'm following a course that implementes Java EE standards using the Vaadin framework, Maven, Spring Boot and JPA.
I have succesfully deployed my Maven project + modules to a Jboss WildFly Server.
A minor error that is ocurring is: in the course, the application URL is
http://localhost:8080/univers-web/*
but when I compile and run the application I have to type:
http://localhost:8080/univers-web-1.3.6.RELEASE
Is a minor annoyance ,but is there a way to remove the project version from the URL name?
I checked the pom.xml file and here is the starting snippet of code:
<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>
<artifactId>univers-web</artifactId>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<version>1.3.6.RELEASE</version>
<artifactId>spring-boot-starter-parent</artifactId>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
.
.
.
</project>
In the build section of your pom, add <finalName>univers-web</finalName>.

Can't find class from other Maven module when in package - IntelliJ

I'm struggling with this issue for a while now, i have a maven project in IntelliJ with 2 maven modules.
When i'm in the java folder (sources root) of my 2nd module, when i create a class, i can reference to the classes of my other project. But when i'm inside a package in the java folder, i am no longer able to use there classes of the other project.
Thanks in advance,
Link to images:
http://imgur.com/a/6wyYM
My POM.xml from the parent project:
<?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>
<packaging>pom</packaging>
<groupId>com.ucll.da</groupId>
<artifactId>project2</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>domain</module>
<module>webApp</module>
<module>rest</module>
</modules>
</project>
The POM files from domain and rest are basically the same:
<?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">
<parent>
<artifactId>project2</artifactId>
<groupId>com.ucll.da</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>domain</artifactId>
</project>
I found my solution but i don't really know why it works now.
My java files in the first Maven module (domain) were not inside a package, just inside the map Java. When I created a new package inside this Java map, and moved all my java files there, I could use these classes inside the other Maven module.

Run a multi-module Maven project

This is a basic question, I'm just not really familiar with maven multi-module structures. Say, I have a web application. And I want to connect some modules to it (some services). Do I need to make a web app just one of the modules, dependent from some others, and then run it? At first I thought I could run the whole project, but this option turns out to be inactive in my IDE (I'm using NetBeans now), which made me think I should run something like a main module (a web app in this case). Is it so? Thanks in advance.
If you have a multi-module project you need a structure like the following which will also be represented by the folder structure as well.
+-- root (pom.xml)
+--- module-1
+--- module-2
+--- module-war
Whereas the root module contains a thing like this:
<project ..>
<groupId>com.test.project</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>module-1</module>
<module>module-2</module>
<module>module-war</module>
</modules>
</project>
In the module-1 your pom should look like this:
<project ..>
<parent>
<groupId>com.test.project</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module-1</artifactId>
dependencies for the module
</project>
in module-2 it look more or less the same..and in the war module it looks like:
<project ..>
<parent>
<groupId>com.test.project</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<packaging>war</packaging>
<artifactId>module-war</artifactId>
dependencies for the module
</project>
If you have dependencies between the modules for example module-1 depends on module-2 it looks like the following in module-1:
<project ..>
<parent>
<groupId>com.test.project</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module-1</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module-2</artifactId>
<version>{project.version}</version>
</dependency>
..other dependencies..
</dependencies>
</project>
To build and package your project you will go to parent folder and do simply a
mvn clean package

Categories