how include my local jar to maven? - java

the question is:
i start a local lib to collect some common utils in it.
then i use eclipse m2e to run as Maven Install, and it truely generate the jar into my local cached repos dir.
and now, i want to use that lib as a dependency in my project, i just type the dependency xml as the other (like spring etc.).
but it just can load that lib in the maven dependencies libs.
I search the web and find that systemPath could work, but i don' t like this way. how can i use my local jar in a same way?

Install it into your repository. Either local (mvn install) or run repository software like Artifactory, Archiva or Nexus. http://maven.apache.org/repository-management.html

You can do a (non-Maven) build and:
install the JAR in your local "repo" directory,
manually upload it your group / corporate repository, or
install it in a so-called "internal repository" that you manage by hand: see http://maven.apache.org/guides/introduction/introduction-to-repositories.html.
(I have even resorted to using an "internal repository" that was part of the project's version control check-out; i.e. putting the JAR into version control.)
But I think that the best approach would be to Mavenize the build for the utility JAR, and handle it just like your main Maven projects.

Use goal install-file .
Like , mvn install-file.

Related

Pre-download all dependencies

I need to release our Maven build Java project to an remote QA team. For this I would like to download all the dependencies, and send them so they do not need to download them.
Currently all dependencies are defined in the pom.xml file, and we use either mvn install or mvn package to build the project. Some of the project members use uber jars, others use jars + dependencies to do execution.
What would be the easiest way to pre-package the dependent jar files so that there is no download from the internet, and does not change our current build process too much?
A possible solution would be to purge your local repository, tell Maven to download every dependencies and plugin dependencies of your project and make a ZIP of that.
To purge your local repository, you can simply delete the folder {user.home}/.m2/repository. Then, you can use the dependency:go-offline goal:
Goal that resolves all project dependencies, including plugins and reports and their dependencies.
mvn dependency:go-offline
This will download everything that your project depends on and will make sure that on a later build, nothing will be downloaded.
Then, you can simply make a ZIP of {user.home}/.m2/repository and send that to your Q/A team. They will need to unzip it inside their own {user.home}/.m2/repository to be able to build the project.
Offline Package deploy
Your requirement can be accomplished by creating a stand alone jar file with full dependencies. You can port it anywhere please refer https://stackoverflow.com/a/35359756/5678086
Build a full dependency JAR file as said in the answer
Copy the JAR to the destination machine you want
Run the below command from there
mvn install:install-file -Dfile=<path-to-file>
This will install the dependecies in the maven repository of the destination machine. This is fully offline
Theoretically if you know which maven commands you'll use (package, install, etc.) you could clear out your ~/.m2/repository folder, run those commands once on somebody's dev box, then distribute the repository folder. You can run maven -o install etc. to have it not give annoying warnings. This might be a slightly smaller distro than the go-offline answer.

maven - create archive of generated jar files

I am currently building out some projects using an aggregate pom. It calls out some parent poms that build out the artifacts.
The artifacts build out ok.
What I would like is to capture the generated jar files and place them into a directory as they are created build after build, version after version.
Possible?
Thank you!
Without knowing more about why you want to achieve this, it's hard to recommend a solution.
A mvn clean install will install all the artifacts into your local repository, but assuming you want a more custom directory layout - you could use the maven-antrun-plugin and use ant to arrange the relevant files.
If you're happy with the default repository layout, you could also configure the repository settings for the project to deploy your plugin into a specific filesystem location (which would be dedicated to this particular project).
Alternatively, you could use the wagon plugin to do the deployment:
http://www.java-tutorial.ch/maven/deploying-in-file-system-using-maven
im using a .bat file that runs
cd dir
mvn clean install
copy dir\*.jar %LIFERAY_TOMCAT_HOME%"\..\deploy
what do you think? would that suit your needs?

How to download all possible maven dependencies so they are local

I work behind a very massive firewall that likes to hiccup on random connections, which makes all work with remote repositories a living nightmare for me!
I am looking to work with a project from Git (this one https://github.com/mrniko/netty-socketio) which heavily utilizes maven for downloading dependencies.
What I would like to do is on another terminal (such as http://cloud9.io or something) download all the maven dependencies so that the entire project can be run standalone.
I have already tried mvn clean install and then zipping up the source folder, but its actually not enough! I still get ClassNotFound related errors when I try to run the project locally in eclipse. And for the record, I did add the compiled *.class files in the build properties, so Eclipse knows where they are. It seems like there are some random classes that get generated dynamically which still aren't present (such as log4j -- and I really don't want to hunt each one down individually)
I am wondering if there is a fully thorough way to download all possible dependencies from maven and then either run a project 100% standalone, or create a local maven server from it?
I am running Java 7 on Eclipse Luna and I do have Maven installed on my windows 7 machine (though again it barely works on remote repositories). I also have a Cloud9 instance which I could use to run Maven commands, then zip up the results for local download.
When you execute mvn clean install, maven downloads all dependencies of currently built project to your local maven repository. This is usually located in
%USERPROFILE%\.m2\repository
When you build your project, maven uses that path, to lookup required dependencies.
If you want do download them all, you can try using mvn dependency:copy-dependencies. Then, you'll find all project dependencies intarget/dependencies directory of your project. This also includes transitive dependencies.
To add them all as eclipse dependencies, you may want to try maven-eclipse-plugin. Using that plugin, you can generate eclipse .project and .classpath files, using mvn eclipse:eclipse command. This will populate eclipse files with required dependencies from maven. You should then import the project to eclipse using Import existing projects into workspace, instead of Import existing maven projects.
maven-eclipse-plugin will add all those jars relative to a folder specified by M2_REPO variable. Just make sure you edit this variable inside eclipse project properties, and you should be set.
I've had to deal with similar issues. I would find that due to changes in firewall policies, occasionally all the .jar files in my project had been updated to be a 1K file that, when opened within notepad++ contained a message from the firewall saying that the download had been blocked.
I recommend looking into Nexus for your local repository management, it means your local projects don't have to go past your firewalls to check for maven updates.
http://www.andrejkoelewijn.com/blog/2010/03/09/getting-started-with-nexus-maven-repository-manager/
Use dependency plugin go-offline task.

maven project checkin in svn with local jar

I am working in a application which consume a webservice. I generated the webservice client using axis2codegen. Since it is generated code there are lot of duplicate codes exist. As per suggestion on code review we have to remove it and add it as jar. I created a jar and add to the local repository of the maven. But the problem is how can i check in the locally generateed jar to the svn, so that the user who check the project does not need to add it to the local repository manually as i did it.
Thanks in advance
Storing the .jar files in subversion isn't really the "maven way". You might want to consider setting up a corporate maven repository using something like nexus or artifactory and then deploy your .jar artifacts there instead.
Once that's done you can distribute a corporate settings.xml file pointing to this repository (or include it in each projects pom.xml file) and you can then manage your generated code like any other maven dependency.
HTH
Don't commit jar into SVN: dependency management has introduced the concept of "artifact repository" separating binaries from sources:
binary are saved into artifact repository
source are saved into source code management repository
In order to share the jar with your pears you should:
install the jar in a corporate maven repository like artifactory or nexus
add a dependency to the jar in your project pom
commit the pom into SVN
tell to your pears to check out from SVN the updated pom
You don't. In most circumstances you will use maven to deploy the project (the jar) to a repository manager (Nexus is by far the de facto for this).
Next you configure your co-workers to proxy their maven requests to yuor Nexus installation which itself "knows" about maven Central, thus providing a single point of presence for everything both from the outside world and published internally.
It's usually a good idea for another service such as Jenkins to be paired with a release plugin to execute the maven release procedure on your before, and for it to publish the artefacts too.
Here we have a long list of maven projects that our Jenkins installation builds upon noticing an SVN change. Upon the click of a button within Jenkins for the project, it can perform a complete build and release to our Nexus repository the project's newly built-and-tested artefacts.

Add jar to maven project & git integration

I have a maven-java project and I use git at the same time. Now I need to use some libraries which does not have any maven support. I have the .jar files of the libraries.
How will I add them to my maven project? and.. Will the other people who pull my code from my git repo be able to run my code without having the .jars?
If you have an artifact repository manager such as Nexus, Archiva, or Artifactory, you can deploy the jars to it. Then you can define them as dependencies in your pom.xml files.
If you don't, you can install them to your local repository using the maven-install-plugin using the install-file goal.
If you don't want to do that, there's also a not-recommended option of defining a dependency with <scope>system</scope> as illustrated here. Again, this is highly NOT recommended, as you would be expecting people would have the artifact on their file system and quite possibly, this jar might end up in your version control, which is really not the way to do it, but is also possible.
answer is that others will not be able to build your code unless some conditions are met.. As mentioned by carlspring, you would have to either install to your own local repo or put a system scope dependency.
if you add it to your local repo, then your local would have to be
some kind of common network writeable share/location that your entire team maps to in a standardized fashion in your development environment.
if you add a system scope dependency, you could actually put this jar into your codebase into a project relative lib directory and provide a path such as ${basedir}/lib/some.jar

Categories