How to refer to a project from innersource? - java

I have a java-maven project working on my STS. The thing is that I want to create my own spring-boot starter and include it as a maven dependency in the pom.xml file of my project. The thing is that this starter will be located in an innersource repository and I don't know what information I need to put in the pom.xml file to refer to that one in innersource and not to other one. Maybe is it possible to specify the URL of the repository or what?
Thanks you so much for your help!

The thing is that I want to create my own spring-boot starter and
include it as a maven dependency in the pom.xml file of my project.
By reading this I think that what you are looking for is how to create a dependency, that you can easily include it at any of your projects.
By this you can have a local maven repository or push it to a remote repository (like most of all dependencies), what is important is wherever you push it is available to be downloaded.
If you go by the local version you can use a maven/gradle plugin to package your jar and publish it. You will need to specify a couple of properties like groupId, artifactId and version
https://docs.gradle.org/current/userguide/publishing_maven.html
with the groupId, artifactId and version you will be able to include it in your project like
<dependency>
<groupId>org.myorg</groupId>
<artifactId>my-artifact</artifactId>
<version>0.0.1</version>
</dependency>
if this is from a maven local dependency don't forget to include maven local as part of your repositories.
https://www.baeldung.com/maven-local-repository
Check these articles, it will help you.
https://maven.apache.org/guides/introduction/introduction-to-repositories.html
Create local maven repository

Related

Install third party jar in local maven before maven resolves its dependency?

I am working on a multi-module maven project and have third party jar which isn't available in central or public repository, I also even don't want to place on public repo. I am providing following plugin directive in my parent pom to install jar in my local maven repository before its dependency is resolved in child project.
Now I provide dependency in child project as;
But I build the project, it successfully adds dependency in local maven repository (places third party jar in .m2 folder) but the at the same time it gives following error. Looks like, it searches this jar file in child projects libs folder as well, while I have already placed it on root (in myproject.parent/libs).
Failed to execute goal org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file (install-
external-non-maven1-jar) on project myProject.core: The specified file 'C:\Users\myuser\git\MyProjectRepository\myproject.parent\myproject.core\libs\be-ixf-java-sdk-jar-with-dependencies.jar' not exists.
I already know scope and systemPath option but I don't want to use it for some reason.
Kindly help in identifying what I am missing ?
The best approach that you could have if your project have a centralized maven repo like nexus setup is to have your third party library also added to the repo. Now , you are having the bin file added to your project and it's not preferable.
If you already have the required jar under your project code in like : libs\*, then why can't you refer the dependency directly in your pom.xml instead of having to install it in your local maven repo and then use it .
<dependency>
<groupId>anything</groupId>
<artifactId>anything</artifactId>
<version>anything</version>
<scope>system</scope>
<systemPath>${basedir}/lib/jar_name.jar</systemPath>
</dependency>
providing the location of the dependency in your project directory should resolve it during build itself.Look at Maven System dependencies.
Since you do not want to change your current setup . Please bear in mind the following about maven pom structure :
Project Aggregation is similar to Project Inheritance. But instead of
specifying the parent POM from the module, it specifies the modules
from the parent POM. By doing so, the parent project now knows its
modules, and if a Maven command is invoked against the parent project,
that Maven command will then be executed to the parent's modules as
well
So the maven-install-plugin execution that you added in main pom.xml might be getting triggered for all your modules because of this reason. You might want to move that to the module that you actually need this lib to be included in.Read maven doc.
Related : force Maven to copy dependencies into target/lib

Install library jar in pom maven

I have Java Maven Project with a folder lib with all jars that must be included in my project.
I don't know how I have to modify the POM to add all libraries. I want that Maven uses this libraries and I can use all in the project.
Lets be frank here: you are basically asking how to use Maven but then not use it at the same time. Maven is built around the fact that dependencies are managed from dependable repositories and then you come along and want to bypass that entire system by having local jars anyway as you would have in a project not managed through Maven - like one that is built with ANT.
The true clean solution to "not getting jars from a Maven repository" is to still get them from a repository - your own. Setup a local repository and put your third party dependencies there, then configure your Maven build to know about that local repository. If they are actually dependencies that exist in Maven central then you can setup your local repository to proxy them rather than manually installing them yourself.
http://maven.apache.org/repository-management.html
If you are using the release management features of Maven (or something like Hudson) then you should actually already have such a thing to stick your generated release artifacts into.
You have to know which libraries are you using. Imagine that you use in your project the joda-time library.
So you have to search your libraries (in this case joda-time) in maven repositories and add to your pom.xml like the following:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
</dependency>
Here the Maven repository --> Maven Repo

