一

{"type":"编程笔记"}


  • Home

  • Archives
  • Search

jrebel configuration and usage with maven

Posted on 2018-04-05   |   In java

2018-07-05 开始 myJrebel 不再免费

下面内容针对jrebel仍是一样可以参考。

注册激活 myJRebel

  1. 进入 https://my.jrebel.com/ 网页,按要求登陆并获取激活用的授权 license。
  2. 进入 https://zeroturnaround.com/software/jrebel/download/ 下载JRebel Standalone独立版本,也可以选择 IDE 插件安装。
  3. 根据 https://my.jrebel.com/account/how-to-activate 提示激活myJRebel。

安装 myJRebel

  1. 解压文件到${HOME}/.jrebel目录。
  2. 复制上面得到的 license 并保存为文件:${HOME}/.jrebel/license.key
  3. 根据${HOME}/.jrebel/readme.txt说明,在${HOME}/.jrebel目录下执行以下命令。
 bin/activate.sh license.key2018-04-05 15:56:35 JRebel: Contacting myJRebel server ..JRebel successfully activated!License type:  myJRebelLicensee name: test

配置 myJRebel

简单配置 maven 的全局环境变量MAVEN_OPTS,可以使所有的mvn命令都经过myJRebel代理,在 Mac OSX 的${HOME}/.bash_profile或者是${HOME}/.zshrc中加入以下配置:

export MAVEN_OPTS="-agentpath:$HOME/.jrebel/lib/libjrebel64.dylib"

或者是 Linux 下面的${HOME}/.bashrc或者是${HOME}/.zshrc中加入以下配置:

export MAVEN_OPTS="-agentpath:$HOME/.jrebel/lib/libjrebel64.so"

