/opt/nexus/
目录做为nexus的根目录,把nexus-2.14.5-02-bundle.tar.gz
解压到此目录中/opt/nexus/nexus-2.14.5-02/conf/nexus.properties
文件,把application-port
设置成合适的端口/opt/nexus/nexus-2.14.5-02/bin/jsw/conf/wrapper.conf
文件,配置合适的JVM参数.3.1在文件的最开始添加
#@wjw_add
wrapper.ignore_sequence_gaps=TRUE
3.2添加JVM参数
#->@wjw_add
wrapper.java.additional.11=-Djava.net.preferIPv4Stack=true
wrapper.java.additional.12=-Dcom.sun.jndi.ldap.connect.pool.protocol="plain ssl"
wrapper.java.additional.13=-server
wrapper.java.additional.14=-Xms1g
wrapper.java.additional.15=-Xmx8g
wrapper.java.additional.16=-XX:ReservedCodeCacheSize=96m
#<-@wjw_add
3.3注释掉
#@wjw_note wrapper.java.initmemory=256
#@wjw_note wrapper.java.maxmemory=768
/opt/nexus/nexus-2.14.5-02/bin/nexus
文件,去掉RUN_AS_USER
的注释,改成RUN_AS_USER=root
nexus
,/opt/nexus/nexus-2.14.5-02/bin/nexus start
Gradle
环境Linux:
/opt/GRADLE_USER_HOME
目录/etc/profile
,在最后添加export > GRADLE_USER_HOME=/opt/GRADLE_USER_HOME
source /etc/profile
,是配置环境生效Windows:
打开
系统属性->环境变量->添加用户变量
变量名: GRADLE_USER_HOME
变量值: z:\GRADLE_USER_HOME
Gradle Wrapper
引用本地的发布包Gradle Wrapper 免去了用户在使用 Gradle 进行项目构建时需要安装 Gradle 的繁琐步骤. 每个 Gradle Wrapper 都绑定到一个特定版本的 Gradle,所以当你第一次在给定 Gradle 版本下运行上面的命令之一时,它将下载相应的 Gradle 发布包,并使用它来执行构建.默认,Gradle Wrapper 的发布包是指向的官网的 Web 服务地址,有时候,下载这个发布包比较慢甚至不成功,本文演示了加速下载发布包的方式.
Gradle Wrapper 的配置在gradle/wrapper/gradle-wrapper.properties
, 其默认的配置如下:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
其中,distributionUrl 指 明了 Gradle Wrapper 下载 Gradle 发布包的位置.如果遇到下载这个发布包比较慢甚至不成功的时候,可以将该地址引到本地的文件,比如:
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
distributionUrl=file\:/D:/software/webdev/java/gradle-4.10-all.zip
这样构建的速度将会非常快了.当然,前提是,要实现准本好发布包放到本地.
build.gradle
文件模版buildscript {
repositories {
mavenLocal()
maven{ url "http://SVN:8081/nexus/content/groups/public"}
mavenCentral()
jcenter()
}
}
apply plugin: 'java'
apply plugin: 'groovy' //@wjw_note(for groovy)
apply plugin: 'eclipse'
apply plugin: 'application'
group = 'name.quanke.study.vertx.two'
version = '1.0-SNAPSHOT'
description = """我的第一个Vert.x 3 应用"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
//@wjw_note(for groovy): 采用Java + Groovy的方式,两者分工也很明确:前者用于数据处理,后者则用于DSL和数据类。
//@wjw_note(for groovy): 此时,由于混用了两者,并且可能会出现Groovy与Java互用类的情况,那么就要用到joint compile。在build.gradle中需要配置如下:
sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDirs += ["src/main/java"]
[compileGroovy]*.options*.encoding = 'UTF-8'
repositories {
mavenLocal()
maven{ url "http://SVN:8081/nexus/content/groups/public"}
mavenCentral()
jcenter()
}
def vertxVersion = '3.5.3'
dependencies {
compile "io.vertx:vertx-core:${vertxVersion}"
compile "io.vertx:vertx-lang-groovy:${vertxVersion}" //@wjw_note(for groovy)
compile "org.codehaus.groovy:groovy-all:2.4.10" //@wjw_note(for groovy)
compile 'org.slf4j:slf4j-log4j12:1.7.25'
testCompile group: 'junit', name: 'junit', version:'4.12'
testCompile group: 'io.vertx', name: 'vertx-unit', version:'${vertxVersion}'
}
mainClassName = 'name.quanke.study.vertx.two.Launcher'
def mainVerticleName = 'name.quanke.study.vertx.two.MyMainVerticle'
// Vert.x watches for file changes in all subdirectories
// of src/ but only for files with .java extension
def watchForChange = 'src/**/*'
// Vert.x will call this task on changes
def doOnChange = ".${File.separator}gradlew classes"
/* @wjw_note gradle版本要>=4.9!
gradle run
*/
run {
//@wjw_note设置 applicationDefaultJvmArgs 参数
if(System.getProperty('os.name').toUpperCase().startsWith("WINDOWS")) {
applicationDefaultJvmArgs = ["-Dfile.encoding=GBK","-Duser.timezone=GMT+8","-Duser.language=zh","-Duser.country=CN","-Djava.net.preferIPv4Stack=true"]
} else {
applicationDefaultJvmArgs = ["-Dfile.encoding=UTF-8","-Duser.timezone=GMT+8","-Duser.language=zh","-Duser.country=CN","-Djava.net.preferIPv4Stack=true"]
}
println "applicationDefaultJvmArgs=${applicationDefaultJvmArgs}"
doFirst {
//@wjw_note需要与终端交互的必须设置
setStandardInput System.in
setStandardOutput System.out
setErrorOutput System.err
//@wjw_note debug开关
if (System.getProperty('DEBUG', 'false') == 'true') {
applicationDefaultJvmArgs += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=localhost:9099']
}
//@wjw_note 添加接受JVM命令行参数,例如:-PjvmArgs="-Xms211m -XX:MaxPermSize=211m"
if ( project.hasProperty('jvmArgs') ) {
applicationDefaultJvmArgs += (project.jvmArgs.split("\\s+") as List)
} else {
applicationDefaultJvmArgs += ["-Xms200m","-XX:MaxPermSize=200m"]
}
//@wjw_note debug开关
if (System.getProperty('START', 'false') == 'true') {
def javaOpts=""
applicationDefaultJvmArgs.each { item ->
javaOpts=javaOpts+item+" "
}
args = ["start", mainVerticleName, "--vertx-id=${mainVerticleName}", "--java-opts=${javaOpts}"] //@wjw_note: 后台启动vertx,可以用: vertx stop ${mainVerticleName} 来停止
} else {
args = ["run", mainVerticleName]
//args = ["run", mainVerticleName, "--launcher-class=${mainClassName}", "--redeploy=${watchForChange}", "--on-redeploy=${doOnChange}"] //@wjw_note Enable automatic redeployment
}
println "args=${args}"
}
}
task createWrapper(type: Wrapper) {
gradleVersion = '4.10'
}
project.name
在项目目录下创建settings.gradle
,文件类容是
rootProject.name = 'my-vertx-two-app'
if (!JavaVersion.current().java8Compatible) {
throw new IllegalStateException('''A Haiku:
| This needs Java 8,
| You are using something else,
| Refresh. Try again.'''.stripMargin())
}
.gitignore
文件模版在项目目录下创建.gitignore
,文件类容是
.gradle
/build/
/bin/
/classes/
/config-repo/
!gradle/wrapper/gradle-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
name.quanke.study.vertx.two.MyMainVerticle
package name.quanke.study.vertx.two;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
public class MyMainVerticle extends AbstractVerticle {
//@wjw_note: 至于deployVerticle(),它 可以接受字符串和类实例。当使用字符串时,若是非Java类,如Groovy,需要采用这样的格式:"语言前缀:类全限定名"。如:
@Override
public void start(Future<Void> fut) {
vertx.deployVerticle(MyTwoVerticle.class, new DeploymentOptions(),(AsyncResult<String> e) -> {
if(e.succeeded()) {
System.out.println("部署Verticle成功: "+e.result());
} else {
System.out.println("部署Verticle失败:"+e.cause().getMessage());
}
});
//@wjw_note: 部署Verticle的几种方式
//vertx.deployVerticle(MyGroovyVerticle.class, new DeploymentOptions(),(AsyncResult<String> e) -> {
//vertx.deployVerticle(new MyGroovyVerticle(), (AsyncResult<String> e) -> {
vertx.deployVerticle("name.quanke.study.vertx.two.MyGroovyVerticle", (AsyncResult<String> e) -> {
if(e.succeeded()) {
System.out.println("部署Verticle成功: "+e.result());
} else {
System.out.println("部署Verticle失败:"+e.cause().getMessage());
}
});
}
}
name.quanke.study.vertx.two.MyTwoVerticle
package name.quanke.study.vertx.two;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
public class MyTwoVerticle extends AbstractVerticle {
@Override
public void start(Future<Void> fut) {
vertx
.createHttpServer()
.requestHandler(r -> {
r.response().putHeader("content-type", "text/plain; charset=utf-8");
r.response().end("Hello from my two " +
"Vert.x 3 application(应用)--"+System.currentTimeMillis());
})
.listen(8080, result -> {
if (result.succeeded()) {
fut.complete();
} else {
fut.fail(result.cause());
}
});
}
}
gradlew run
gradlew run -DSTART=true
gradlew run -DDEBUG=true