18

I'm new to maven project. I'm changing an ant project to maven project. To install the 3rd party jar's in maven local repository, I used install command. Its trying to download the resource jar.pom. I don't have download access in my organization so the build failed for installtion. After request i got the resouce jar and clean jar in my desktop(also i can get other necessary jar). How to make maven to use these jar for the process and how to install the jar in local repository without internet acess.

I downloaded the jar and placed in local repository but it couldn't point the path and use those jars.

please let me know what steps i have follow to run maven install and other commands to build the project without internet access.

where should i placed the jar which i have downloaded by external way.

Please guide me for building and deploying the project.

Thanks in advance.

http://maven.40175.n5.nabble.com/Maven-installation-and-using-in-project-without-Internet-conncetion-tp4564443p4564443.html. http://www.coderanch.com/t/544641/Jobs-Offered/careers/Maven-installation-project-without-Internet#2471141

I've posted same question in these link

Zumo de Vidrio
  • 2,021
  • 2
  • 15
  • 33

5 Answers5

17

You need an internet connection. Maven isn't initially self-sufficient. It needs to download a bunch of plugins along with their dependencies and the dependencies of your own project. And this really depends on what sort of settings you have for your projects. One set up will require one set of dependencies, another - a whole different one. You can't download artifacts from the Maven Central manually and then install them locally one by one. Simply put, that sounds stupid.

I understand that you're coming from the Ant world where Ant has everything it needs on the local file system. However, Maven relies on the fact that it will have a central repository (either Maven Central, or your own repository - Nexus, Artifactory, etc.) from which to download the plugins and dependencies it needs. There is no point in you migrating to Maven, unless you'll be allowed access to the Central Maven Repository.

Yes, indeed, you can run Maven offline and you can have Maven produce a local repository for you to use when you are in offline mode. However, what you're trying to do is against Maven's principles.

If your company won't allow access to Maven Central, just stick to Ant. Your effort will be a waste of your company's and, ultimately, your own time.

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • 4
    Furthermore, if you're not allowed to connect to the internet, perhaps your IT-s should set up a Nexus Maven Repository for you so that you can use it as a Maven proxy and be able to download the dependencies. – carlspring Jul 08 '11 at 12:16
  • Thank you for your support and guidelines. You have suggested me with clean explanation. I'm eager to upgrade my project to maven so i tried when client requested. Is there any possiblity to do this if a indepent machine has on maven default download package. Please suggest me any possibility just to know about it – Krishna Moorthy Seetha Raman Jul 08 '11 at 12:29
  • 3
    Krishna, no, there isn't a way to do it without the Internet. If they do not allow outbound connections to repo1.maven.org, then they should at least install a company proxy repository such as Nexus through which you could download the dependencies via Maven. If you have all the dependencies you need in a local Maven repository, yeah, surely you can build your project, but before that there's just no other feasible way. – carlspring Jul 08 '11 at 12:45
  • Thank you for your help carlspring – Krishna Moorthy Seetha Raman Jul 11 '11 at 05:28
  • 2
    This does really sound like a silly approach. How are projects that work on a secure environment supposed to use Maven if you need to have an internet connection to be able to use it? I work on a project that is completely protected from the outside world and based on what you are saying it is not possible to use Maven on such a project. – ziggy Dec 22 '11 at 15:39
  • 2
    @Ziggy: But I'm sure you have your internal repository (Nexus/Artifactory/etc) set up at and that that proxies connections for repo1.maven.org and fetches all the plugins and dependencies for you. Yeah, in that sense you can live without accessing the external web, as you'll have them cached in your internal repository. – carlspring Dec 22 '11 at 16:05
  • Why the down-votes? At least be decent enough to justify yourselves. – carlspring Sep 09 '16 at 11:43
  • Sorry but this didn't answer the question. You mention you can do it but don't give details on how to. Unfortunately in certain circumstances you need to build in an environment that does not have a direct internet connection (ie: all data going into an environment must be manually quarantined for a period of time then scanned then transferred via USB... Admittedly this can be a bit crazy, but if these are the security principles of the organization that's what you have to deal with). – maloo Jan 11 '18 at 02:42
  • @maloo: Actually, this answer explains to the original poster why it's not possible to use Maven completely disconnected from the web, without having a company (or other local) installation of an artifact repository manager, or a local cache on your machine. I'm not sure what you expect as an answer. If you really, really must work in complete isolation from the Internet, then Maven simply _is not_ the right tool for the job. This I have explained clearly as well. You might not like it, but this is a fact. – carlspring Jan 11 '18 at 15:38
  • @maloo: Sure, you can use `mvn dependency:go-offline` and work out some magic to generate a local cache of artifacts, but you would initially need the Internet for this. Where you'd put all this also another story (if you don't have an artifact repository manager). You could also install all of the thousands of dependencies one by one using `mvn install:install-file`, if you're extremely enthuciastic about using Maven in your locked down environment as suggested by @sblundy. – carlspring Jan 11 '18 at 15:38
