Cannot add local jar files in maven project - java

I'm trying to repackage log4j so I can use it with Android. In order to do so, I have to use openbeans library and replace each java.beans with com.googlecode.openbeans.
Obviously this is not sufficient, since before repacking the through maven log4j I've to include openbeans-1.0.jar in the project.
So I've found this method.
I've installed openbeans through the following command:
mvn install:install-file -Dfile=/home/luca/openbeans-1.0.jar -DgroupId=com.googlecode -DartifactId=openbeans -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
I've checked that the correct execution of the command checking if the .jar exists in the following path (and it does):
~/.m2/repository/com/googlecode/openbeans/1.0/openbeans-1.0.jar
Then I edited the pom.xml file adding:
<dependency>
<groupId>com.googlecode</groupId>
<artifactId>openbeans</artifactId>
<version>1.0</version>
</dependency>
But if I try mvn package then this error is returned:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.2:run (rmdir_tests_output) on project log4j: Execution rmdir_tests_output of goal org.apache.maven.plugins:maven-antrun-plugin:1.2:run failed: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.2 or one of its dependencies could not be resolved: Failure to find com.googlecode:openbeans:jar:1.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
Like the install-file didn't worked.
I've tried also with this method, using the following code (obviously I copied the .jar in the project root dir):
<dependency>
<groupId>com.googlecode</groupId>
<artifactId>openbeans</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/openbeans-1.0.jar</systemPath>
</dependency>
And here the error returned is:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.1:compile (default-compile) on project log4j: Compilation failure
[ERROR] /home/luca/apache-log4j-1.2.17/src/main/java/org/apache/log4j/config/PropertyGetter.java:[31,21] error: package com.googlecode does not exist
What is wrong in what I'm doing?

Even if I still don't understand why, I found out that executing:
mvn install:install-file -Dfile=/home/luca/openbeans-1.0.jar -DgroupId=com.googlecode.openbeans -DartifactId=openbeans -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
And using in pom:
<dependency>
<groupId>com.googlecode.openbeans</groupId>
<artifactId>openbeans</artifactId>
<version>1.0</version>
</dependency>
The code is compiled without error. But as I said, still wondering why.

Related

Maven - can't find Jackson artifact in central repository although it exists?

I have a pom.xml with the following dependency:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
<type>bundle</type>
</dependency>
The dependency exists in Maven's central repo:
https://search.maven.org/artifact/com.fasterxml.jackson.core/jackson-databind/2.9.6/bundle
But when (using Eclipse) i right click on my pom.xml file and choose Run As -> Maven install, it downloads a bunch of dependencies related to that artifact, but finishes with the following error:
[ERROR] Failed to execute goal on project jackson-json-demo: Could not resolve dependencies for project com.elad:jackson-json-demo:jar:1.0.0: Could not find artifact com.fasterxml.jackson.core:jackson-databind:bundle:2.9.6 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
I tried a couple of other versions and also deleting the dependency from my local repo and trying again, but it didn't help. What could be the issue?
I have never heard of an artifact type bundle. Here's a list of some of the valid artifact type strings.
Just remove the <type /> tag from your dependency block and it will default to jar.

Error when creating a Spring Boot project from command line with mvn archetype: generate

I want to create a Spring Boot project with this command in command line: mvn archetype:generate -DarchetypeGroupId=com.dgs -DarchetypeArtifactId=spring-boot-quickstart -DarchetypeVersion=1.0.0 -DgroupId=com.dgs -DartifactId=sampleapp -Dversion=1.0.0-SNAPSHOT -DinteractiveMode=false
And I get this error: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.1.1:generate (default-cli) on project standalone-pom: The desired archetype does not exist (com.dgs:spring-boot-quickstart:1.0.0)
What can I do to resolve the problem? Thank you!
I believe you refer to https://mvnrepository.com/artifact/com.github.supermanhub/spring-boot-quick-start-archetype/1.0
In this case the -DarchetypeGroupId, -DarchetypeArtifactId and -DarchetypeVersion are wrong
In maven central repository its defined as:
<dependency>
<groupId>com.github.supermanhub</groupId>
<artifactId>spring-boot-quick-start-archetype</artifactId>
<version>1.0</version>
</dependency>

How to use OpenCV build (opencv and opencv_contrib) in a Maven project

