C:\\Gradle (Windows) or /opt/gradle/gradle-4.1 (Linux).bin directory in the unzipped directory to the system environment variable PATH in the following way as appropriate:export PATH=$PATH:/opt/gradle/gradle-4.1/bin.Path variable, click Edit, and add ;C:\\Gradle\\bin; at the end of the variable value.gradle -v
------------------------------------------------------------Gradle 4.1------------------------------------------------------------Build time: 2017-08-07 14:38:48 UTCRevision: 941559e020f6c357ebb08d5c67acdb858a3defc2Groovy: 2.4.11Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015JVM: 1.8.0_144 (Oracle Corporation 25.144-b01)OS: Windows 7 6.1 amd64
scf_example.src/main/java/ as the directory where the package is stored.example package directory in the created directory and then create a Hello.java file in the package directory. The final directory structure is formed as follows:scf_example/src/main/java/example/Hello.java
Hello.java file:package example;public class Hello {public String mainHandler(String name, Context context) {System.out.println("Hello world!");return String.format("Hello %s.", name);}}
build.gradle file in the root directory of the project folder and enter the following content:apply plugin: 'java'task buildZip(type: Zip) {from compileJavafrom processResourcesinto('lib') {from configurations.runtime}}build.dependsOn buildZip
build.gradle file is as follows:apply plugin: 'java'repositories {mavenCentral()}dependencies {compile ('com.tencentcloudapi:scf-java-events:0.0.2')}task buildZip(type: Zip) {from compileJavafrom processResourcesinto('lib') {from configurations.runtime}}build.dependsOn buildZip
repositories is used to indicate that the dependent library source is mavenCentral, Gradle will pull the dependencies from Maven Central during compilation, i.e., the com.tencentcloudapi:scf-java-events:0.0.2 package specified in dependencies.jars directory in the root directory of the project folder and place the downloaded dependent Jar package into it. The content of the build.gradle file is as follows:apply plugin: 'java'dependencies {compile fileTree(dir: 'jars', include: '*.jar')}task buildZip(type: Zip) {from compileJavafrom processResourcesinto('lib') {from configurations.runtime}}build.dependsOn buildZip
dependencies is used to indicate that the search directory is the *.jar file in the jars directory, the dependencies will be automatically searched for during compilation.gradle build in the root directory of the project folder, and the compilation output should be like the example below:Starting a Gradle Daemon (subsequent builds will be faster)BUILD SUCCESSFUL in 5s3 actionable tasks: 3 executed
/build/distributions directory of the project folder and named scf_example.zip after the project folder.C:\\Maven (Windows) or /opt/mvn/apache-maven-3.5.0 (Linux).bin directory in the unzipped directory to the system environment variable PATH in the following way as appropriate:export PATH=$PATH:/opt/mvn/apache-maven-3.5.0/bin.Path variable, click Edit, and add ;C:\\Maven\\bin; at the end of the variable value.mvn -v
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)Maven home: C:\\Program Files\\Java\\apache-maven-3.5.0\\bin\\..Java version: 1.8.0_144, vendor: Oracle CorporationJava home: C:\\Program Files\\Java\\jdk1.8.0_144\\jreDefault locale: zh_CN, platform encoding: GBKOS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
scf_example.src/main/java/ as the directory where the package is stored.example package directory in the created directory and then create a Hello.java file in the package directory. The final directory structure is formed as follows:scf_example/src/main/java/example/Hello.java
Hello.java file:package example;public class Hello {public String mainHandler(String name, Context context) {System.out.println("Hello world!");return String.format("Hello %s.", name);}}
pom.xml file in the root directory of the project folder and enter the following content:<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>examples</groupId><artifactId>java-example</artifactId><packaging>jar</packaging><version>1.0-SNAPSHOT</version><name>java-example</name><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>2.3</version><configuration><source>11</source><target>11</target></configuration><executions><execution><phase>package</phase><goals><goal>shade</goal></goals></execution></executions></plugin></plugins></build></project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>examples</groupId><artifactId>java-example</artifactId><packaging>jar</packaging><version>1.0-SNAPSHOT</version><name>java-example</name><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>2.3</version><configuration><createDependencyReducedPom>false</createDependencyReducedPom></configuration><executions><execution><phase>package</phase><goals><goal>shade</goal></goals></execution></executions></plugin></plugins></build></project>
pom.xml file is as follows. To add dependencies, pay attention to the <dependencies> section.<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>examples</groupId><artifactId>java-example</artifactId><packaging>jar</packaging><version>1.0-SNAPSHOT</version><name>java-example</name><dependencies><dependency><groupId>com.tencentcloudapi</groupId><artifactId>scf-java-events</artifactId><version>0.0.2</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>2.3</version><configuration><createDependencyReducedPom>false</createDependencyReducedPom></configuration><executions><execution><phase>package</phase><goals><goal>shade</goal></goals></execution></executions></plugin></plugins></build></project>
mvn package in the root directory of the project folder, and the compilation output should be like the example below:[INFO] Scanning for projects...[INFO][INFO] ------------------------------------------------------------------------[INFO] Building java-example 1.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO]...[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 1.785 s[INFO] Finished at: 2017-08-25T10:53:54+08:00[INFO] Final Memory: 17M/214M[INFO] ------------------------------------------------------------------------
target directory of the project folder and named java-example-1.0-SNAPSHOT.jar after the artifactId and version fields in pom.xml.Feedback