4

I think the questioner is looking for -o or --offline option for mvn. This is a command line option and can be provided while executing.

I think you can setup your repo correctly and execute the mvn goals once when you are connected to internet and use the -o option for later executions .

Hope this helps.

~Abhay

Abhay Dandekar
  • 1,230
  • 10
  • 30
4

In fact the maven strenght is mainly in the internet accessible repositories and automatic dependency management. But it's possible to use this tool to build your project if you have all dependencies required for your project in your local repository. Then you may use -o option for offline mode and maven will not try to download updated artefact versions.

To get the artifacts into you local repository you have several options:

1) connect to the internet once and mvn build the project (this will download all required dependencies)

2) install dependencies as jar to the local repository manualy (using appropriate mvn command)

Martin Vejmelka
  • 448
  • 3
  • 15
  • I tried for this approach but it tries to download its jar from internet. for example resource,clean,deploy,... Where to place these jars for maven referance. Please help me out to trobleshoot this issue – Krishna Moorthy Seetha Raman Jul 08 '11 at 04:53
  • If you do `mvn build` for example - this SHOULD try to download all required artefacts and place them to `$HOME$/.m2/...` directories. Using this approach you will need internet connection but only for limited period of time. Then try to use `mvn -o `. Note the `-o` or `--offline` switch. If you haven't changed your pom.xml and have all your dependencies already downloaded, the build should work (I was using this for some time in order to make my build faster.). For adding third party jars follow: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html – Martin Vejmelka Jul 08 '11 at 09:33
3

You can configure maven to run in offline mode. Add this entry to your settings.xml

<offline>true</offline>

See here for further information:

http://maven.apache.org/settings.html

Before you can use offline mode, you have to install all necessary third party jars to your local maven repository.

mvn install:install-file
 -Dfile=filename.jar
 -DgroupId=com.stackoverflow
 -DartifactId=artifact
 -Dversion=1.0.0
 -Dpackaging=jar
 -DcreateChecksum=true
 -DgeneratePom=true

It's much easier to get those jars in your local repository using an internet connection and online mode.

phlogratos
  • 13,234
  • 1
  • 32
  • 37
  • Am tried with offline tag but it tries to download its jar from internet. for example resource,clean,deploy,... Where to place these jars for maven referance. Please help me out to trobleshoot this issue. – Krishna Moorthy Seetha Raman Jul 08 '11 at 04:54
  • 1
    The `` tag will only help you, if you already have all the dependencies you need in your local repository. The suggestion above won't help you at all. – carlspring Jul 08 '11 at 11:49
  • @carlspring Added info about installing files in local repository – phlogratos Jul 08 '11 at 12:04
  • @phlogratos, while indeed your example is correct, I am not sure Krishna understands the implications of using offline mode, when you're in the process of migrating from Ant to Maven. – carlspring Jul 08 '11 at 12:13
  • @carlspring That's why I added the last sentence. – phlogratos Jul 08 '11 at 12:33
  • Thanks for all. But client request for maven to build,pack ear and to deploy in server without download access. so am confused whether its possible by any means. I understood the purpose of maven but is there any possibility to work out for my issue. Its for my knowledge too. As I've to justfy for my client – Krishna Moorthy Seetha Raman Jul 08 '11 at 12:42
3

It's possible to install these resource jars in your local maven repo using install-file. This will make the available to the build. You'll have to do this for each individually, but once that's done you won't have to do anything special.

To be clear, maven puts everything in your local repository, both the jar you're building with this project and the various library jars. Because your system cannot be connected to the internet to maven can populate the local repo with your libraries, you'll have to use this manual approach.

Edit: You should be able to run install-file anywhere. When you do, you'll need to provide the groupId, artifactId, version, and packaging using the command line options. If you already have a POM file for the library, you can provide that instead via -DpomFile=your-pom.xml.

This question has some useful info: How to manually install an artifact in Maven 2?

Community
  • 1
  • 1
sblundy
  • 60,628
  • 22
  • 121
  • 123
  • From where install-file command should be executed.Same comments as i have given above was the result. It searchs for POM. whats the exact thing it tries. where should i place resource,deploy and maven's jars.Please help for solving the issue. – Krishna Moorthy Seetha Raman Jul 08 '11 at 04:54
  • Again, what's the point of manually feeding your local repository?! You either do it the Maven way, or simply not use Maven. – carlspring Jul 08 '11 at 11:48