add external jar to our dependency

There is a jar file lets say "abc.jar" which maven dependency does not exist(ie created a jar by using java command of own classes). I want to add this jar as maven dependency so that at build time it will automatically copy that jar in lib folder as like other maven dependency. how i will do. please help .
Add it as a dependency with a system scope. See the docs here.
However, rather than adding it as a system dependency it might be better to mavenize the jar itself, then you can build and install it into your dependency management system.
Also, see this question: Can I add jars to maven 2 build classpath without installing them?
You can use the systemPath attribute in the dependency tag in the POM file of your project.
In your pom.xml, use the following snippet corresponding to abc.jar:
<dependencies>
<!-- Other dependencies -->
<dependency>
<groupId>abc</groupId>
<artifactId>x</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>{path_to_abc.jar}</systemPath>
</dependency>
</dependencies>
The scope parameter corresponding to this artifact must be set to system, for the artifact to be picked up from the specified systemPath.
Hope this helps!
A normal maven dependency is always resolved by looking into a repository. So you must put your JAR file into a repository.
You could install your JAR into your local repository. Have a look at the install plugin. The install-file goal is your friend.
If other developers also need this JAR (because they are working with the same project), they either need to install it locally too, or - better - you deploy the JAR to a remote repository. Have a look at the deploy plugin. Here the deploy-file goal is your friend. For deploying artifacts, you need a repository manager like Nexus or Artifactory.
However, a dependency could also have the system scope (look at the other answers).

Maven dependency for aqapi13.jar

I am upgrading a project from Ant to Gradle. The project uses a aqapi13.jar(this is oracle aq jar. This is needed as the project reads from an oracle-queue and writes to an activemq queue.)
The ant project contains the jar aqapi13.jar in the libs folder. But iam trying to get this dependency from a repository instead of having it in the libs folder.
However, iam not able to find a repository which contains this jar. All the repositories that I have seen contain aqapi13-9i.jar, but not aqapi13.jar.
Anyone knows the difference between aqapi13.jar and aqapi13-9i.jar and how to get the needed aqapi13.jar from a repository.
Advance Thanks
Some dependencies are never found in public repositories because of the license they have.
One way to use this dependencies is to create your own repository (e.g. artifactory, nexus, archiva). Then you are free to put in every artifact you want (as long as you do not publish the repository). This repository can also serve as a mirror for maven.
Another way could be to mark this dependency as system scope.

Add a dependency in Maven

How do I take a jar file that I have and add it to the dependency system in maven 2? I will be the maintainer of this dependency and my code needs this jar in the class path so that it will compile.
You'll have to do this in two steps:
1. Give your JAR a groupId, artifactId and version and add it to your repository.
If you don't have an internal repository, and you're just trying to add your JAR to your local repository, you can install it as follows, using any arbitrary groupId/artifactIds:
mvn install:install-file -DgroupId=com.stackoverflow... -DartifactId=yourartifactid... -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/jarfile
You can also deploy it to your internal repository if you have one, and want to make this available to other developers in your organization. I just use my repository's web based interface to add artifacts, but you should be able to accomplish the same thing using mvn deploy:deploy-file ....
2. Update dependent projects to reference this JAR.
Then update the dependency in the pom.xml of the projects that use the JAR by adding the following to the element:
<dependencies>
...
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
You can also specify a dependency not in a maven repository. Could be usefull when no central maven repository for your team exist or if you have a CI server
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>commons-utils</artifactId>
<version>1.3</version>
<scope>system</scope>
<systemPath>${basedir}/lib/commons-utils.jar</systemPath>
</dependency>
Actually, on investigating this, I think all these answers are incorrect. Your question is misleading because of our level of understanding of maven. And I say our because I'm just getting introduced to maven.
In Eclipse, when you want to add a jar file to your project, normally you download the jar manually and then drop it into the lib directory. With maven, you don't do it this way. Here's what you do:
Go to mvnrepository
Search for the library you want to add
Copy the dependency statement into your pom.xml
rebuild via mvn
Now, maven will connect and download the jar along with the list of dependencies, and automatically resolve any additional dependencies that jar may have had. So if the jar also needed commons-logging, that will be downloaded as well.
I'd do this:
add the dependency as you like in your pom:
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
run mvn install it will try to download the jar and fail. On the process, it
will give you the complete command of installing the jar with the error message. Copy that command and run it! easy huh?!
I'll assume that you're asking how to push a dependency out to a "well-known repository," and not simply asking how to update your POM.
If yes, then this is what you want to read.
And for anyone looking to set up an internal repository server, look here (half of the problem with using Maven 2 is finding the docs)

Categories