Maven local repository - maven

I want Maven to work offline. I downloaded all artifacts like spring and hibernate onto my computer. Then I tried to set up Maven to use local repository only. I followed instructions to point Maven to local repository. However every time I tried to load spring mvc project, I got the errors like this:
Offline / Missing artifact org.springframework:spring-context:jar:3.0.6.RELEASE:compile
Offline / Missing artifact org.springframework:spring-core:jar:3.0.6.RELEASE:compile
I checked the local repository. The jar and pom files are there. I can't figure out what is wrong with my configuration. Can someone help me out here?
Thanks.
Jerry

You probably messed up your settings.xml.
Correct way to prepare for offline is this:
mvn install dependency:go-offline
The answer bilash.saha gave will not work for multi module projects.
After first command finished, you may test that everything is ok by running
mvn -o package
To save you a from typing "-o" every time use this settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<offline>true</offline>
</settings>

Run
mvn dependency:go-offline
then build your project offline using the '-o' flag:
mvn install -o

Related

AEM 6.5 WKND repo build issues

I created a maven project in batch mode by typing the following command:
mvn archetype:generate -B -DarchetypeGroupId=com.adobe.granite.archetypes -DarchetypeArtifactId=aem-project-archetype -DarchetypeVersion=22 -DgroupId=com.adobe.aem.guides -Dversion=0.0.1-SNAPSHOT -DappsFolderName=wknd -DartifactId=aem-guides-wknd -Dpackage=com.adobe.aem.guides.wknd -DartifactName="WKND Sites Project" -DcomponentGroupName=WKND -DconfFolderName=wknd -DcontentFolderName=wknd -DcssId=wknd -DisSingleCountryWebsite=n -Dlanguage_country=en_us -DoptionAemVersion=6.5.0 -DoptionDispatcherConfig=none -DoptionIncludeErrorHandler=n -DoptionIncludeExaples=y -DoptionIncludeFrontendModule=y -DpackageGroup=wknd -DsiteName="WKND Site"
when I type mvn -PautoInstallSinglePackage clean install
I get the following error:
[ERROR] Failed to execute goal on project aem-guides-wknd.ui.apps: Could not resolve dependencies for project com.adobe.aem.guides:aem-guides-wknd.ui.apps:content-package:0.0.1-SNAPSHOT: Could not find artifact com.adobe.aem.guides:aem-guides-wknd.ui.frontend:zip:0.0.1-SNAPSHOT
From the error I guess and when I searched that there is no such artifactid in maven repository. Can someone please help me out here?
If your sole requirement is to build the wknd project, then just download the maven project from git and import it as a maven project in eclipse. After that build it. That should hopefully resolve your issue.
You have below options :
1.You Can check your root pom.xml file. There you can comment out ui.frontend module i.e. <!--module> ui.frontend </module-->. After hat you can run your package build command.
2. you can got to each sub-module like core,ui.appss and run following command to build individually mvn clean install -PautoInstallBundle
Let me know if this helps or will look into some other solution.
Inside parent pom.xml comment dispatcher module
example :
<modules>
<module>all</module>
<module>core</module>
<module>ui.frontend</module>
<module>ui.apps</module>
<module>ui.apps.structure</module>
<module>ui.config</module>
<module>ui.content</module>
<module>ui.content.sample</module>
<module>it.tests</module>
**<!--<module>dispatcher</module>-->**
<module>ui.tests</module>
</modules>

Errors with Maven install on a project

I'm trying to install Maven on a project (with mvn clean install) but I have some errors and I don't know what they mean.
Here is the screen shot of the cmd :
I also add the right environment variables for maven (M2, M2_HOME and MAVEN_OPTS).
Can someone help me and tell me what it means please ?
It means that your dependency to eu.akka.jbossas:jboss-as-client:7.1.7.Final that you have specified in your POM is not available at Maven central. Do you have the jar file available somewhere?
If that is the case, run this:
mvn install:install-file -Dfile=<your jar file> -DgroupId=eu.akka.jbossas -DartifactId=jboss-as-client -Dversion=7.1.7.Final -Dpackaging=jar
Please bear in mind that this means that only the machine you are running on will be able to build your project. If other developers/machines also need to build this project, consider installing a central repository at your site, such as Nexus or Artifactory, and upload the jar file there. You will then also need to make Maven aware that it should fetch the dependencies from there.
The error tells you that the maven dependency eu.akka.jbossas:jboss-as-client doesn't exist. I've checked the url where it should be and it doesn't exist.
You should check other dependencies. For example the one maven provides:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-appclient</artifactId>
<version>7.1.1.Final</version>
</dependency>
If you've got the jar local, you can create a maven-dependency by using this guide.

Run tomcat project without pom.xml (like yum or apt-get)

