Why doesn't maven see a specific version of the dependency? - java

I have a separate project, which I assemble into a jar file, and connect as an external dependency to my main project.
External project pom.xml
<groupId>my.group</groupId>
<artifactId>artif-idbla</artifactId>
<version>0.9.2</version>
<name></name>
<packaging>jar</packaging>
The command to place the jar file in a local repository.
mvn deploy:deploy-file -DgroupId=my.group -DartifactId=artif-idbla -Dversion=0.9.2 -Durl=file:C:/Development/local-maven-repo -DrepositoryId=local-maven-repo -DupdateReleaseInfo=true -Dfile=C:/path/my.jar
Then I connect it to the main project.
Main project pom.xml
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file://C:/Development/local-maven-repo</url>
</repository>
</repositories>
<dependency>
<groupId>my.group</groupId>
<artifactId>artif-idbla</artifactId>
<version>0.9.2</version>
</dependency>
It works!
Next, I make changes to my dependency, and I want to generate a new version of the project.I am changing the version from 0.92 to 0.9.21
External project pom.xml
<groupId>my.group</groupId>
<artifactId>artif-idbla</artifactId>
<version>0.9.21</version>
<name></name>
<packaging>jar</packaging>
I reassemble the jar file and put it in the local repository.
-Dversion=0.9.21
Changing the main project pom.xml.
<dependency>
<groupId>my.group</groupId>
<artifactId>artif-idbla</artifactId>
<version>0.9.21</version>
</dependency>
And I get an error.
Unresolved dependency: 'my.group:artif-idbla:jar:0.9.21'
This is what the local repository looks like.
Here is the structure maven-metadata.xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>my.group</groupId>
<artifactId>artif-idbla</artifactId>
<versioning>
<release>0.9.21</release>
<versions>
<version>0.9.2</version>
<version>0.9.21</version>
</versions>
<lastUpdated>20220707041151</lastUpdated>
</versioning>
</metadata>
For what reason does Maven not see version 0.9.21 but sees 0.9.2 ?
UPD 1.
I use Intellij Idea.
When updating pom.xml the main project, I'm trying to update maven.
If version 0.9.2 is specified, everything works if 0.9.21 is not updated.
The only output I see in the console.
Unresolved dependency: 'my.group:artif-idbla:jar:0.9.21'

Related

Import Maven local .jar as a lib

I made a simple Maven project for my class. According to the teachers tutorial we cannot upload it to our school repo due to some server issues, so we have to store it locally using altDeploymentRepository. I have the following 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.dpp</groupId>
<artifactId>simple_lib</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<altDeploymentRepository>internal.repo::default::file://${project.basedir}/../${project.name}-mvn-repo</altDeploymentRepository>
</configuration>
</plugin>
</plugins>
</build>
</project>
So in the directory with my Maven project I have two directories:
sample_lib
sample_lib-mvn-repo
In the second one, deep down in : sample_lib-mvn-repo\com\dpp\sample_lib\1.0-SNAPSHOT I have a .jar file which I want to import (but not using just .jar file like passing the path to it - I need to do this "Maven way", import it as Maven lib). Can I do it if the file is not stored on any remote repository, but on my hard drive?
Running simply mvn install will install the file in your local repository. The local repository, by default, is in your home directory, under .m2\repository.
Using your pom above, after running mvn install, you would have jar (and some other files) in .m2\repository\com\dpp\sample_lib\1.0-SNAPSHOT.
To import this subsequently in another project, you would create a dependency in that project's pom like:
<dependency>
<groupId>com.dpp</groupId>
<artifactId>simple_lib</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
This all takes place only on your machine, and will not use any remote repository.
Now you have a local simulation of a repository.
You can import it using the repository tag as described in https://maven.apache.org/pom.html#Repositories. To specify a file make it a file url like file:
Yes, you can add maven repository and point it to a local directory:
<repository>
<id>local</id>
<name>local</name>
<url>file:${user.dir}/sample_lib-mvn-repo</url>
</repository>
https://maven.apache.org/guides/introduction/introduction-to-repositories.html
Given that your jar file is here sample_lib-mvn-repo\com\dpp\sample_lib\1.0-SNAPSHOT.jar, you then can add it as a dependency:
<dependency>
<groupId>com.dpp</groupId>
<artifactId>sample_lib</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
It's not exactly what you're asking. But a quick and dirty solution is to make a POM project (no source code).
Inside the POM project you have the main and external projects.
You can simply make a dependency on the other project.

