Maven module jar missing - eclipse

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?

Related

Scala-Maven project on Eclipse

I am trying to use this Scala project.
The project contains maven dependencies so I have created a pom.xml and then I have imported the project as a maven project in eclipse.
In order to test the project I tried to add a Scala class, but I'm surprised that I can't.
this is my 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.group-name</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.12.6</version>
</dependency>
<dependency>
<groupId>org.opencypher</groupId>
<artifactId>spark-cypher</artifactId>
<version>0.1.5</version>
</dependency>
</dependencies>
</project>
i imported it to eclipse as a maven project then i build the maven project.
My questions are:
1) is my approach right ?
2) if 1) is right then how can I use this Scala project with maven ??
In order to import a Scala Maven Project on eclipse, you need to :
• install Scala plugin for eclipse (HELP>ECLIPS MARKETPLACE>”search for Scala ide”)
• Install Maven Integration for Scala IDE(HELP>INSTALL NEW SOFTWARE>”search for http://alchim31.free.fr/m2e-scala/update-site/”)
• Import project as Existing Maven Projects
Try the below POM
<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.group-name</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.12.6</version>
</dependency>
<dependency>
<groupId>org.opencypher</groupId>
<artifactId>spark-cypher</artifactId>
<version>0.1.5</version>
</dependency>
</dependencies>
</project>

Problems with Pom.xml

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).

Eclipse m2e not generating Maven Libraries for Java Resources

I am currently trying to create a m2e maven-archtype-webapp project in Eclipse, but I notice that it does not generate the Maven Libraries under the Java Resources directory.
<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>ord.code.ranch</groupId>
<artifactId>somewebapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>somewebapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>somewebapp</finalName>
</build>
</project>
Eclipse Juno - Project Explorer

Package does not exist when using Maven

<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.mycompany</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mavenproject1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
When I try to import com.mongodb, I get a package does not exist error. I had to manually add the .jar file to make it work. How do I get Maven dependency to work?
Thank you
You have the maven coordinate correct, and the artifact does exist on maven central repository. So I strongly believe your maven settings had configuration problem causing it unable to fetch from central repository.
This commonly occur when you're behind a company internal repository such as nexus and it has stale index, or you set your ~/.m2/settings.xml to NOT lookup from the central repo.

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???