For a presentation purpose and installation handbook i like to run a tomcat-project directly with only maven installed.
I googled around an found:
a way to download the dependency directly my mvn dependency:get
a way to start the war by mvn tomcat7:run
Is there any way to have a short shell-command who download the dependency from the server, compile and start it?
Actually i got this:
mvn dependency:get tomcat7:run
-DgroupId=XXXXX
-DartifactId=hasty-tumbleweed
-Dversion=0.9.2-SNAPSHOT
-DrepoUrl=file://C:/Users/woodcraft.xenther-vladic/.m2/repository
But mvn still try to find the plugin from the official maven repository.
Any Idea?
Are you maybe missing this:
Caveat: will always check the central repository defined in the super pom
From the little information here, you make it look as if you're distributing files already (the repository stuff) so why not provide a POM as well, opening you up to doing whatever nifty Maven stuff you desire. Then you can do:
mvn install -f <path to your POM>

Maven and Jsig CAS 4.0RC

I have downloaded the code from the repository but I have little experience to use maven (command line) to get the .war file to be included in my tomcat.
I do not have experience in this.
I have not changed the pom.xml file
I directly run the command mvn clean package but I have several errors.
Spete help me?
My goal is to generate the. War file CAS 4.0RC
I'm using the pom.xml file that I found on git (a very long file) can fit that?
If you've downloaded the source of CAS and its by itself should be a mavenized project then, pom.xml should be inside.
so you should just 'cd' to the root folder of your source and type
mvn install
or
mvn package
The first command will install your jar into local maven repository, the second one will only prepare the war in the target folder of the module with packaging war in the source.
If you encounter any errors, please post them here.
Hope this helps
It should build without any problem when executing mvn clean install in the CLI... What are your errors ?

Maven fails to find local artifact

