Maven Import AAR Classes.jar - java

I'm using Intellij Idea. I'm trying to import couch-lite into my project using Maven.
My pom 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>*</groupId>
<artifactId>*</artifactId>
<version>0.1.0</version>
<repositories>
<repository>
<id>com.couchbase.lite</id>
<name>couchbase-lite</name>
<url>http://files.couchbase.com/maven2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.couchbase.lite</groupId>
<artifactId>couchbase-lite-android</artifactId>
<version>1.0.0</version>
<type>aar</type>
</dependency>
</dependencies>
The result:
As you can see, I can't access the classes.jar of the aar library. Does anyone have any idea how I can reference the files in that jar?

I'm now using Gradle to build the project. The build times are much longer, but all the libraries are being loaded correctly.

Related

Maven needs extra dependency to build the project whereas Gradle doesn't

I am currently learning JFoenix library. There is a nice demo and instructions how to run it.
JFoenix uses Gradle, but I need to use Maven, so I've decided to recreate the demo project using Maven for further testing.
The problem appeared when I tried to run my newly created project. It turned out that some classes (e.g. de.jensd.fx.glyphs.GlyphIcon) were not found. I found out that de.jensd:fontawesomefx-fontawesome:4.7.0-5 depends on de.jensd:fontawesomefx-commons:8.15 in runtime. So I decided to add it as compile dependency and the demo ran correctly. But build.gradle of the demo specifies only de.jensd:fontawesomefx-fontawesome:4.7.0-5.
Do Maven and Gradle handle dependencies in a different way? Or is it a specific case?
Here 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>jfoenix</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- Bintray is needed for de.jensd:fontawesomefx-fontawesome. -->
<repositories>
<repository>
<id>central</id>
<name>bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.jfoenix</groupId>
<artifactId>jfoenix</artifactId>
<version>8.0.7</version>
</dependency>
<dependency>
<groupId>io.datafx</groupId>
<artifactId>datafx</artifactId>
<version>8.0.1</version>
</dependency>
<dependency>
<groupId>io.datafx</groupId>
<artifactId>flow</artifactId>
<version>8.0.1</version>
</dependency>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-fontawesome</artifactId>
<version>4.7.0-5</version>
</dependency>
<!-- Without this dependency the project can't be compiled. -->
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-commons</artifactId>
<version>8.15</version>
</dependency>
</dependencies>
</project>
P.S. I am not sure whether the title for this question is OK. So suggestions are welcome.
P.P.S. If you try to compile the demo using my pom.xml you'll have to comment out demos.components.AnimationTemplateDemo.java because com.jfoenix.transitions.template package is new and is not available in com.jfoenix:jfoenix:8.0.7.
The pom.xml file at jcenter is this one:
<?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>de.jensd</groupId>
<artifactId>fontawesomefx-fontawesome</artifactId>
<version>4.7.0-5</version>
<dependencies>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-commons</artifactId>
<version>8.15</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
As you can see, fontawesomefx-commons is only required at runtime. I’m not sure why this is, but it explains why it is not pulled at compile time.
I don’t now where gradle pulls its dependency from, you don’t mention it, but my guess is that the configuration there is not runtime, but compile.
Edit : the scope is compile at later versions of fontawesomefx-fontawesome. So it appears that the runtime scope specified in the 4.7.0-5 version is probably a bug…
pom.xml for version 4.7.0-9:
<?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>de.jensd</groupId>
<artifactId>fontawesomefx-fontawesome</artifactId>
<version>4.7.0-9</version>
<dependencies>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-commons</artifactId>
<version>9.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

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.

Adding external jar in a maven project

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>

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.

Error in pom.xml with dependencies: Missing artifact org.eclipse.jetty.tests:test-mock-resources:jar:9.1.0.v20131115

My pom.xml file:
<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.name.MyProject</groupId>
<artifactId>MyProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>example-jetty-embedded</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
</dependencies>
</project>
and I got a problem:
Missing artifact
org.eclipse.jetty.tests:test-mock-resources:jar:9.1.0.v20131115
I see that mvnrepository does not contain this jar file (http://mvnrepository.com/artifact/org.eclipse.jetty.tests/test-mock-resources)
How can I fix this problem?
Test resources are not deployed to maven central by the Jetty project.
And example projects are usually not considered dependencies.

Categories

Resources