gradle package

Non-web applications

Non-web project, few posts to explain this package and run. (Web projects easily by adding warplug-ins and gradle buildpackaging)

Run out of the way to try several.

idead directly run

Use idea runs directly maincategory can be.

Use plug-ins

Use gradle, you need to build.gradlefile, add the plug-in applicationand set good name of the main function mainClassName. Finally, the project root directory ( build.gradleexecute the command the same directory):

gradle run

Packaged into multiple jar files

Still we need to step on the applicationplug-in and mainClassNameconfiguration, and then execute the command to download dependencies and publish:

gradle install

Open build/install/项目名/Directory can see two folders bin/and lib/, in the lib directory are packaged jar package and other items to add dependencies, the bin directory is configured sh script, convenient and direct operation.

This sh script is mainly acquired the lib path, all paths inside the jar packets are recorded, and then execute the command java -classpath 绝对路径/lib/xxx.jar:绝对路径/lib/yyy.jar com.yww.Mainto run.

Packaged into a single jar file

One way out of the pack, packaged jar own projects and dependent jar are scattered heap in the folder, run-time, also you need to specify all the jar package path -classpath, very troublesome. Found in build.gradleconfiguration are packaged, and does not require plug-ins applicationand mainClassNameconfigurations.

jar {
    from {
        configurations.runtime.collect{zipTree(it)}
    }
    manifest {
        attributes 'Main-Class': 'com.yww.Main'
    }
}

Locate the directory build/lib/execute the command to run:

java -jar demo.jar

Idea can be found directly packaged into a single file, output to out/the directory, but not the same run, can not find the main class, need to run the java -classpath demo.jar com.yww.Mainoperation.

reference

Guess you like

Origin www.cnblogs.com/maplesnow/p/11622748.html