Occasionally maven complains that a particular dependency, which is built and packaged locally, cannot be found in the local repository while building another project that has it as a dependency. We get an error like:
Failed to execute goal on project X: Could not resolve dependencies for project X: Failure to find Y in [archiva repository] was cached in the local repository, resolution will not be reattempted until the update interval of internal has elapsed or updates are forced ->
Where X is the project being built, and Y is the supposedly missing artifact. If you look in the local repository, the artifact is there. This artifact is never installed in our archiva repository, so the problem is purely based in the local repository.
We have tried various profiles in settings.xml, and of course "mvn -U". Neither do any good, nor should they because this artifact never goes any further than the local repository.
The only two things that seem to work are to wait a very long time until maven smartens up, or to completely delete the local repository. Presumably the waiting option is related to the aforementioned update interval.
We have experienced this problem with maven 3.0.2 and 3.0.3. We are using Archiva 1.0.3 (but again this shouldn't be a factor). Any help would be greatly appreciated.
The local Maven repo tracks where artifacts originally came from using a file named "_maven.repositories" in the artifact directory. After removing it, the build worked. This answer fixed the problem for me.
As the options here didn't work for me, I'm sharing how I solved it:
My project has a parent project (with its own pom.xml) that has many children modules, one of which (A) has a dependency to another child (B). When I tried mvn package in A, it didn't work because B could not be resolved.
Executing mvn install in the parent directory did the job. After that, I could do mvn package inside of A and only then it could find B.
Even in offline mode, maven will check remote repositories if there is a _remote.repositories marker for the dependency. If you need to operate in offline mode, you may need to delete these files.
The simple shell command below deletes these marker files. This is safe to do if you only use offline mode for the machine. I would NOT do this on a machine that needs to pull files down from the web.
I have used this strategy on a build server that is disconnected from the web. We have to transfer the repository to it, delete the marker files and then run in offline mode.
On Linux / Unix you can delete the remote repository marker files this way:
cd ~/.m2
find . -name "_remote.repositories" -type f -delete
Maven remembers when it didn't find something. The key is "resolution will not be reattempted until the update interval of internal has elapsed or updates are forced ->"
The quick solution is to delete your local "repository" subdirectory for the problem artifact - assuming you have fixed the problem with it. :)
mvn -U will force update from remote repository - again, assuming you have now populated remote with said artifact.
When this happened to me, it was because I'd blindly copied my settings.xml from a template and it still had the blank <localRepository/> element. This means that there's no local repository used when resolving dependencies (though your installed artifacts do still get put in the default location). When I'd replaced that with <localRepository>${user.home}\.m2\repository</localRepository> it started working.
For *nix, that would be <localRepository>${user.home}/.m2/repository</localRepository>, I suppose.
If you have <repositories/> defined in your pom.xml apparently your local repository is ignored.
Catch all. When solutions mentioned here don't work(happend in my case), simply delete all contents from '.m2' folder/directory, and do mvn clean install.
Even I faced this issue and solved it with 2 ways:
1) In your IDE select project and clean all projects then install all the maven dependencies by right clicking on project -> go to maven and Update project dependencies select all projects at once to install the same. Once this is done run the particular project
2) Else What you can do is check in the pom.xml for the dependencies for which you are getting error and "mvn clean install" those dependent project first and the install maven dependencies of the current project in which you facing issue. By this the dependencies of the local project will be build and jars will be created.
I run to the similar problem when my new project depend on oracle jdbc jar(which I have installed in my local repository and work well for other projects). I tried -U option ,deleting .lastupdate file or the whole directory and downlaod again,but it did not work. finally,I deleted the directory and installed it locally again,it works.
One of the errors I found around Maven is when I put my settings.xml file in the wrong directory. It has to be in .m2 folder under your user home dir. Check to make sure that is in the right place (along with settings-security.xml if you are using that).
I had DependencyResolutionException in Ubuntu Linux when I've installed local artifacts via a shell script. The solution was to delete the local artifacts and install them again "manually" - calling mvn install:install-file via terminal.
This happened because I had http instead of https in this:
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
check if if your artifact Y have packaging set to "jar". If you have defined it as "war" by error or copy paste, it will show this strange "was cached in the local repository, resolution will not be reattempted until the update interval of internal has elapsed or updates are forced". I would expect something like "artifact Y is war, jar type expected".
In my case I needed project Y to be a WAR to be deployed through Tomcat, as well as it needed to be a JAR to be able to add it as a dependency in project X.
So in project Y's pom.xml, I added this plugin to create a JAR along with the WAR:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<attachClasses>true</attachClasses>
<classesClassifier>classes</classesClassifier>
</configuration>
</plugin>
And while adding the dependency of project Y in project X's pom.xml, I had to add a classifier:
<dependency>
<groupId>groupId.of.project.Y</groupId>
<artifactId>project.Y</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>classes</classifier>
</dependency>
Note: when you build project Y, you will see 2 packagings in the target folder: project-Y.war and project-Y-classes.jar, so that's why while importing you are specifying the classes classifier to import the JAR and not the WAR.
Here is the long Solution to the problem
(Not Quick fix but will work if no other solution)
You're going to hate me for saying this but this is the truth about open source projects like eclipse. Because Open source is modular and allows you to build and develop a project in many ways with many tools such as maven, spring boot, options for xml or groovy, different eclipse updates & Etc. The problem is that eclipse allows you to run the project with missing maven builds because the IDE is smart enough to resolve dependencies using a remote_repository where it stores and catches the jar files that is not properly built on the project.
Because of this feature, You may actually have local build issues but just like DNS servers; if the solution is not found in the local directory, Eclipse will look for a solution in it's remote cached repository. When you delete the remote_repository and let Maven rebuild it a second time, The project may end up creating more errors and not build a second time or may possibly rebuild a cache that was missing. But that is unlikely.
So the long answer to fix your solution.
This is a project architecture issue!
SOLUTION:
What you need to do is look in to all your dependant project's pom.xml file and the maven dependencies folder in your local project and try to resolve all the missing dependency jars in your maven dependency folder. If you have a referenced library, I suggest moving those jars into your local project's maven dependency folder.
You have to work your way into solving every child project and then navigate into your root project and fix every single project by using Maven -> Build -> clean install (check off "skip tests" & "resolve workspace artifacts") until every project builds with a clean success.
most likely, when you force update your entire solution to all your projects, you will get a list of errors that you have the IDE auto-resolve. The auto-resolve will refer to a easy reference to fix the issue. But to deploy, you have to manually fix the project because Eclipse, Spring & Maven will work well together but there are maybe a few things they don't agree on. So, you have to play diplomat in those situations and figure it out.
That's the sad truth.
All said, I have a list of problems in my project. I have this issue. The war file generated has empty jar folders and the build is not clean without errors unless i force it. The WAR file generate will run a 404 error on tomcat server production and my angular application will throw a Cors-Error when executing the API.
All the errors on my front end project is artificial because the root of all issues is the WAR file generated. It did not generate with dependencies, the Main project did not execute in tomcat and tomcat server cannot run the spring initializer to deploy the cors-policy on the server to allow my angular application to communicate. But all in all, development environment works fine with no issues.
So that is my long ended solution for this thread.
I had the same error from a different cause: I'd created a starter POM containing our "good practice" dependencies, and built & installed it locally to test it. I could "see" it in the repo, but a project that used it got the above error. What I'd done was set the starter POM to pom, so there was no JAR. Maven was quite correct that it wasn't in Nexus -- but I wasn't expecting it to be, so the error was, ummm, unhelpful. Changing the starter POM to normal packaging & reinstalling fixed the issue.
In my case I had to add mavenLocal() in root level gradle dependency
mavenCentral()
mavenLocal()

Resources