Problems with Pom.xml - eclipse

I hope you guys can help me out.
I want to make a simple webLogin (Maven project) so far my code works. Now to make a build and deploy it i had to look into poms and i really tried but i don't know what i am doing wrong. Maybe someone knows how to do it right
My project tree:
pom.xml(project)
<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.apache.maven</groupId>
<artifactId>LoginTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>LoginTest</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
pom.xml(app)
<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>src.main.java</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>LoginTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>/pom.xml</relativePath>
</parent>
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
<exclude-ui>false</exclude-ui>
<api.ctx.root>/rest</api.ctx.root>
<ui.ctx.root>/webui</ui.ctx.root>
</properties>
</profile>
</profiles>
</project>
pom.xml(rest)
<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>src.main.java</groupId>
<artifactId>rest</artifactId>
<packaging>war</packaging>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>LoginTest</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>src.main.java.app</groupId>
<artifactId>Login.java</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
<packagingExcludes>WEB-INF/lib/*intf*.jar,WEB-INF/lib/*shared*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom.xml(webui)
<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>src.main.java</groupId>
<artifactId>webui</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>LoginTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
<exclude-ui>false</exclude-ui>
<api.ctx.root>/rest</api.ctx.root>
<ui.ctx.root>/webui</ui.ctx.root>
</properties>
</profile>
</profiles>
</project>
This is what i get right now and im sure this will not be the last ERROR i get..
[ERROR] Non-resolvable parent POM for src.main.java:app:1.0.0: Could not find artifact org.apache.maven:LoginTest:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 12, column 10 -> [Help 2]
Maybe someone can help me thanks in advance

Your project structure seems to be broken. You usually have one pom per project, and especially you should not have pom files in the src/main/java. If you want to define modules (subprojects) they need to have their own inner structure (as every Maven project).

Related

Maven module jar missing

I've got a multi-modules maven project and I'm trying to add a module to my project. I know a lot of questions have been asked but it didn't solved my problem. When I deploy my project, the .jar of my new module is not registered whereas my others modules are working properly.
I've added the new module in the pom of my parent module in my dependency management:
<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.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.33-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>base</module>
<module>mynewmodule</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.project</groupId>
<artifactId>base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.project</groupId>
<artifactId>mynewmodule</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
About the pom of the new module, I've specified the packaging to jar:
<?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.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.33-SNAPSHOT</version>
</parent>
<artifactId>mynewmodule</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.project</groupId>
<artifactId>base</artifactId>
</dependency>
</dependencies>
</project>
I've also done a maven build project.
I don't understand then why when I deploy my project with Jenkins, the jar of my new module is missing. Have I missed something?

SpringBootApplication can not be resolved to a type error in Spring tool suite and maven

I have created the maven project in spring tool suite. I created the pom.xml with required dependencies but facing error as "SpringBootApplication can not be resolved to a type".
I have tried a couple of solutions like Maven -> Update Project..., Clean Project, deleted local repository directory of Maven (.m2), etc... also I tried creating another maven project but still the same error.
I think this is eclipse spring tool suite problem with maven.
Is there any solution like patch by eclipse or anything else?
Thanks in advance!
Pom.xml as follows
<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>io.javabrains.springbootquickstart</groupId>
<artifactId>cource.api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Cource API</name>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
You did not add the correct dependencies.
You should add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
as a dependency (in <dependencies>) instead of spring-boot-starter-parent.
Parent just defines the versions but does not actually add any dependency (you use it as a <parent> in Maven).
If you have test, also add spring-boot-starter-test.
I would also suggest to use https://start.spring.io/ to generate a working Spring Boot base project (also available from STS in File->new->Other->Spring Starter project).
<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>io.javabrains.springbootquickstart</groupId>
<artifactId>cource.api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Cource API</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
Copy/Paste it in your POM.xml. Update the Maven project and it will fetch the required JARs.

Multi module Maven Project dependency issue?

I have a multi module project where common-project is depend on another 3rdparty project and below is the pom.xml of common-project
<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.tri.iss.pet.common</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>common-um-entities</artifactId>
<name>common-um-entities</name>
<description>Common UM Entities</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<fork>true</fork>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.tri.iss.pet.common</groupId>
<artifactId>3rdparty</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
As you clearly check i have added dependency in pom.xml file but check below image its saying jar missing
Can someone tell me why only project dependency not able to load while other dependency which coming from Artifactory working fine ?
Note:- Dont be confuse from project name .

JFXtras ClassNotFoundException on maven build

I am using Eclipse with the Maven integration and included JFXtras in my project. When I do the maven build, it successfully creates the jar, but when I try to run it, I get a
java.lang.ClassNotFoundException: jfxtras.scene.control.ListSpinner
I integrated jfxtras like described here:
http://mvnrepository.com/artifact/org.jfxtras/jfxtras-labs/8.0-r3
Edit:
<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>propgr</groupId>
<artifactId>Project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-labs</artifactId>
<version>8.0-r1</version>
</dependency>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-controls</artifactId>
<version>8.0-r1</version>
</dependency>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-common</artifactId>
<version>8.0-r1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Any ideas / help?
JFXtras consist of a number of artifact; labs, controls, common, ..., with some dependencies between them. The dependency for labs is missing. The pom below works for me.
<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>propgr</groupId>
<artifactId>Project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-labs</artifactId>
<version>8.0-r3</version>
</dependency>
</dependencies>
<build>
...
</build>
</project>
That is for a release, if you want to use a snapshot, you need to add the Sonatype snapshot repository in the pom or .m2/settings.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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>propgr</groupId>
<artifactId>Project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-labs</artifactId>
<version>8.0-r4-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
...
</build>
</project>

Creating multi module Maven Projects in Eclipse

Trying to create a multi module maven project in eclipse.
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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>parent</groupId>
<artifactId>proj1</artifactId>
<version>${myversion}</version>
<packaging>pom</packaging>
<properties>
<myversion>1.0.0</myversion>
</properties>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
</project>
Child-Module 1 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>
<parent>
<artifactId>proj1</artifactId>
<groupId>parent</groupId>
<version>${myversion}</version>
</parent>
<groupId>parent</groupId>
<artifactId>child1</artifactId>
<version>${myversion}</version>
</project>
Child Module 2 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>
<parent>
<artifactId>proj1</artifactId>
<groupId>parent</groupId>
<version>${myversion}</version>
</parent>
<groupId>parent</groupId>
<artifactId>child2</artifactId>
<version>${myversion}</version>
<dependencies>
<dependency>
<groupId>parent</groupId>
<artifactId>child1</artifactId>
<version>${myversion}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
If I use mvn clean install on command line from the parent folder I can build find. All the projects are build successfully.
But in eclipse I keep getting an error for Child Module 2 pom.xml
Description Resource Path Location Type
parent:child1:1.0.0:jar Missing:
----------
1) parent:proj1:pom:${myversion}
----------
1 required artifact is missing.
for artifact:
parent:proj1:pom:${myversion}
from the specified remote repositories:
central (http://repo1.maven.org/maven2, releases=true, snapshots=false)
pom.xml /child2 line 1 Maven Problem
I need to achieve 2 things
1. have a maven property define the version in the parent pom file.
2. use this property to define the version in all the child modules.
What should I do? I am stuck. Please help.
I am using Eclipse Galileo with m2Eclipse
This can't work, you can't get the version of the parent to use from the parent (and actually, properties don't get substituted in the parent element, see MNG-624). So you need to hard code the version and your parent POM should be:
<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>parent</groupId>
<artifactId>proj1</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
</project>
And in your child POM 1. you need to hardcode the version in /project/parent/version 2. you don't need to specify the <version> (you inherit it) 3. use the ${project.version} property in dependencies.
<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>
<parent>
<artifactId>proj1</artifactId>
<groupId>parent</groupId>
<version>1.0.0</version>
</parent>
<groupId>parent</groupId>
<artifactId>child2</artifactId>
<!--version>${myversion}</version--> <!-- Inherited -->
<dependencies>
<dependency>
<groupId>parent</groupId>
<artifactId>child1</artifactId>
<version>${project.version}</version> <!-- use the built-in property here -->
<!--type>jar</type--> <!-- This is a default, you can omit it -->
<!--scope>compile</scope--> <!-- This is a default, you can omit it -->
</dependency>
</dependencies>
</project>
Versionless parent elements will be supported in Maven 3.1.
See also
Missing artifact error in Maven
Eliminate Maven POM Redundancy
Maven 3 - Worth it???