Intellij - Add project as dependency to another project - maven

I am trying to make my project work on intellij (it works with eclipse). I have a project with this in my 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.fitnetapplication</groupId>
<artifactId>fitnet-common</artifactId>
<version>6.0.2-Final</version>
<packaging>war</packaging>
<name>FitnetCommon</name>
<description>Socle Commun FitnetManager / SyrhaLogic</description>
Now i have another project which needs to be linked to this one, so I had:
com.fitnetapplication
fitnet-common
6.0.2-Final
runtime
war
<dependency>
<groupId>com.fitnetapplication</groupId>
<artifactId>fitnet-common</artifactId>
<version>6.0.2-Final</version>
<type>jar</type>
<scope>provided</scope>
<classifier>classes</classifier>
</dependency>
The problem is that on Intellij, the version is not accepted for some reason, I don't know why, it tells me that the version 6.0.2-Final is not found for the artifact fitnet-common

To confirm - you are actually running mvn clean install (or similar) on the first project before trying to resolve the dependency in the second project?
If you are, it sounds like you're installing the project using one Maven repo location, and then in the other project it is looking in a completely different location. Are your .m2 location settings identical for both projects?
Edit:
Is it because you're specifying the first project as a war packaging, but in the dependency declaration you are looking for a jar? They would essentially be two different artefacts:
.war - com.fitnetapplication:fitnet-common:6.0.2-Final:war
.jar - com.fitnetapplication:fitnet-common:6.0.2-Final:jar
Check in your .m2/com/fitnetapplication/fitnet-common/6.0.2-Final to see what you have there, likely it is just the war file.

Related

How to import all provided Wildfly libraries in my maven project?

Is there a way to translate this human language in an xml codeblock that Maven will happily understand?
Hey Maven, look you are a great dependency management system. I am working on a JavaEE project which is intended to be deployed on Wildfly 10.1.0. Please put all Libraries that are specified in Wildflys parent BOM http://repo1.maven.org/maven2/org/wildfly/wildfly-parent/10.1.0.Final/wildfly-parent-10.1.0.Final.pom on the compiletime classpath and consider them as provided by Wildfly at runtime. And please dont bother me to list every single referenced artifact in the dependencies section of the projects pom file. Thank you Maven, you are so cool.
To clarify:
As far as I understand, importing the bom file in the dependencyManagement section of my pom file will only spare me to specify the Version Number of every single artifact, but I will still have to declare every artifactID and groupID.
This is indeed discussed here How to use BOM file with Maven
But in this answer is also stated:
Then you do not have to specify the version attribute of a dependency.
I would prefer to declare only that I am using wildfly and then be able to use all client libraries without declaring any other dependencies.
But I must admit, I have the feeling to miss something obvious. There should be an easy way to do this.
If you want everything in a another pom to be set as a dependency and as provided you can specify that in your pom. A minimal pom for wildfly 10.1.0.Final that includes everything seems to be 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>wft</groupId>
<artifactId>wft</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>wft</name>
<description>wft</description>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-spec-api</artifactId>
<version>10.1.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
But I would still recommend doing it the way that wildfly does it themselves, which is to put the BOM in the depencency management section and declare artifacts as you need them. Why? I don't know other than it's cleaner to read and maybe easier for maven/java to compile and build.

Generating the .war file from maven dependency project