IntelliJ can't find Maven dependencies at runtime

I'm not getting any red lines, but IntelliJ can't find my Maven dependencies when I run the (Play) app. Tried invalidate cache/restart. Tried running mvn clean install.
compiler error message
(compile:compileIncremental) Compilation failed
[info] Compiling 8 Scala sources and 5 Java sources to /Users/****/IdeaProjects/GeoMood/target/scala-2.11/classes...
[error] /Users/****/IdeaProjects/GeoMood/app/views/show_tweets.scala.html:1: not found: value twitter4j
[error] #import twitter4j.Status
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>groupId</groupId>
<artifactId>geomood</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.8.0</version>
<classifier>models</classifier>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[4.0,)</version>
</dependency>
</dependencies>
</project>
Does anyone have any ideas why IntelliJ isn't picking this up? The maven build runs fine, and the dependencies are listed under external libraries.
I usually have to do the following to make IntelliJ aware of changes to my dependencies in the pom.xml:
Right click the root folder of the project in IntelliJ's project view
Go the the Maven menu item, and open the Maven submenu
Click Reimport
It sounds like you've hit bug IDEA-148573:
when a Maven dependency uses a classifier, IDEA ignores the classifier when building its classpath and tries to use the non-classified artifact for that dependency

Alfresco maven sdk error

I am new to alfresco, activity and maven.I want to design activiti workflow using Eclipse Mars 4.5.0. But i have to set alfresco maven sdk first. There is Alfresco Maven sdk error is given below. Any help will be appreciated.
pom.ml file is given below.
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>workflowProcess</groupId>
<artifactId>worflowProcessAr</artifactId>
<version>1.0-SNAPSHOT</version>
<name>worflowProcessAr AMP project</name>
<packaging>amp</packaging>
<description>Manages the lifecycle of the worflowProcessAr AMP (Alfresco Module Package)</description>
<parent>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-sdk-parent</artifactId>
<version>1.1.1</version>
</parent>
<!--
| SDK properties have sensible defaults in the SDK parent,
| but you can override the properties below to use another version.
| For more available properties see the alfresco-sdk-parent POM.
-->
<properties>
<!-- Defines the alfresco edition to compile against. Allowed values are [org.alfresco|org.alfresco.enterprise]-->
<alfresco.groupId>org.alfresco</alfresco.groupId>
<!-- Defines the alfresco version to compile against -->
<alfresco.version>4.2.e</alfresco.version>
<app.log.root.level>WARN</app.log.root.level>
<alfresco.data.location>alf_data_dev</alfresco.data.location>
<!-- Defines the target WAR artifactId to run this amp, only used with the -Pamp-to-war switch
. | Allowed values: alfresco | share. Defaults to a repository AMP, but could point to your foundation WAR -->
<alfresco.client.war>alfresco</alfresco.client.war>
<!-- Defines the target WAR groupId to run this amp, only used with the -Pamp-to-war switch
. | Could be org.alfresco | org.alfresco.enterprise or your corporate groupId -->
<alfresco.client.war.groupId>org.alfresco</alfresco.client.war.groupId>
<!-- Defines the target WAR version to run this amp, only used with the -Pamp-to-war switch -->
<alfresco.client.war.version>4.2.e</alfresco.client.war.version>
<!-- This controls which properties will be picked in src/test/properties for embedded run -->
<env>local</env>
</properties>
<!-- Here we realize the connection with the Alfresco selected platform
(e.g.version and edition) -->
<dependencyManagement>
<dependencies>
<!-- This will import the dependencyManagement for all artifacts in the selected Alfresco version/edition
(see http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies)
NOTE: You still need to define dependencies in your POM, but you can omit version as it's enforced by this dependencyManagement. NOTE: It defaults
to the latest version this SDK pom has been tested with, but alfresco version can/should be overridden in your project's pom -->
<dependency>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco-platform-distribution</artifactId>
<version>${alfresco.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Following dependencies are needed for compiling Java code in src/main/java;
<scope>provided</scope> is inherited for each of the following;
for more info, please refer to alfresco-platform-distribution POM -->
<dependencies>
<dependency>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco-repository</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- This repository is only needed to retrieve Alfresco parent POM.
NOTE: This can be removed when/if Alfresco will be on Maven Central
NOTE: The repository to be used for Alfresco Enterprise artifacts is
https://artifacts.alfresco.com/nexus/content/groups/private/. Please check
with Alfresco Support to get credentials to add to your ~/.m2/settings.xml
if you are a Enterprise customer or Partner
-->
<repositories>
<repository>
<id>alfresco-public</id>
<url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
</repository>
<repository>
<id>alfresco-public-snapshots</id>
<url>https://artifacts.alfresco.com/nexus/content/groups/public-snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
</repositories>
</project>
Maven will resolve the dependency by downloading the parent pom when you build. Do that by completing these steps:
Right-click on the pom.xml file and select Run As/Maven build...
In Goals, type install. This tells Maven to download any dependencies it doesn't already have.
Click Apply, then Run.
This should result in a successful build and the resolution of that error.
you can go ahead with "Finish", Eclips automatically resolve it by downloading.

POM is missing, no dependency information available, cfg.xml not found

I've tried to connect my application with database as described on this site: https://www.visual-paradigm.com/tutorials/hibernateinnetbeans.jsp
I use MySQL and Maven project. But the rest is done the way it was explained on the website and when I run CreateAutoPartsStore I have such output:
The POM for unknown.binary:orm:jar:SNAPSHOT is missing, no dependency information available
[...]
--- exec-maven-plugin:1.2.1:exec (default-cli) # AutoPartsStore ---
org.hibernate.HibernateException: /ormmapping/AutoPartsStore.cfg.xml not found
at org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2026)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2007)
at org.orm.PersistentManager.<init>(PersistentManager.java:72)
at autopartstore.AutoPartsStorePersistentManager.<init>(AutoPartsStorePersistentManager.java:31)
at autopartstore.AutoPartsStorePersistentManager.instance(AutoPartsStorePersistentManager.java:41)
at ormsamples.CreateAutoPartsStoreData.main(CreateAutoPartsStoreData.java:65)
This is my pom.xml file:
<?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.mycompany</groupId>
<artifactId>AutoPartsStore</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>unknown-jars-temp-repo</id>
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>unknown.binary</groupId>
<artifactId>orm</artifactId>
<version>SNAPSHOT</version>
</dependency>
</dependencies>
<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>
</project>
I found some solutions to the problem concerning copying XML files to another location, but none of them worked for me.
Looks like you need to add hibernate jar to the Maven dependecies list.
This:
<dependency>
<groupId>unknown.binary</groupId>
<artifactId>orm</artifactId>
<version>SNAPSHOT</version>
</dependency>
informs maven that your repository contains the artifact unknown.binary:orm:jar:SNAPSHOT but it seems it was never installed, and obviously is not present in Maven Central to be downloaded. What is it expected to point to?
Note that .jar lying around in folder marked as Maven repository does not make it count as installed. Also, Maven does not understand the notion of "Jar directory" and will not automatically add to classpath every jar from lib directory, if it is not declared as dependency.

How to get all of required Apache POI library using Maven?

I have installed maven and I created a project using this command:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
The result is there are 2 folder and 1 file created in my-app folder: src, target, and pom.xml.
Then I modify the pom.xml in order to get the all of required apache POI jars.
<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.mycompany.my-app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- This is what I added -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
</dependencies>
</project>
Then I run:
mvn package
but no jars downloaded into the project folder although I got message "BUILD SUCCESS".
What you've done is correct. However, the poi jars won't download to your project folder but to your local Maven repository. This is exactly what Maven is supposed to do so that you don't have to manage many libraries/jars yourself and get all in a mess. If you do a search of your local Maven repository, you should find it there.
I also suggest you read up on how Maven uses external dependencies, this is all explained here:
http://maven.apache.org/guides/getting-started/index.html#How_do_I_use_external_dependencies
If you want to package up all of your dependent jars in to one big jar look here:
How can I create an executable JAR with dependencies using Maven?
Your project has a jar packaging type. Java not support nested jar and then maven package doesn't put any jar in your project . To do this you have to use Maven Assembly Plugin or use Spring-boot to make your uber jar

Categories

Resources