I compiled openCV and OpenCV_contrib library and had the resulting build/bin/opencv-411.jar and libraries .so in build/lib/. Now I am wondering how can I add these to my Maven project?
I was using that Maven repository but the contrib modules are not available.
I tried including the jar as a dependency like here with:
<dependency>
<groupId>org.opencv</groupId>
<artifactId>opencv-411</artifactId>
<version>4.1.0</version>
<scope>system</scope>
<systemPath>${resourcesfolder}/opencv-411.jar</systemPath>
</dependency>
I get no error when I launch clean javafx:compile but when I launch clean javafx:run a lot of OpenCV errors appear :
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/.../src/main/java/model/VideoModel.java:[3,23] package org.opencv.core does not exist
[ERROR] /home/.../src/main/java/model/VideoModel.java:[4,23] package org.opencv.core does not exist
[ERROR] /home/.../src/main/java/model/VideoModel.java:[5,26] package org.opencv.videoio does not exist
[ERROR] /home/.../src/main/java/model/VideoModel.java:[6,26] package org.opencv.videoio does not exist
[ERROR] /home/.../src/main/java/model/VideoModel.java:[25,17] cannot find symbol
symbol: class VideoCapture
location: class model.VideoModel
[ERROR] /home/.../src/main/java/model/VideoModel.java:[26,17] cannot find symbol
symbol: class Mat
I also had a look to that but he deployed his new jar containing the executables and libraries in a remote repository. The interesting part is the jar creation, so I tried to do the same with opencv-411.jar and lib/ folder with:
cp opencv-411.jar opencv-411-new.jar
jar -uvf opencv-411-new.jar lib/
and kept the dependency as above, but raised the same errors...
What should I do?
Thanks to the answers, I came to the solution for including OpenCV jar and libs to Maven:
install the jar in the maven local repository with:
mvn install:install-file -Dfile=/home/.../src/main/resources/opencv.jar -DgroupId=org -DartifactId=opencv -Dversion=4.1.1 -Dpackaging=jar
create the dependency in pom.xml:
<dependency>
<groupId>org</groupId>
<artifactId>opencv</artifactId>
<version>4.1.1</version>
</dependency>
Now that the jar is included, we must add the OpenCV libraries somehow.
Just load the library in your app with:
System.load("/path/to/lib/libopencv_java411.so");
For the UI tests, as the maven-surefire-plugin uses a special JVM, you have to specify the lib folder to the java.library.path:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Djava.library.path=${project.build.outputDirectory}/lib</argLine>
</configuration>
</plugin>
Please feel free to edit if you have a better solution or corrections to add.
Maven expects the artifacts (.jar files, etc.) in $USER_HOME/.m2 since you compiled opencv yourself you also need to install the file (as 3rd party module) in the local maven repository:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Where the variables need to match those you use in you pom.xml and packaging must be set to jar.
See also: https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
mvn install:install-file -Dfile=C:\Users\your jar path -DgroupId=org.opencv -DartifactId=opencv-411 -Dversion=4.1.0 -Dpackaging=jar
you can use this one may be solve your issue

Could not resolve dependency after installing jar

I installed my jars with:
install:install-file -Dfile="C:/Program Files/keydox/jkdx/codecs.jar" -DgroupId=keydoxWeb -DartifactId=keydoxWebCodec -Dversion=1.0
That worked fine and the jar also is in the .m2 repository.
But as I add them to the POM by:
<dependency>
<groupId>com.keydoxWeb</groupId>
<artifactId>keydoxWebCodec</artifactId>
<version>1.0</version>
</dependency>
I get the error message:
Failed to execute goal on project test: Could not resolve dependencies for
project com.TestOne:test:jar:0.0.1-SNAPSHOT: Could not find artifact
com.keydoxWeb:keydoxWebCodec:jar:1.0 in spring-snapshot
(http://repo.spring.io/snapshot)
When you installed your codecs.jar you set the -DgroupDId to be keydoxWeb, in your pom.xml you're trying to get the artifact with groupid com.keydoxWeb which does not exist since it is installed without com..

How to use GitHub Repo using JitPack.io in Maven

I wants to use https://github.com/liquibase/liquibase version 3.5.0-SNAPSHOT
I have added the following in pom.xml
<dependency>
<groupId>liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.5.0-SNAPSHOT</version>
</dependency>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
but got following error when compile:
[ERROR] Failed to execute goal on project XYZ: Could not resolve dependencies for project com.XYZ:jar:0.0.1-SNAPSHOT: Failure to find org.liquibase:liquibase-core:jar:3.5.0-SNAPSHOT in https://github.com/liquibase/liquibase was cached in the local repository, resolution will not be reattempted until the update interval of liquibase-repository has elapsed or updates are forced -> [Help 1]
There seems to be an issue with JitPack and downloading this repository. According to the maven modular example that JitPack provides, the dependency should be defined as follows:
<dependency>
<groupId>com.github.User.Repo</groupId>
<artifactId>Module</artifactId>
<version>Commit/Tag</version>
</dependency>
The following should then work:
<dependency>
<groupId>com.github.liquibase.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>f7f3b8f60b</version>
</dependency>
But it also fails resolving the dependency:
[ERROR] Failed to execute goal on project my-app: Could not resolve dependencies for project com.mycompany.app:my-app:jar:1.0-SNAPSHOT: Failure to find com.github.liquibase.liquibase:liquibase-core:jar:0885bc4 in https://jitpack.io was cached in the local repository, resolution will not be reattempted until the update interval of jitpack.io has elapsed or updates are forced -> [Help 1]
You can see that this is definitely an issue by just trying to use the liquibase parent repository (not just the liquibase-core module) as follows:
<dependency>
<groupId>com.github.liquibase</groupId>
<artifactId>liquibase</artifactId>
<version>f7f3b8f60b</version>
</dependency>
Which also errors out. According to JitPack's log for this commit, it looks like there is a compilation error with the source:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project liquibase-core: Compilation failure
[ERROR] /home/jitpack/build/liquibase-core/src/main/java/liquibase/parser/core/formattedsql/FormattedSqlChangeLogParser.
java:[213,209] ')' expected
It seems like the best route would be to file an issue with the JitPack folks and see if they can shed some light on it.

Categories

Resources