Here I have two projects those are project(1) and project(2).
I am going to generate a .war file for the project(1) but it depends on project(2).
I built the project(2) as a .jar file and added it to the project(1)'s build path but while runnig mvn install it results in compilation errors like:
package com.disha.db.dao.orm.gen does not exist` the package is in the project(2).
Can any one please help to me.
You have to delegate dependency management to Maven and that's actually where it comes in hand, otherwise you can move on packaging and resolving inter-projects dependencies by hand and let the Maven alternative be dropped.
You should make sure you have provided the correct Project Object Module description for your projects (pom.xm) along with tha packaging type.
Then since you want the project(2) to be availble for project(1) at compilation time, you have to declare, project(2) as a dependency of project(1).
project(2) pom.xml (I will refer to it as project-2 since 'project(2)' does not match a valid id pattern.):
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>project2.group.id</groupId>
<artifactId>project-2</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
</project>
Now the project(1) will refer to the project-2 artifact as a dependency with scope compile:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>project1.group.id</groupId>
<artifactId>project-1</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>project2.group.id</groupId>
<artifactId>project-2</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
Note: Update the group and artifact IDs with ones you are using.

Why Maven is looking for .pom file when .jar is present in the repository?

I have the following dependency in my pom.xml
<dependency>
<groupId>aGroup</groupId>
<artifactId>anArtifact</artifactId>
<version>aVersion</version>
</dependency>
I also have the anArtifact-aVersion.jar file in ~/.m2/repository/aGroup/anArtifact/aVersion directory.
When I start building the project, maven looks for a .pom file instead of using the .jar file and attempts to download the following
http://repo1.maven.org/maven2/aGroup/anArtifact/aVersion/anArtifact-aVersion.pom
How can I configure maven to use the existing .jar file?
Every jar needs to have a pom file describing it, you can just add something simple like this:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aGroup</groupId>
<artifactId>aArtifactId</artifactId>
<version>aVersion</version>
<packaging>jar</packaging>
<name>a Name</name>
</project>
Run your build using the "-o" switch to use Maven in offline mode. In offline mode, Maven will not check for updates of snapshot dependencies in remote repositories.
the best way to install an artifact to the local repository which were not built by Maven ist to use
mvn install:install-file ...
have a look at the install:install goal.
POM that is installed to nexus will describe the jar. Used to pull the dependencies that are associated to corresponding jar. When we add the jar as dependency to our project, all the jars required for the included jar will be identified through the corresponding pom.
It is looking for the pom to, among other things, resolve the transitive dependencies.

Maven Systempath not working as expected

I have specified following dependencies(For example mentioned one here) in pom.xml which will look for saaj.jar under the specified sytempath and Maven used to pick it from same path and working fine.
<dependency>
<groupId>saaj</groupId>
<artifactId>saaj</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/saaj.jar</systemPath>
</dependency>
Now I have moved to windows 7 and Spring Tool suite 2.7.1 version(Previously Win XP and Spring older vesion). In this new setup am getting below error.
Missing artifact saaj:saaj:jar:1.0:system
Now, It is looking for saaj-1.0.jar instead of saaj.jar and under the folder ${basedir}/src/main/webapp/WEB-INF/lib/saaj/saaj/1.0/ instead of ${basedir}/src/main/webapp/WEB-INF/lib/.
Why is it so? Please provide the solution where my previous setup should work fine.
Avoid systemPath, you must create a local repository like :
this is you pom file :
<repositories>
<repository>
<id>local-repo</id>
<url>file://${basedir}/lib</url>
</repository>
</repositories>
<dependency>
<groupId>tiago.medici</groupId>
<artifactId>eureka</artifactId>
<version>0.0.1</version>
</dependency>
on project you create a lib folder to put your jar and maven pom file generated from
mvn install:install-file -Dfile=c:\tiago.medici-0.0.1.jar -DgroupId=tiago.medici -DartifactId=eureka -Dversion=0.0.1 -Dpackaging=jar
tiago.medici-0.0.1.pom
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>tiago.medici</groupId>
<artifactId>eureka</artifactId>
<version>0.0.1</version>
<description>POM was created from install:install-file</description>
</project>
Don't use system scope. It was meant for system provided libraries. Given the path you gave for it, you are obviously creating a web application.
Use a war project and specify your dependencies with provided scope if they're already available (e.g. because they are provided by your application server) or without a scope specification otherwise. Maven will take care of packaging your project dependency in a correct way, both for Eclipse development and for deployment in your application server.

Maven can't find httpcomponents-client in repository

I am trying to add the Apache httpcomponents-client library to my Maven project. I have added a dependency to pom.xml (as found on http://mvnrepository.com/artifact/org.apache.httpcomponents/httpcomponents-client/4.1.1), but when building my Eclipse project Maven is unable to find and download the library.
I have made a test project which does nothing but include this library to ensure that it's not any other settings that cause problems:
<?xml version="1.0"?>
<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>no.gundelsby.test</groupId>
<artifactId>NeedMyPackage</artifactId>
<version>0.1</version>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcomponents-client</artifactId>
<version>4.1.1</version>
</dependency>
</dependencies>
</project>
Building this project results in the same error.
Other things I have tested:
Tried building with vanilla installs of both Maven 2.2.1 and 3.0.3
Had a friend build the test project on his computer to rule out local problems on my computer
Changed the version from 4.1.1 to 4.1
For what it's worth I had the same problem a few days ago with org.easytesting.fest-swing, see pom dependency entry below:
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-swing</artifactId>
<version>1.2.1</version>
</dependency>
You don't want httpcomponents-client as a dependency. That's just the parent pom for the client-related modules. I suspect you actually want <artifactId>httpclient</artifactId>.
Here a simple solution...
Its great for me...
You can downloar jar file from internet and add manually to project from netbeans or another IDE.
Here an example for you:
enter image description here
Search the downloaded jar in your computer
enter image description here

Resources