简体   繁体   中英

Package a maven project via Windows command line

I want to release a server, built using Maven. The idea is that there is a batch file than can run the server and a batch file that can compile the server (any updated code, but stops leaching by not compiling certain changes).

Creating a deploy-able jar file in Maven is annoying as it is on its own using an IDE:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>
                    // Main class
                </mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

To then execute mvn package . But, the potential user who has downloaded the server, may not have MVN installed. Is there any way to package a maven project in the windows command line? (CMD) I have tried:

jar cvf MainClass.jar * // First attempt
jar cfe myJar.jar MainClass *.class // Second attempt

However, each of these will not work because it contains multiple packages therefor my structure looks like

- Folder A
    - a.class
    - b.class
- Folder B
    - c.class
    - d.class
etc..

Maven is frequently installed by java developpers, but there is a workaround if you don't have maven:

You can use the Spring boot maven wrapper, you don't need Spring boot dependencies, it's only 2 script and a directory with a jar that can be copied/pasted in your project : mvnw and mvnw.cmd and .mvn/*

Find an example of source here:

https://github.com/spring-guides/gs-spring-boot/blob/master/complete/mvnw

https://github.com/spring-guides/gs-spring-boot/blob/master/complete/mvnw.cmd

https://github.com/spring-guides/gs-spring-boot/tree/master/complete/.mvn/wrapper

It works just like the graddle wrapper:

  • It download a maven runtime from the tiny jar
  • It launch it.

CLI usage:

$ ./mvnw clean install

PS: The inconvenience of this method is that you rely on having the network for the download (with proxy well configured if needed) and every project you build will need the wrapper.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM