Run maven project with dependencies from the command line

I have a maven project that depends on 2 other local projects and many third-party banks. I want to move the jar file to another computer and run the application from there. I tried the mvn exec: exec command, but it could not find 2 local projects, which makes sense. How do I get this script to work. the machine on which the application will be installed has maven in it and is connected to the Internet, so if necessary it can download the banks mentioned in pom.

+3
source share
2 answers

Use the Maven-assembly-plugin to create jar-with-dependencies, which will lead to the mvn packagecreation of a more easily deployable package.

+1
source

I could not understand much from the answer above. I think Maven looks complicated. In any case, I realized if you do this, then your problem will be solved.

First, in the pom.xml file, add this plugin to the build section , as shown below.

  <plugin>

    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
 </plugin>

I think jar-with-dependencies does the trick

Now follow this sequence of commands from your root directory (where pom.xml exists)

mvn compile
mvn package
mvn install assembly:assembly

I don’t know if the mvn package is required or not, but the third important one. Now, if you see your goal / you will see a jar with addiction.

How to start

 java -cp target/Your-Jar-1.0-SNAPSHOT-jar-with-dependencies.jar com.mycode.myapp

com.mycode.myapp... ( : maven, )

+3

All Articles