Missing Maven Dependency on Locally installed atrifact - java

I have a .jar file, which I want to use in my current project which I am building with Maven. After some research I figured out that I need to install it locally. This I did using:
mvn install:install-file -Dfile="D:\Eclipse Workspace\TextOnlyJam\adapterLib\lwjgladapter.jar" -DgroupId=lwjgladapter -DartifactId=lwjgladapter -Dversion=1.0 -Dpackaging=jar`
I then added the dependency into my pom like so:
<dependency>
<groupId>lwjgladapter</groupId>
<artifactId>lwjgladapter</artifactId>
<version>1.0</version>
</dependency>
My project in exclipse now manages to resolve all dependencies and does not give me any compile errors. However after cleaning and updating my maven project several times, I still get the following error when running an install:
Failure to find lwjgladapter:lwjgladapter:jar:1.0 in https://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
I assume that maven is looking for the artifact in the wrong location, however I can not figure out what I need to change here.
(I am also not sure if I need to add the dependency into , since it does not seem to change anything when I do.)

Okay, I just figured out that it was just a stupid mistake on my end. I looked into the repository folder and found, that my jar file was named `.jar``
So yeah, a simple copy and past error. Thanks for the help so far!

Related

Could not find artifact sun-jaxb:jaxb-api:jar:2.2 in central

I am trying to upgrade a project from JDK 7 to JDK 8.
In order to fix some issues during compile time, I needed to upgrade Maven to 3.6.3 as well.
The other issue is fixed with this upgrade however, I am getting the below error during mvn install
Failed to execute goal on project jbossha-PATCH: Could not resolve dependencies for project com.company.wae:jbossha-PATCH:jar:5.1.0.GA: Could not find artifact sun-jaxb:jaxb-api:jar:2.2 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
When I check my m2 repo, the jax-api.jar is present under sun-jaxb folder. If I delete sun-jaxb, it is created again with jax-api.jar.
This dependency is present in a lot pom.xml within the project.
Why the error is saying that it can not find the artifact and is there a way to solve this issue?
Why the error is saying that it can not find the artifact and is there a way to solve this issue?
Because the dependency in the POM files is incorrect. I checked, and there are no official dependencies for "sun-jaxb" in Maven Central.
The correct Maven dependency for the JAXB apis in Java 8 is
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.8</version>
<scope>provided</scope>
</dependency>
as described in "https://stackoverflow.com/questions/63608553". I checked and the artifact is there, as are older and newer versions.
So a good solution would be to update all of the POM dependencies.
Now I presume that you are trying to build was building correctly before you started porting it. (Did you check?) If it was, then it must having been getting the "sun-jaxb:jaxb-api:jar:2.2" dependency from ... somewhere:
It might have been in Maven Central "unofficially" and removed as a result of a clean-up
You (or the previous maintainer) might have installed it directly into the local repo on your build box.
You might have been getting it from another repo; e.g. a corporate Maven repo where someone has previously uploaded it.
It would be a good idea to figure out how it worked before.

What is causing ArtifactNotFoundException in anypoint maven?

I am trying to create new connector using mulesoft sdk. The connector has been successfully created and and loaded into the internal maven repository. When I try to reference the connector in the anypoint project, I get
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Failure to find org.demo.cloud:mule-connector:pom:1.0.0 in https://maven.anypoint.mulesoft.com/api/v2/maven was cached in the local repository, resolution will not be reattempted until the update interval of anypoint-exchange-v2 has elapsed or updates are forced
When I run the maven cmd in the command line, there are no errors. But as soon as I add dependency in the anypoint project pom file, I get the error. What could be wrong?
It looks like the Mule application project is trying to reference the connector reference with an incorrect Maven classifier. It should be a mule-plugin but the error message implies it is pom.
Example:
<dependency>
<groupId>org.demo.cloud</groupId>
<artifactId>mule-connector</artifactId>
<version>1.0.0</version>
<classifier>mule-plugin</classifier>
</dependency>
I faced similar issue before. I would like to add some extras to the existing answer.
The misuse of classifiers can happen when you try to pull artifacts from maven central without knowing what type of packaging type the artifact is made of during its maven release phase.
mvn release:clean
mvn release:prepare
mvn release:perform
Observe that when you add something as mule-plugin as a classifier in your dependency. It will add the connector plugin in your mule package explorer on the left hand side. This may not still resolve the pom unavailability problem you have pasted in the question.
I also believe that org.demo.cloud is an groupId not an artifact ID. Nevertheless, your application might not be a true mule-plugin based on its pom declaration.
Try packaging your main APP-1 (in maven central) as a mule-plugin in the APP-1 pom file. If not, simply put the packaging as jar type and republish your artifacts. Later, don't mention the classifier section in your APP-2. Simply call the direct dependency.
Check my other answer in here.:Unable to reference to DWL script files in Mule 4 dataweave from Project Libraries(jar)

