How to run a maven created jar file using just the command line

前端 未结 4 1098
庸人自扰
庸人自扰 2020-12-01 05:20

I need some help trying to run the following maven project using the command line: https://github.com/sarxos/webcam-capture, the webcam-capture-qrcode example is the one I\

相关标签:
4条回答
  • 2020-12-01 05:23

    Use this command.

    mvn package
    

    to make the package jar file. Then, run this command.

    java -cp target/artifactId-version-SNAPSHOT.jar package.Java-Main-File-Name
    

    after mvn package command. Target folder with classes, test classes, jar file and other resources folder and files will be created.

    type your own artifactId, version and package and java main file.

    0 讨论(0)
  • 2020-12-01 05:25

    1st Step: Add this content in pom.xml

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

    2nd Step : Execute this command line by line.

    cd /go/to/myApp
    mvn clean
    mvn compile 
    mvn package
    java -cp target/myApp-0.0.1-SNAPSHOT.jar go.to.myApp.select.file.to.execute
    
    0 讨论(0)
  • 2020-12-01 05:37

    I am not sure in your case. But as I know to run any jar file from cmd we can use following command:

    Go up to the directory where your jar file is saved:

    java -jar <jarfilename>.jar
    

    But you can check following links. I hope it'll help you:

    Run Netbeans maven project from command-line?

    http://www.sonatype.com/books/mvnref-book/reference/running-sect-options.html

    0 讨论(0)
  • 2020-12-01 05:41

    Just use the exec-maven-plugin.

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>com.example.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    Then you run you program:

    mvn exec:java
    
    0 讨论(0)
提交回复
热议问题