This question already has answers here:
How to add local jar files to a Maven project?
(35 answers)
Closed 2 years ago.
I have a pre-compiled artifact Framework-0.0.1-SNAPSHOT.jar located in \lib folder. In my maven I try to use and include that as 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>
<groupId>com.heroic.backend</groupId>
<artifactId>BackendHeroic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>BackendHeroic</name>
<dependencies>
<dependency>
<groupId>com.heroic.utilities</groupId>
<artifactId>Framework</artifactId>
<scope>compile</scope>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
</project>
But look like I cannot import anything in my code from that Framework jar file. Can you please let me know what's wrong with my setup above? Thank you
You can add a local repository:
<repositories>
<repository>
<id>local-libs</id>
<name>Libs Local Repository</name>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>
Then you can add a dependency:
<dependencies>
<dependency>
<groupId>my.company</groupId>
<artifactId>Framework</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
But you need to put your jar file under /lib/my/company/0.0.1-SNAPSHOT/Framework-0.0.1-SNAPSHOT.jar
Maven looks in the Internet for dependencies, it does not inspect lib directory.
If this artifact built with maven in another project, just install it into your local repository cache: mvn install
If you just got this jar file from someone, install it with the following command:
mvn install:install-file -Dfile=Framework-0.0.1-SNAPSHOT.jar -DgroupId=com.heroic.utilities -DartifactId=Framework -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
you can write it into bat or sh script for other people.
Related
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.
I have a maven project (I use the jersey template, since I'll be creating an API) and would like to add an external jar file. I tried to follow this reference here
I'm using Eclipse Mars in Windows environment. I added the following depedency to my pom.xml file
Now, when I try to use the jar file in my application, why is that I can't access it? The classes in the jar file couldn't be resolved.
I sometimes use file system based repos for this kind of thing.
<repositories>
<repository>
<id>local-files</id>
<name>local-files</name>
<url>file://c:\test\filerepo</url>
</repository>
</repositories>
Then you can install files into the file repo...
mvn install:install-file -Dfile=onebusaway-gtfs-1.3.3 -DgroupId=org.onebusaway.gtfs -DartifactId=onebusaway-gtfs-1.3.3 -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=c:\test\filerepo
Just include the above <repoisitory> entry into any pom you want to have access to the file repo. For example:
<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.example</groupId>
<artifactId>some-artifact</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>some-artifact</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>local-files</id>
<name>local-files</name>
<url>file://c:\test\filerepo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.onebusaway.gtfs</groupId>
<artifactId>org-onebusaway-gtfs-1.3.3</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
I have a maven project, created using the quickstart archetype.
This is my 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>com.dotd</groupId>
<artifactId>marus</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>marus</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>mvnrepository.com</id>
<name>mvnrepository.com</name>
<url>http://www.mvnrepository.com/artifacts</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</project>
This is what I see in Eclipse:
The fact is that in the maven .m2 repository the jar exists and is resolved by eclipse, so I'm able to import and use classes from log4j as you can see in the following screenshot.
Why does eclipse still tell me that the artifact is missing?
UPDATE
As pointed out by Juned Ahsan, it could be a repository issue. So I did browse http://www.mvnrepository.com/artifacts and it shows a 404 error: the repository doesn't exist.
I switched to the official maven repo, http://repo1.maven.org/maven2/, but the error persists.
Log4j is such a popular library and used by so many frameworks. So it must be transitively injected by maven from any other dependent jar and hence it is available for you in your classpath in eclipse.
You can generate maven dependency tree using plugin.
There are many related questions to this but I am getting confused with the answers from them and decided to ask this myself. I have a Java program and want to use it in another one. How can I add the first one as a dependency in the POM.xml file of the second program? The IDE I am using is IntelliJ version 13.
If the first java program was built with maven (it has pom.xml with groupId:artifactId:version), you can add it as a dependency into your new project:
<dependency>
<groupId>old-program-group-id</groupId>
<artifactId>old-program-artifact-id</artifactId>
<version>version-you-want-to-re-use</version>
</dependency>
If no - it would be very complicated way (in size of an article)...
Suppose this is pom.xml of project A
<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.a</groupId>
<artifactId>a</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>a</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>
</project>
After you compile project A through mvn install command, you can add project A into project B by using <dependency> of project A
suppose this is pom.xml of project B
<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.maventest</groupId>
<artifactId>mytest2</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>b</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.a</groupId>
<artifactId>a</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
See more information : How do I add a project as a dependency of another project?
The easiest way to make one a dependency of the other would be to put them together under a parent POM. Building multi-module Maven project is easy. This will get your started. Once you have created the parent pom and referenced it in the two modules, just use a standard maven <dependency/> tag in the one needing the dependency and create a new Intellij project that imports from the parent POM.xml file.
Follow this steps
Create jar file (java archive) with your project.
Execute
mvn install:install-file -Dfile=c:\your file.jar -DgroupId=your.id
-DartifactId=your name a -Dversion=1.0 -Dpackaging=jar
to include at your local repository
Add dependency to pom.xml
<dependency>
<groupId>your.id</groupId>
<artifactId>your name</artifactId>
<version>1.0</version>
I am trying to set up a maven project in eclipse that downloads resources from a maven repository. How do I set this up?
The description of the repository is at this link. I created a new maven project in eclipse then tried Maven...update project and Maven...download sources, but there is still no content added to the project.
Here is the pom.xml I am using:
<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>some.id.i.made.up</groupId>
<artifactId>EverestTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>EverestTest</name>
<properties>
<!-- Generic properties -->
<java.version>1.6</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<repositories>
<repository>
<id>marc-te-main</id>
<url>http://te.marc-hi.ca/mvn</url>
</repository>
</repositories>
</project>
How do I change my pom.xml or other configurations so that the relevant elements are downloaded?
Note that this library is not hosted in the maven central repository.
Now that you're pointed at the repository, you have to tell Maven which libraries in that repository your project needs. To do this, include the tag:
<dependencies>
<dependency>
<groupId>org.marc.everest</groupId>
<artifactId>everest-core</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.marc.everest</groupId>
<artifactId>everest-connectors-spring</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
The site you linked to has the list of artifacts you may need:
everest-core - Everest core modules
everest-connectors-spring - Everest Spring Connector
everest-formatters-xml-its1 - Everest XML ITS1 Formatter
everest-formatters-xml-dt-r1 - Everest XML Datatypes R1 Formatter
everest-rmim-{ca|uv}-{version} - RMIM Assemblies
You'll need a "dependency" stanza for each one that you want. Similarly, change the version tag to be the version you need.