Cant build project because of cached Dependencies (java)

I am trying to package my project to a jar, whenever I try this it fails to compile because of old cached dependencies I dont use anymore.
Could not resolve dependencies for project at.htl:testmonitoring-client:jar:1.18.47: Failed to collect dependencies [old dependencies] 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]
If you're not using the dependencies, then you should remove them from the pom. If the dependency is not in the pom, then (most of the time) Maven won't try to resolve them and the build won't fail.
If you've removed them from the pom but maven is still trying to resolve them, then it may mean that something is using them transitively. You can check on that with mvn dependency:tree
If for whatever reason the build needs to resolve them, then the simplest thing is to remove the "cached failures" from your local repo. The easiest thing to do is remove the entire ~/.m2/repository directory (and all subdirectories and content thereof), which is probably safe as maven will reconstruct it from the remote. The only problem would be if you have/need artifacts in the local repo that don't exist on any remote. If that's not the case, you won't lose anything by doing it, though it will make the next build take longer as it must download everything again.
If you can't remove the entire local repo, then you could still track down the specific artifacts causing the problem. For example, if you have a problem with an artifact groupId=com.some.comapny artifactId=someArtifact, version=1.0.0 then you could remove ~/.m2/repository/com/some/company/someArtifact/1.0.0 (and all content thereof).
Note that this assumes Maven will be able to resolve the dependencies from the configured remote(s). If they aren't available in the remotes you've configured, then you may have to resolve that (either by adding them to your local repo manager, by adding public repos that do have the artifacts, etc.).
go to home directory and delete .m2 (hidden directory) folder and update project and run it.

Maven not able to download dependency

I have started working on a new project using Maven, and I'm unable to have it work properly on eclipse. I have multiples of this error :
ArtifactTransferException: Failure to transfer com.caucho:hessian:jar:3.1.5 from <repository> was cached in the local repository, resolution will not be reattempted until the update interval of Archiva SIVPN Internal has elapsed or updates are forced. Original error: Could not transfer artifact com.caucho:hessian:jar:3.1.5 from/to Archiva SIVPN Internal (<repository>): No response received after 60000 pom.xml /<file> line 2 Maven Dependency Problem
Description Resource Path Location Type
Missing artifact com.caucho:hessian:jar:3.1.5 pom.xml / line 2 Maven Dependency Problem
After doing some research, I found that it was probably either the pom.xml that's wrong, or that I have proxy problems.
I checked that the resource was available on our repository, and that the pom snippet is the same as declared in my code :
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>3.1.5</version>
</dependency>
My proxy works just fine for the trunk of the project, and there is no other proxy I'm aware of.
I thought it was maybe a one-time connection problem, but making a new maven build with -U didn't resolve the problem.
I also found https://stackoverflow.com/questions/6111408/maven2-missing-artifact-but-jars-are-in-place
with several I-don't-know-what-else-to-do solutions, but it didn't work for me...
Since the lead developer is on vacation and I have little experience on mvn, could someone tell me other potential problems that could be responsible for this ?
Thanks in advance for answers :)
Open a command prompt, go to your project directory and run: mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
The eclipse:eclipse portion will regenerate your project files etc, the last 2 properties are more for convenience but I like downloading the sources and javadoc.
After a failed attempt, maven will leave a small file in your local .m2 repository that will prevent any attempt to re-download the file unless the update interval has elapsed or you force the updates using the maven -U switch described in other answers.
Just delete the folder for that artifact in your local m2 repository and update you project; a new download attempt will trigger.
rm -rf ~/.m2/repository/com/caucho/hessian/3.1.5

Maven: How to include jars, which are not available in reps into a J2EE project?

