Maven Command Dependencies - maven

I am trying to execute "mvn license:add-third-part" on a server, that is not connected to the web. It's missing some dependencies. I tried to add them manually, but it says that still some transitive dependencies are missing. I there a way to display all dependencies by a Maven Command, including transitve ones?
I know the
"mvn site"
"mvn dependency:tree"
Commands, but I dont know how to execute them on a Maven Command.
Also did not found anything on the Codehouse Mojo Page, which created the Command.
did try to execute "mvn dependency:tree" on mvn license:add-third-part's folder, but didnt work as I assumed, cuase its no Maven Projekt
looked into "mvn license:add-third-part"'s Pom but there are only the direkt dependencies
added Dependcies manually -> lead to the "transitive Dependencies are missing" Warning

I am not sure how you are going to resolve dependencies if your host is not connected to the Internet. However you can just create separate pom.xml (in some separate folder) and include there the only dependency of your plugin.
Say you are using plugin v2.0.0:
<!-- https://mvnrepository.com/artifact/org.codehaus.mojo/license-maven-plugin -->
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>2.0.0</version>
</dependency>
Now inside that folder run mvn dependency:tree.
Another way is to use online service like: http://101coder.com/genTreeUI

Usually you resolve the problem by using a company Nexus/Artifactory that resolves the artifacts for you (from the web). Without this, it is hardly possible to run a normal build (like mvn clean deploy).
You can of course also run the command on a machine that is connected to the internet (with a fresh local repository) and then copy the downloaded dependencies over.

Related

Run mvn exec:exec without a pom.xml

I am trying to find a way just to fetch a library from maven repository and run it. I want to define everything by command line and ignore the pom. I am trying following:
mvn exec:exec -Dexec.mainClass="org.main.Class" -Dspring.profiles.active=test
When I try to run it with pom.xml, it starts to fetch all the dependencies described in the pom. Which I really don't want. When I run it without the pom.xml, it says Goal requires a project to execute but there is no POM in this directory. Please verify you invoked Maven from the correct directory. Is there a way to run it without the pom or at least ignore it?
My goal is just to start my application from anywhere without sources or jars.
One possible workaround would be to:
first get the jar
then execute it
For that, the maven plugin dependency:get is handy, and can be executed without any pom.xml/project (so from any folder you want)
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=https://dtp.intramundi.com/nexus/repository/maven-central/ -Dartifact=<group>:<artifact>:<version>
Once you have copied the artifact to the folder of your choice, a plugin like dependency:copy-dependencies could, reading the pom.xml of the artifact you just got, copy said dependencies to the same folder of your choice.
Finally, a java -cp . yourArtifact.jar can execute it.
I realize this is not as straightforward as just "exec:exec", and that it fetches dependencies from the pom.xml, but here at least:
the first step does not require any pom.xml,
the second step needs the pom.xml of the very artifact you want to execute, and those dependencies might be needed at runtime: you would need those anyway if you want to 'exec' your artifact.
Nope. It's impossible. Mvn Exec is, in fact, Maven Pluging dedicated to execute something as part of maven-nature project. If you need to execute Jar outcome why not use just java ***.jar ?

Installation and deployment of maven test-jar

I've discovered the wonderful test-jar facility in Maven: https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html
But it may so happen that one project needs to use the test-jar of another project. From https://stackoverflow.com/a/6469256/421049 and experimentation, it would seem that using mvn install does not install the test-jar to the local ~/.m2/repository. So how does one project on my machine use the test jars of another project not in the same aggregate POM?
Yet it would seem from Maven deploy not to upload test jar that deployment of a project to Maven Central does in fact deploy the test-jar? So I can deploy it to Nexus but not install it locally? And if I deploy it to Nexus, will my local project using a dependency of <type>test-jar</type> go find it on Maven Central?
It turns out that maven-jar-plugin does in fact install the test-jar (e.g. foo-1.2.3-tests.jar) in the local Maven repository ~/.m2/repository/.... Wonderful!
My problem is that I had inadvertently configured the maven-jar-plugin to be in a separate profile named release. (I had copied and pasted to the wrong location in my POM.) That's why the test-jar didn't show up in my local repository after a mvn install, and that's why it suddenly showed up later (after I used -P release once in testing), and I thought I had just missed it when I looked the first time.
I move the maven-jar-plugin to the <build> section and everything is working fine: the test-jar gets put into the local maven repository using mvn install.
In my case, I was setting maven.test.skip for a particular build profile. That property actually causes tests to not be compiled/installed, thus also preventing their deploy. The solution was to set the skipTests property instead.

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.

Maven ant task to add system path jar to WAR file

Running into a small problem. I have a spring-maven project. And there are some external jars I need to add into the POM which I did using .
Now to build the WAR file we are using an Ant Maven task i.e. artifact:mvn providing the argument war:war.
Here somehow my external jars are not getting added to the WAR file i.e. WEB-INF/lib
Can some one please let me know if I am missing something. Below is my pom entry
<dependency>
<groupId>{test}</groupId>
<artifactId>Test</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/test.jar</systemPath>
</dependency>
Best solution is to start using a repository manager (a.k.a "Maven proxy server") and install the needed artifacts (test.jar) into the repository manager and use it as a usual dependency instead of using system scope via systemPath.
Calling mvn war:war via Ant does not make sense and shows you should learn how Maven works.
Change the packaging type in your pom file to war and you can simply call maven via:
mvn clean package
and everything should work. But this is only gues cause you didn't show your full pom file.
Install the test.jar locally using mvn install:install-file (docs). Now you can remove the system scope (and the systemPath) and everything will work out of the box.

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>

Resources