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

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.

Related

Publish maven project to a local directory

I want to publish my maven project to a local directory but not in $HOME/.m2/repository. I have created the following directory structure:
$HOME/myrepo
|- third_party
+- private
The directory $HOME/myrepo/third_party holds, as the name suggests, external artifacts from 3rd parties. I want to publish my own projects into $HOME/myrepo/private. Therefore, I use the following adjusted $HOME/.m2/settings.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>maven-private</id>
<username></username>
<password></password>
</server>
</servers>
<mirrors>
<mirror>
<id>maven-local</id>
<url>file:///home/user/myrepo/third_party</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>
The file pom.xml for my test project looks like this:
<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>app</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>maven-private</id>
<name>Internal Release Repository</name>
<url>file:///home/user/myrepo/private</url>
</repository>
</distributionManagement>
</project>
When I run
mvn install
The project compiles successfully and all required files are fetched from $HOME/myrepo/third_party, however, after compilation the project is always installed to $HOME/.m2/repository.
How do I have to configure maven in order to publish my projects into the $HOME/myrepo/private directory?
If you want to put the artifacts in a repository other than local, you are not thinking of installing but deploying them. Installing with maven by definition puts the artifacts in local repository - so unless you intend to overwrite the location of .m2/repository and all its contents, just run
mvn deploy
You can change the location of your local Maven repository, i.e. where artifacts are installed, by editing the Maven settings file ~/.m2/settings.xml. Specifically, you are interested in changing the <localRepository> to directory of your choice. One thing to look out for is that path you specify must be an absolute path according to the Configuring your Local Repository section of the user guide. Please also note that this will affect all artifacts (both your private and 3rd party ones) as Maven only supports a single local repository.
Example:
<settings>
<!-- settings -->
<localRepository>/path/to/local/repo/</localRepository>
<!-- more settings -->
</settings>

Maven - How to use an artifact from local folder? [duplicate]

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.

Eclipse shows error on log4j dependency, but log4j is correctly included

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.

SWT dependency artifact missing?

I want to use swt in my project and used this page as a starting point:
https://code.google.com/p/swt-repo/
I added the repository and dependency but my pom.xml has an error saying:
Missing artifact org.eclipse.swt:org.eclipse.swt.win32.win32.x86:jar:4.4
What could be the problem?
My whole 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>artifact</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- SWT -->
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86</artifactId>
<version>4.4</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>swt-repo</id>
<url>https://swt-repo.googlecode.com/svn/repo/</url>
</repository>
</repositories>
</project>
The problem is that there is no official maven repository that hosts the SWT library files. There were a few sites that worked in the past, but almost all are now abandoned, closed or moved. On https://github.com/maven-eclipse/maven-eclipse.github.io they explain the problem, but the solution described there (to use http://maven-eclipse.github.io/maven) doesn't work because that link will redirect you to the git repository.
The link you posted seems to be the only maven repo that is currently left. I had problems with Maven accessing it properly just like you. I'm not entirely sure what the problem is. I suspect it has something to do with missing or invalid indexes, but I'm not sure. In any case the best solution is to download the required jars and add them to your local repository manually. This is probably a good idea anyway, because Google Code will shutdown in January 2016
BTW, there is an open bug for SWT to be distributed via Maven, but it's been posted in 2007! and there still is no official solution.

connecting eclipse maven to a repository not hosted at maven central

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.

Categories

Resources