in my J2EE project I've a couple of dependencies, which are not available in any Maven repository, because they're proprietary libraries. These libraries need to be available at runtime, so that have to be copied to target/.../WEB-INF/lib ...
Right now, I'm listing them as system dependency in my POM, but with this method the problem is, that aren't being copied to the target build during compilation. Also this method is not very elegant.
So which is the best way to integrate them in Maven?
Note: I don't want to create my own Maven repository.
For people wanting a quick solution to this problem:
<dependency>
<groupId>LIB_NAME</groupId>
<artifactId>LIB_NAME</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/WebContent/WEB-INF/lib/YOUR_LIB.jar</systemPath>
</dependency>
just give your library a unique groupID and artifact name and point to where it is in the file system. You are good to go.
Of course this is a dirty quick fix that will ONLY work on your machine and if you don't change the path to the libs. But some times, that's all you want, to run and do a few tests.
EDIT: just re-red the question and realised the user was already using my solution as a temporary fix. I'll leave my answer as a quick help for others that come to this question. If anyone disagrees with this please leave me a comment. :)
As you've said you don't want to set up your own repository, perhaps this will help.
You can use the install-file goal of the maven-install-plugin to install a file to the local repository. If you create a script with a Maven invocation for each file and keep it alongside the jars, you (and anyone else with access) can easily install the jars (and associated pom files) to their local repository.
For example:
mvn install:install-file -Dfile=/usr/jars/foo.jar -DpomFile=/usr/jars/foo.pom
mvn install:install-file -Dfile=/usr/jars/bar.jar -DpomFile=/usr/jars/bar.pom
or just
mvn install:install-file -Dfile=ojdbc14.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0 -Dpackaging=jar
You can then reference the dependencies as normal in your project.
However your best bet is still to set up an internal remote repository and I'd recommend using Nexus myself. It can run on your development box if needed, and the overhead is minimal.
Create a repository folder under your project. Let's take
${project.basedir}/src/main/resources/repo
Then, install your custom jar to this repo:
mvn install:install-file -Dfile=[FILE_PATH] \
-DgroupId=[GROUP] -DartifactId=[ARTIFACT] -Dversion=[VERS] \
-Dpackaging=jar -DlocalRepositoryPath=[REPO_DIR]
Lastly, add the following repo and dependency definitions to the projects pom.xml:
<repositories>
<repository>
<id>project-repo</id>
<url>file://${project.basedir}/src/main/resources/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>[GROUP]</groupId>
<artifactId>[ARTIFACT]</artifactId>
<version>[VERS]</version>
</dependency>
</dependencies>
You need to set up a local repository that will host such libraries. There are a number of projects that do exactly that. For example Artifactory.
None of the solutions work if you are using Jenkins build!! When pom is run inside Jenkins build server.. these solutions will fail, as Jenkins run pom will try to download these files from enterprise repository.
Copy jars under src/main/resources/lib (create lib folder). These will be part of your project and go all the way to deployment server. In deployment server, make sure your startup scripts contain src/main/resources/lib/* in classpath. Viola.
you can install them in a private, local repository (e.g. .m2/repository under your home directory): more details here
If I am understanding well, if what you want to do is to export dependencies during the compilation phase so there will be no need to retrieve manually each needed libraries, you can use the mojo copy-dependencies.
Hope it can be useful in your case (examples)
#Ric Jafe's solution is what worked for me.
This is exactly what I was looking for. A way to push it through for research test code. Nothing fancy. Yeah I know that that's what they all say :) The various maven plugin solutions seem to be overkill for my purposes. I have some jars that were given to me as 3rd party libs with a pom file. I want it to compile/run quickly. This solution which I trivially adapted to python worked wonders for me. Cut and pasted into my pom. Python/Perl code for this task is in this Q&A: Can I add jars to maven 2 build classpath without installing them?
def AddJars(jarList):
s1 = ''
for elem in jarList:
s1+= """
<dependency>
<groupId>local.dummy</groupId>
<artifactId>%s</artifactId>
<version>0.0.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/manual_jars/%s</systemPath>
</dependency>\n"""%(elem, elem)
return s1
Continue to use them as a system dependency and copy them over to target/.../WEB-INF/lib ... using the Maven dependency plugin:
http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html
Install alone didn't work for me.
mvn deploy:deploy-file -Durl=file:///home/me/project/lib/ \
-Dfile=target/jzmq-2.1.3-SNAPSHOT.jar -DgroupId=org.zeromq \
-DartifactId=zeromq -Dpackaging=jar -Dversion=2.1.3

Categories

Resources