mvn clean install, mvn install:install-file order? - maven

I am learning maven and trying to understand the order of things. As I understand, mvn clean install builds the repository with the default jars, where install produces a .zip that I will need later.
I want to use my custom jars which I call mvn install:install-file, but when I run this before install, I get some cannot find symbol errors. I am assuming my custom jars (which don't contain these classes) overwrites some default jars? I can't find these classes anywhere on my filesystem, so I am assuming they are already packaged in 1 of the default jars. How can I get around this?
Also, which order should I do things? All I want is the final .zip, that includes the custom jars?

mvn install -- builds and packages the source code and copies ( installs ) the artifact to your local repository which is $USER_HOME/.m2/repository
It's hard to say what's happening there without looking at the command you typed in, and the error trace that you received. That said, install-file is to copy an artifact to your local repo at appropriate hierarchy. It's nothing more than that. The correct syntax would be:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Usually, you just need to run install:install-file for all the custom dependencies once, and before you execute the mvn install.
If your custom jars have same coordinates -- artifactid, groupid, and version as some of the dependencies in your pom.xml and your custom jars do not have the classed that your source code uses -- well, you get the error.
refer: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Regarding to the maven-install-plugin website they mention as the following: -
install:install-file: is mostly used to install an externally created artifact into the local repository, along with its POM. In that case the project information can be taken from an optionally specified pomFile, but can also be given using command line parameters.
This means the artifact should be created before using this command. If you would like to deploy your fresh compiled code to the local repository, please just use the mvn clean install.
Please look at the Introduction to the Build Lifecycle for further information about the sequence and lifecycle. I hope this may help.
Regards,
Charlee Ch.

Related

maven: local installed jar not found

I'm getting this error message:
Could not resolve dependencies for project com.psgd.template:backend:war:1.0.0: Could not find artifact com.oracle:ojdbc7:jar:12.1.0.2
I've previously installed this library into local repository using:
mvn install:install-file \
-DgroupId=com.oracle \
-DartifactId=ojdbc7 \
-Dversion=12.1.0.2 \
-Dpackaging=jar \
-Dfile=ojdbc7-12.1.0.2.jar \
-DgeneratePom=true
I've look up into my repository:
$ ls -Rh ~/.m2/repository/com/oracle/
/home/jeusdi/.m2/repository/com/oracle/:
ojdbc7
/home/jeusdi/.m2/repository/com/oracle/ojdbc7:
12.1.0.2
/home/jeusdi/.m2/repository/com/oracle/ojdbc7/12.1.0.2:
ojdbc7-12.1.0.2.jar.lastUpdated ojdbc7-12.1.0.2.pom.lastUpdated
So, it's present into local repository.
Any ideas?
Many things can go wrong here.
When you run mvn install:install-file you should see the log line in command line: something like : INFO Installing file ... to full <<PATH_COMES_HERE>>
So check that path.
If everything works as expected you should be able to see both pom.xml and the jar in the corresponding folder of your repository, not "lastUpdated" I believe.
I don't see it in the provided snippet...
You can also check permissions as one possible source of issues.
The last thing is checking the actual pom generated by install:install-file. Make sure, the pom is valid and contains the information you've entered.
You can also delete the whole folder from maven repo and re-run mvn install:install-file maybe the repo went corrupted for some reason who knows.
The files
ojdbc7-12.1.0.2.jar.lastUpdated ojdbc7-12.1.0.2.pom.lastUpdated
mean that the Maven looked for the pom and did not find it. It is a kind of cache for missing artifacts.
Please delete these two files and try again to install the jar. Then try again to build against it.

Jenkins & Maven - build process

I am learning about Jenkins and I have to explore some existing build jobs that others wrote (in the company that I'm working).
So I am trying to understand a job which uses mvn command.
So under the build part (inside the job), I see these details:
Maven version: 3.0.5
Root POM: pom:xml
Goals and options: clean install -U -Pnotest,docs
I'm trying to understand what this mvn command means?
I tried to google it: "clean install -U"
But I didn't find what the parameter U means.
And I don't know what is "-Pnotest,docs".
can you guide me regarding how I can find what's it? (maybe "-Pnotest,docs" is from a xml file or it's from the artifactory etc..)
Thanks a lot!!!!
-U Forces a check for miss releases and updated snapshots on remote repositories
If Maven is regularly used in your company, and you will have to work with it on a day-to-day basis, I would advise you to find a mentor (any colleague that knows the tool well and is ready to share its knowledge with you) and work with them. Maven, when you first look at it, can be quite of a mouthful and you'll learn it more efficiently with their help.
For the problem at hand, Elarbi Mohamed Aymen's answer already tells you what the -U flag corresponds to. As for -P, it is used to activate profiles (in your case notest and docs). These profiles are usually defined in the pom.xml of the project being build.
See Running Apache Maven for the basic commands, and as advised on that page run mvn -h to have the complete list of flags the command can use.
Maven is one of the mechanism how to handle the build process and check project dependencies, especially for Java.
One of the option can be to have physically included dependencies (artifacts / libs) in the project, but its not so useful- in case of new version, you have to replace the file, sometimes you are using same lib in more apps, ten you have to handle it manually in all projects.
Except this, there is the maven- it has a global repository with shared artifacts / libs , which are common used- ref. https://repo1.maven.org/maven2/.
Except this, you can make your own libs/ artifacts in this case, its a modules / applications which are reusable, then you are storing it in private repository- this is the artifactory.
When you want to build your project, in case of maven project you have pom.xml , which is like manual for maven what to do / how to build.
clean and install are common goals, clean will wipe your local maven repository, install will download them again, with parameter -U it force to download them.
You can define your own goals in pom file, eg. to "tree build"- build some dependent modules, then build parent project.
Eg. with -D you pass parameters to the maven eg.
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app
- that will generate new project, based on given archetype- "template", with the given groupID and artifactID- groupID can be eg. company name, artifactID is then the name of specific app / component.
-P,--activate-profiles <arg> Comma-delimited list of profiles
to activate
-D,--define <arg> Define a system property

How to install Maven archetype from local JAR and POM, and also update local catalog

I want to distribute a custom archetype JAR and POM, without deploying them to a Maven repository, so that someone can grab them and install in their local repository with something like a mvn install:install-file -Dfile <file> -DpomFile <pom>.
But if one just does:
mvn install:install-file -Dfile=./my-archetype-1.0.jar -DpomFile=./my-archetype-1.0.pom
the local catalog doesn't get updated.
Though there are similar questions like this, this and this, they left me missing a small step.
I'm not sure how to run the mvn archetype:update-local-catalog that they mention. Where's the pom.xml?
Simply run mvn -f <archetypePomFile> archetype:update-local-catalog doing a mvn -f pointing to the archetype pom.
So altogether it's:
Install archetype
mvn install:install-file -Dfile=./my-archetype-1.0.jar -DpomFile=./my-archetype-1.0.pom
Update local catalog
mvn -f my-archetype-1.0.pom archetype:update-local-catalog
Maybe that's obvious to others reading the doc but I spent enough time on this that I thought I'd write it up.

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>

Where can I find a repository containing functionaljava 3.0?

I would like to use functional Java 3.0 in a maven project. I have been googling a little, but I can't find valid information to include the corresponsding 'dependency' in my pom.xml.
Someone mentioned that he would upload the artifacts to the scala-tools maven repository, but it does not seem like he followed-up on his announcement.
It does not even seem that earlier versions of functional Java are available from maven.
Does anyone have valid and recent information about this issue?
Thanks!
P.S.: Yes, I know I can download and manually include the .jar in my project, but this is only a workaround solution...
Version 3.0 is now in Maven Central: http://repo1.maven.org/maven2/org/functionaljava/functionaljava/3.0/
There doesn't seem to be any maven distribution. But here's a small shell script that will install the jar and the sources in your local repo.
Unpack the zip distribution and execute this script from inside the unpacked directory:
#!/bin/bash
# edit these to suit your needs
GROUPID=org.functionaljava
ARTIFACTID=fj
VERSION=3.0
mvn install:install-file -DgroupId=$GROUPID -DartifactId=$ARTIFACTID \
-Dversion=$VERSION -Dpackaging=jar -Dfile=functionaljava.jar
cd src/main
jar cf src.jar *
mvn install:install-file -DgroupId=$GROUPID -DartifactId=$ARTIFACTID \
-Dversion=$VERSION -Dpackaging=jar -Dclassifier=sources -Dfile=src.jar
rm src.jar
(Windows version would be very similar, probably just replace $this with %this%, maybe prepend CALL to the maven calls)
Fact is, I don't like to manually include .jars in repositories, because it is not a distributed solution.
I have copied the functional java code in a maven 'repository' project called 'externals' and it compiles fine. I can generate the artifacts and have no need to upload them manually anymore.

Resources