How to execute a maven goal described in a pom.xml file packaged in a jar - maven

I have a maven project which generated a jar with its pom file inside and this jar is deployed on different environment. pretty straightfoward for the moment.
I would like to execute a goal (a liquibase:update) from this pom file using only the jar produced. Is there a way to do this automatically with maven, without extracting the files from the jar beforehand ? Something like mvn -jar myJar.jar liquibase:update

Check the answer to this question, I think it can help you:
Is there a good way to use maven to run an executable jar?

Related

Run testng.xml from command prompt. I have jar that is created from Maven Project. Surefireplugin is not solving my purpose

What i have
Jar created from maven project
TestNG.xml file
What i want
Want to run testng.xml from command prompt
What i tried
Used surefire plugin in pom then executed mvn test command.
What is problem then ?
Surefire plugin will need. src folder and every time it will build project.
Any solution available ? Using jar file and testng . I dont want to use src or bin
You could use a multi-module maven project.
For example with two modules, A and B. Module A will build the jar file, and in module B, you can specify A as a dependency, and run your tests from there.

Upload multiple jar files to maven repository (e.g. Archiva)

In one of our project we are planning to generate multiple jar files (basically libraries, which contain no dependencies) .
We would like to upload these jar files to local maven repository (Archiva looks good, we are also open to other options) so other developers can simply use them.
(Single jar file deploy works great)
PS: We are using maven.
Thanks in advance.
When you build your jar files with Maven, you simply call mvn deploy (having a correct settings.xml) and the jar goes into your Maven repository.
If you have jars not built with Maven, you can use mvn deploy:deploy-file to upload them.

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 ?

What is wrong with my neo4j test setup? EmbeddedNeo4j.java, neo4j, maven

I started a project with maven using the "quickstart" archetype. I then changed my POM to include neo4j:
https://github.com/ENCE688R/msrcs/blob/master/pom.xml
I added:
https://github.com/neo4j/neo4j/blob/master/community/embedded-examples/src/main/java/org/neo4j/examples/EmbeddedNeo4j.java
and ran
mvn package
This works with no errors, but
java -cp target/msrcs-1.0-SNAPSHOT.jar org.neo4j.examples.EmbeddedNeo4j
Returns the Error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/neo4j/graphdb/RelationshipType
What am I missing? At this point I simply need to test that I can include and use neo4j.
use
mvn exec:java -Dexec.mainClass=org.neo4j.examples.EmbeddedNeo4j
there is also mvn dependency:copy that copies all dependencies to target/dependencies
and there is the mvn appassembler plugin that allows you to generate startup shell scripts that include all your dependencies as a classpath.
And last but not least there is the maven assembly plugin mvn assembly:single which generates a single jar file that you can run java -jar my-jar-file.jar
You need to add the Neo4j dependencies to your classpath as well. At the moment you're only adding the source jar you created. If you look at this POM you'll see that Neo4J examples require many other dependencies.
Find the libs directory where the dependencies have been downloaded (this may be in your local .m2 maven repo) and add these jars to your classpath. You do not need to add each jar one-by-one as you can simply add a directory with wildcards - ex:
Windows:
java -cp "target/msrcs-1.0-SNAPSHOT.jar;lib/*" org.neo4j.examples.EmbeddedNeo4j
Mac/Unix:
java -cp "target/msrcs-1.0-SNAPSHOT.jar:lib/*" org.neo4j.examples.EmbeddedNeo4j
I've started to work on some maven archetypes which could be a good starting point as well.
For java Neo4j projects, use neo4j-archetype-quickstart.
For Spring Data Neo4j projects, use sdn-archetype-quickstart.

Maven: Deploying a jar/war with built in pom.xml file

I don't have a Maven project. What I have is a jar with the pom.xml embedded in the file. When I deploy this via the Artifactory GUI, Artifactory finds the pom and deploys it with the jar. It even recognizes the groupId, artifactId, and version.
When I try using mvn deploy:deploy-file it fails. If I extract the pom, and run mvn deploy:deploy-file with the -DpomFile=pom.xml, it works. Is there a way of deploying this jar with the embedded pom via the Maven command line? Or, do I need to extract the pom.xml first?
I have not heard of the possibility to specify the pom file from archive. I think it is unlikely to be an option, because Maven itself is just a light-weight program, which runs with plugins; and it needs some configurations to run with; and all references to plugins to be used are in those files.
Consider writing an Ant script that will extract the file, run mvn deploy:deploy-file -DpomFile=pom.xml and then delete the file.
The solution looks not very nice, I know, but it should help.
This is an Artifactory feature and not standard Maven behaviour.
Keep in mind that, for example, if you use dependency:unpack-dependencies or the assembly plugin to create some sort of über jar there would be multiple pom.xml files within the jar under the /META-INF/ path so it would be very difficult to select which pom was the true pom.

Resources