Non-web applications
Non-web project, few posts to explain this package and run. (Web projects easily by adding
war
plug-ins andgradle build
packaging)
Run out of the way to try several.
idead directly run
Use idea runs directly main
category can be.
Use plug-ins
Use gradle, you need to build.gradle
file, add the plug-in application
and set good name of the main function mainClassName
. Finally, the project root directory ( build.gradle
execute the command the same directory):
gradle run
Packaged into multiple jar files
Still we need to step on the application
plug-in and mainClassName
configuration, 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.Main
to 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.gradle
configuration are packaged, and does not require plug-ins application
and mainClassName
configurations.
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 thejava -classpath demo.jar com.yww.Main
operation.