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

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>

Related

Maven Command Dependencies

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.

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 ?

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.

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

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.

Maven local repository

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

Resources