然后执行 maven 项目的mvn clean操作:

 jrebel clean2018-04-05 16:04:53 JRebel: Contacting myJRebel server ..[INFO] Scanning for projects...[INFO][INFO] ------------------------------------------------------------------------[INFO] Building language-java 0.3.1-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO][INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ language-java ---2018-04-05 16:04:55 JRebel:  Starting logging to file: /Users/test/.jrebel/jrebel.log2018-04-05 16:04:55 JRebel:2018-04-05 16:04:55 JRebel:  #############################################################2018-04-05 16:04:55 JRebel:2018-04-05 16:04:55 JRebel:  JRebel Agent 2018.1.0 (201803221138)2018-04-05 16:04:55 JRebel:  (c) Copyright ZeroTurnaround AS, Estonia, Tartu.2018-04-05 16:04:55 JRebel:2018-04-05 16:04:55 JRebel:  Over the last 1 days JRebel prevented2018-04-05 16:04:55 JRebel:  at least 10 redeploys/restarts saving you about 0.4 hours.2018-04-05 16:04:55 JRebel:2018-04-05 16:04:55 JRebel:  Licensed to test (using myJRebel).2018-04-05 16:04:55 JRebel:2018-04-05 16:04:55 JRebel:2018-04-05 16:04:55 JRebel:  #############################################################2018-04-05 16:04:55 JRebel:[INFO] Deleting /github.com/maven-jrebel/target[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 0.543 s[INFO] Finished at: 2018-04-05T16:04:55+08:00[INFO] Final Memory: 24M/251M[INFO] ------------------------------------------------------------------------
Read more »

spring boot debug using maven

Posted on 2018-04-05   |   In java

初始化本地 git 仓库的脚本

git init --bare spring-boot-debug.gitgit clone spring-boot-debug.gitcd spring-boot-debugmkdir -p src/main/java/com/example/boot/controllermkdir -p src/main/resources### create pom.xml and java files ###touch pom.xmltouch src/main/java/com/example/boot/SpringBootDebugApplication.javatouch src/main/java/com/example/boot/controller/DebugController.javagit add -A :/git commit -am "init spring boot application"git push

spring boot 项目的 pom.xml

<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/xsd/maven-4.0.0.xsd">    <modelVersion>4.0.0</modelVersion>    <parent>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>1.5.9.RELEASE</version>    </parent>    <groupId>com.example.spring</groupId>    <artifactId>spring-boot-debug</artifactId>    <packaging>jar</packaging>    <name>${project.artifactId}</name>    <version>0.0.1-SNAPSHOT</version>    <properties>        <java.version>1.8</java.version>    </properties>    <dependencies>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-test</artifactId>            <scope>test</scope>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-actuator</artifactId>        </dependency>    </dependencies>    <build>        <finalName>${project.artifactId}</finalName>        <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>                <version>${project.parent.version}</version>                <executions>                    <execution>                        <goals>                            <goal>build-info</goal>                            <goal>repackage</goal>                        </goals>                    </execution>                </executions>            </plugin>            <plugin>                <groupId>pl.project13.maven</groupId>                <artifactId>git-commit-id-plugin</artifactId>                <version>2.2.4</version>                <executions>                    <execution>                        <id>get-the-git-infos</id>                        <goals>                            <goal>revision</goal>                        </goals>                    </execution>                </executions>                <configuration>                    <generateGitPropertiesFile>true</generateGitPropertiesFile>                    <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>                </configuration>            </plugin>        </plugins>    </build></project>

spring boot 应用程序 SpringBootDebugApplication

package com.example.boot;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;@SpringBootApplicationpublic class SpringBootDebugApplication {    public static void main(String[] args) {        new SpringApplicationBuilder(SpringBootDebugApplication.class).run(args);    }}

测试的 DebugController

1234567891011121314151617181920212223
package com.example.boot.controller;import javax.servlet.http.HttpServletRequest;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class DebugController {    private static final Logger LOGGER = LoggerFactory.getLogger(DebugController.class);    @RequestMapping("index")    public String index(HttpServletRequest httpServletRequest) {        String host = httpServletRequest.getRemoteHost();        int port = httpServletRequest.getRemotePort();        LOGGER.info("add breakpoint at this line, host is {}, and port is {}", host, port);        return host;    }}
Read more »

nodemon - monitor file change and execute command

Posted on 2018-04-05   |   In linux

项目开发过程中,有时需要监控指定目录的文件变化情况,如果发生变化,则执行指定代码。如 Maven 项目中,src/test/java目录中的测试用例代码更新之后,需要自动执行编译命令:mvn test-compile。

网上查了一下,比较方便的一个工具是基于node的nodemon。

安装 nodemon

 npm install nodemon -g+ nodemon@1.17.3updated 3 packages in 6.45s
Read more »

install node and npm using nvm

Posted on 2018-04-05   |   In linux

在 Mac OSX 上node从0.12.2版本升级到8.10.0之后,执行nodemon时抛出以下错误:

exception in nodemon killing nodeError: Cannot find module 'internal/util/types'    at Function.Module._resolveFilename (module.js:513:15)    at Function.Module._load (module.js:463:25)    at Module.require (module.js:556:17)    at require (internal/module.js:11:18)    at evalmachine.<anonymous>:31:26    at Object.<anonymous> (/usr/local/lib/node_modules/nodemon/node_modules/update-notifier/node_modules/configstore/node_modules/graceful-fs/fs.js:11:1)    at Module._compile (module.js:612:30)    at Object.Module._extensions..js (module.js:623:10)    at Module.load (module.js:531:32)    at tryModuleLoad (module.js:494:12)

网上查了一些资料,最简单的方式就是完全卸载旧版本,并将系统里的node_modules清理干净,再重新安装就可以。

清理旧版本 node

Mac OSX 上不建议使用Homebrew来安装node,将原来安装的所有相关程序和类库全部清理干净,如果不清理这些旧的类库,使用NVM时会碰到如下一些警告信息,因为NVM不支持Homebrew方式安装的node和npm。

nvm is not compatible with the npm config "prefix" option: currently set to "/Users/test/.nvm/versions/node/v0.12.2"
Run nvm use --delete-prefix v8.10.0 to unset it.

 brew uninstall npm brew uninstall node [ -s /usr/local/bin/node ] && rm -f /usr/local/bin/node [ -s /usr/local/bin/npm ] && rm -f /usr/local/bin/npm rm -rf /usr/local/lib/node_modules
Read more »

java generic terminology explanation

Posted on 2018-03-17   |   In java

Java Generic

java泛型是java 1.5版本中增加的最重要特性,虽然在java语法本身上增加了非常高的复杂度,却为开发者带来极大的便利,尤其是在容器相关的使用中。它为代码提供了编译时检查,减少了手动的类型强转,在很大程度上,提高了代码的类型安全。由于java泛型是通过擦除来实现的,对于JVM而言,并不知道泛型的存在,也就是说java泛型实际上是一种java的语法糖,与java的内部类,受检异常,枚举,注解等一样。

Java Generic 相关的术语说明

  1. Type Parameter: 类型参数,泛型类、泛型构造器、泛型方法和泛型接口声明中的类型变量(type variable),如Iterable<T>中的标识符T和List<E>中的标识符E,这个E即是类型参数(type parameter)。
  2. Type Argument: 类型参数,不同于type parameter,在表达式中替换泛型类、泛型构造器、泛型方法和泛型接口中声明的type parameter,可以使用通配符(即?),也可是完全限定标识符,如List<?>和List<java.lang.String>。
  3. Type Variable: 类型变量,是在泛型类、泛型构造器、泛型方法和泛型接口中用作类型的非限定标识符,如<E extends T>中的T,即为类型变量(type variable),类型变量有交集类型,如<T extends C & I>中的C & I,除了交集类型的类型变量,type variable必须是一个非限定标识符,类型变量即可以出现在泛型类和泛型接口的声明中,也可出现在表达式中。
  4. Generic Type: 泛型类型,是通过类型参数化的类或接口。
  5. Raw Type: 原生类型,将参数化类型擦除之后的类型,如将List<String>的类型参数擦除之后,使用余下的原生类型List与遗留系统进行交互,非泛型类和非泛型接口则不是raw type,如String和int。
  6. Parameterized Type: 参数化类型,泛型类或者泛型接口的声明定义了一个参数化类型集,如泛型接口List<E>的参数化类型List<String>,其中List是泛型名,而<String>是表示此泛型的特定参数化形式的类型变量列表。
  7. Generic Class: 泛型类,一个类声明的同时,也声明了一个或者多个类型变量,如ArrayList<E>。
  8. Generic Interface: 泛型接口,与泛型类定义相似,如Comparable<T>和Map<K, V>。
  9. Generic Method: 泛型方法,一个方法为自己引入了类型变量,这些类型变量也就是此方法的类型参数,静态方法和非静态方法都可以声明为泛型方法。
  10. Generic Constructor: 泛型构造器,与泛型方法类似,不管是否是在泛型类中,构造器可以引入自身的类型变量。
  11. Generic and Subtypes: 通过extends和implements泛型类和泛型接口,创建子类型,如List<E> extends Collection<E>,只要不改变类型参数,继承关系就仍然存在,如List<String>就是Collection<String>的子类型,但是List<String>和List<Object>却是二个完全不同的类型,并不存在继承关系,除了共同的父类List<?>和Object。
  12. Bounded Type Parameters: 有界类型参数,限制类型参数在某个指定范围内,如类型参数<E extends Number>,表示类型变量E必须是Number或者其子类型。
  13. Type Inference: 类型推断,JVM在编译期根据方法调用和其类型参数的声明,来推断传入的type arguments是什么类型,从而使方法调用是正确的。
  14. Wildcards: 通配符,在泛型中使用问号?来表示type argument,代表了某个未知类型,通配符不能用在泛型类和泛型接口的声明中。
  15. Upper Bounded Wildcards: 上界通配符,通过上界通配符放宽对类型参数的限制,如方法参数类型List<? extends Number>,使得List<Integer>,List<Double>和List<Number>都可以符合方法的参数要求。
  16. Unbounded Wildcards: 无界通配符,如List<?>,称之为未知类型的List(a list of unknown type)。
  17. Lower Bounded Wildcards: 下界通配符,指定类型参数为某个指定类型的父类,如List<? super Integer>。
  18. Wildcards and Subtyping: List<Integer>和List<Number>这2个参数化类型的除了泛型名都是List之外就并无关系,而带有通配符的参数化类型List<? extends Integer>则是List<? extends Number>的子类型。
  19. Wildcard Capture: 通配符捕获,在某些情况下,编译器会推断通配符的类型。 例如,当评估表达式List<?>时,编译器会从代码中,为?推断出一个特定的类型,并在编译器内部以CAP#1或者capture#1这种形式标示通配符?,这种情况被称为通配符捕获。
  20. Heap Pollution: 堆污染,当参数化类型的变量引用不是该参数类型的对象时,会发生堆污染,如在接受可变长的类型参数时就可能发生堆污染,void faultyMethod(List<String>... list),泛型数组可能发生Heap Pollution。
  21. Recursive Type Bound: 递归式类型绑定,类型参数中的类型变量以递归方式表示,如java.lang.Enum类中的类型参数<E extends Enum<E>>和泛型方法java.util.Collections#min(Collection<? extends T>)中的类型参数<T extends Object & Comparable<? super T>>。
  22. Type Erasure: 类型擦除,Java通过Erasure擦除来实现泛型,这个实现在Java界也是备受质疑,它提供了编译期的类型安全检查,避免了一些类型强转及导致的ClassCastException运行时异常,并且在运行期没有实际产生大量的泛型类,从而减少了运行时的开销。
  23. Reifiable Types: 可具化类型,因为泛型实现是通过类型擦除实现的,因此并非所有类型信息在运行时都可用,在运行时完全可用的类型称为可具化类型reifiable type,如String、Integer、int、int[]和List<?>。
  24. non-Reifiable Types: 相对于reifiable type而言,如List<? extends Number>和List<? extends C & T>就是不可具化类型。
  25. Covariant: 协变,指方法调用的协变返回,当子类重写父类的方法时,放宽了返回类型的限制,可以精细化返回结果,返回原来返回类型的子类型。泛型不是协变的,而数组却是协变的,Integer[]是Number[],List<Integer>却不是List<Number>。
  26. PECS: 从容器的角度来观察其中元素的操作,如果只是从容器中获取元素,容器此时就扮演了生产者Producer的角色,这时候就使用上界通配符<? extends T>;反之只是往容器里放元素进去,而不需要取出来,此时容器相当于一个消费者Consumer,就使用下界通配符<? super T>,为方便记忆,Josh Bloch将之简单归纳在一起作为一个助记符号,就是PECS,也有些人归纳为Get/Put Priciple。如果即要往容器里放元素,同要往外取元素,那就不要使用通配符<T>。
Read more »
1…91011…99
yuweijun

yuweijun

492 posts
12 categories
RSS
GitHub Twitter
© 2021 yuweijun
Powered by Hexo
Theme - NexT.Mist.KISS