Jar not downloading from maven - java

I have a scenario, where in my maven repository, the required JAR is available, but it is not inside the version folder, instead, it is directly under the group.
For Example I need test-1.0.0.jar
In my Maven Repo, the jar is placed in the path like below,
com.java.test
----test-1.0.0.jar
But it is supposed to be like the below,
com.java.test
---1.0.0
------test-1.0.0.jar
Because of this, the jar is not downloading when I do maven install. Are there any workarounds to get the jar downloaded without changing the maven repository structure?

I think there is a problem with pom.xml of test.jar or jar uploaded to the remote repo incorrectly.
In that case, if you have control over test.jar codebase or remote repo, you can figure out what is wrong and fix it. If you don't have control over them, you can treat like it is 3rd party jar. Using below command you can populate the jar into your local maven repository.
mvn install:install-file
Basically, this command reads this dependency and installs into your local maven repository within the constraints you provided as a parameter.
Below example have been taken from Apache Maven Documentation.
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
But keep in mind, it is just a workaround for your local development. In the long run, the actual problem needs to be resolved. As mentioned earlier, either pom.xml of test.jar should be fixed or structure of remote repository should be corrected by re-uploading the jar.

You would need to re-upload your jar to the right path in Nexus, using mvn deploy:deploy-file :
In Windows:
cmd /v /c "set g=com.java&& set a=test&& set v=1.0.0&& mvn deploy:deploy-file -Dfile=!a!-!v!.jar -Dpackaging=jar -DgroupId=!g! -DartifactId=!a! -Dversion=!v! -DrepositoryId=your-nexus-id -Durl=https://nexus.your.comany.com repository/public"
You can execute that in the folder where the jar is, even without any pom.xml.

Related

mvn cli with chosen plugins location

Is there a way to make maven use another repository than the configured one on CLI?
Eg.: maven is using the org.apache.maven.plugins:maven-clean-plugin:3.2.0 jar maven-clean-plugin-3.2.0.jar in the configured maven repo. I’d like to make maven run mvn clean with this jar from another location on the disk, like –
> mvn clean -<some-option> <maven-clean-plugin-3.2.0.jar-location-of-choice>
I looked up the command line options, nothing directly saying it so far
TIA

Cannot integrate an external jar in a spring boot maven project

I have a local jar which I need to test. This jar has not yet been pushed to maven repository.
I created a sample project and added this jar as an external jar on the classpath by clicking on configure build path.
When I import the class from the jar eclipse is able to import it but when i run Maven build it gives an error saying
com.x.y package does not exist
ClassName.class cannot find symbol
What is going wrong over here ?
Just push it to your local maven repository, this is the command line:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Later add this dependency in your pom and it will work.

Installing Maven Artifacts Into a Local Repository From Outside Of Any Project

Is there any way to install an arbitrary Maven artifact into your local repository without first creating and switching to a project and specifying that package as one of its dependencies?
Yes, if you have the jar file of the artifact that you want to install to your local repository, you can the run the below command from your command prompt or terminal. Replace the value inside the angle brackets to your desired ones. And then you can use this as a dependency in your Maven projects.
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
HTH

Installing 3rd party JARs to Jenkins .m2 repository

I am Trying to add a third party jar to jenkis .m2 repository
This is the command i found to add it to the repository from command line
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
i have a linux machine where jenkins run by its own user. it has a .m2 repository in the home directory. when i tried the above command it gives error saying that, The program 'mvn' can be found in the following packages:* maven * maven2 . so jenkins can build with out a maven installed?, if so how it is done?. how can i add the jar to .m2 repository without installing maven ?
i read that maven need a setting.xml file in its .m2 folder, but i cant find any for jenkins.
You can also use the maven binary from the jenkin's maven-plugin. Use find / -type f -name mvn to find out, where the jenkins maven plugin is installed to and call mvn from there.
You can then change mvn install:install-file ... to <pathFromFind>/mvn install:install-file ... or add this path to your PATH variable.

Maven Spring project: Adding a custom library using Eclipse IDE [duplicate]

I want to add jpoller.jar as a maven dependency, so I edited my pom.xml file to include it:
<dependency>
<groupId>org.sadun</groupId>
<artifactId>jpoller</artifactId>
<version>1.5.2</version>
</dependency>
Now, as expected, when I compile from the command line I get an error because jpoller isn't in any of the repositories I have listed in my pom, nor could I find one for it. Although I could create a repository for it, I'd rather not at this point. Thus, I get the following error:
[INFO] Failed to resolve artifact.
Missing:
---------- 1) org.sadun:jpoller:jar:1.5.2
Try downloading the file manually
from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.sadun -DartifactId=jpoller -Dversion=1.5.2 -Dpackaging=jar -Dfile=/path/to/file
How can I do this from the M2Eclipse plugin on machines where the maven CLI isn't available?
How can I do this from the M2Eclipse plugin on machines where the maven CLI isn't available?
Well, simply do it from Eclipse. First, get that jpoller jar and save it somewhere on your file system. Then, in Eclipse, from the top bar, Run > Run Configurations... then right-click on Maven Build and configure the New_configuration freshly created:
Select an arbitrary Base directory
Fill the Goals with install:install-file
Add parameters for each required parameters, without the -D prefix (e.g. file as Parameter name and /path/to/file as Value and so on for groupId, artifactId,packaging and version).
And run this configuration. Or... just install Maven.
The install command automates the creation of a folder structure in ~/.m2 and pom.xml file for the dependency artifact. This can be done manually. OR You can simply copy the ~/.m2/{group}/{artifact} folder from a machine that does have mvn installed.
Edit: This tool will help you find public repositories for a given dependency.
Edit2: See http://maven.apache.org/guides/mini/guide-coping-with-sun-jars.html for an explination of the process of installing dependencies manually. Note that most sun jars are now available in the java.net repository http://download.java.net/maven/2/

Categories

Resources