URL编码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
### URL中一些字符的特殊含义,基本编码规则如下:   
1、空格换成加号(+)
2、正斜杠(/)分隔目录和子目录
3、问号(?)分隔URL和查询
4、百分号(%)制定特殊字符
5#号指定书签
6、&号分隔参数

### 如果需要在URL中用到,需要将这些特殊字符换成相应的十六进制的值
+ %20
/ %2F
? %3F
% %25
# %23
& %26
  1. javascript对url进行编码的函数有3个,escape,encodeURI,encodeURIComponent 推荐使用最后一个,因为encodeURIComponent()不编码的字符最少,只有5个

    1
    2
    ~!*()'
    encodeURIComponent和decodeURIComponent 可以成对使用

  2. 对应python

    1
    urllib.quoteurllib.unquote

tomcat">tomcat


request.getParameter(“name”)之前会自动做一次解码的工作,而且URIEncoding是默认的ISO-8859-1

html

1
2
3
表单数据会在未编码的情况下进行发送:
<form action="form_action.asp" enctype="text/plain">
</form>

enctype 规定在发送到服务器之前应该如何对表单数据进行编码:
application/x-www-form-urlencoded 在发送前编码所有字符(默认)

multipart/form-data 不对字符编码。在使用包含文件上传控件的表单时,必须使用该值。

text/plain 空格转换为 “+” 加号,但不对特殊字符编码。

```

termial编译乱码问题:

macos:
在MAC OS X 控制台下使用Javac命令编译java程序时,会出现乱码的情况,现提供一种解决办法:
打开终端( terminal)窗口,点击桌面左上方的终端(terminal)–>偏好设置(preferences)–>设置–>高级–>字符编码–>中文(GBK)
或者
-J-Dfile.encoding=UTF-8
javac -encoding utf-8 -classpath D:\web\xxx\WEB-INF\classes;D:\web\xxx\WEB-INF\lib\struts.jar -d D:\web\xxx\WEB-INF\classes xxx.java

解决mac下maven编译乱码的问题">解决mac下maven编译乱码的问题

在.profile下新增: export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
其他方法, 比如在pom.xml里面的maven-compiler-plugin 增加 utf-8测试不成功
maven:
-Dfile.encoding=UTF-8

开发环境热部署

  1. 用jrebel
1
2
3
4
5
Could you please add -Drebel.log=true -Drebel.log.perf=true
Most of the options are listed in the reference manual http://zeroturnaround.com/reference-manual/agent.html#agent-5.1
-noverify
-javaagent:E:/src/jrebel-3.0-M1/jrebel.jar
-Drebel.dirs=E:\frameWork\strutsWork\SpringMVC2\WebRoot\WEB-INF\classes

However not everything is listed as some of the options can only be used for the specific cases and might do more harm than good to the overly curious user.
原理java agent:

  1. osgi
    1
    Spring itself doesn't tell much about redeployment and stuff, but in most cases you can reload your templates without restarting depending on your ViewResolver.
    Furthermore in some environments (for example in OSGi) it is possible to hot-deploy classes, resources and nearly everything. Having a properly configured SpringSource [Tool Suite](https://spring.io/) and eg. [Virgo](http://www.eclipse.org/virgo/) WebServer it is possible to achieve hot deployment and as such you can reload the running classes as you save them.

生产环境使用切换集群

  1. dcevm

maven配置详解

compile (编译范围)
compile是默认的范围;如果没有提供一个范围,那该依赖的范围就是编译范围。编译范围依赖在所有的classpath 中可用,同时它们也会被打包。

provided (已提供范围)
provided 依赖只有在当JDK 或者一个容器已提供该依赖之后才使用。例如, 如果你开发了一个web 应用,你可能在编译 classpath 中需要可用的Servlet API 来编译一个servlet,但是你不会想要在打包好的WAR 中包含这个Servlet API;这个Servlet API JAR 由你的应用服务器或者servlet 容器提供。已提供范围的依赖在编译classpath (不是运行时)可用。它们不是传递性的,也不会被打包。

runtime (运行时范围)
runtime 依赖在运行和测试系统的时候需要,但在编译的时候不需要。比如,你可能在编译的时候只需要JDBC API JAR,而只有在运行的时候才需要JDBC
驱动实现。
test (测试范围)
test范围依赖 在一般的编译和运行时都不需要,它们只有在测试编译和测试运行阶段可用。

system (系统范围)
system范围依赖与provided 类似,但是你必须显式的提供一个对于本地系统中JAR 文件的路径。这么做是为了允许基于本地对象编译,而这些对象是系统类库的一部分。这样的构件应该是一直可用的,Maven 也不会在仓库中去寻找它。如果你将一个依赖范围设置成系统范围,你必须同时提供一个 systemPath 元素。注意该范围是不推荐使用的(你应该一直尽量去从公共或定制的 Maven 仓库中引用依赖)。

常用mavan命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mvn dependency:sources 					#下载源码jar 或者 dependency里面加<classifer>true</classifer>
mvn dependency:resolve -Dclassifier=javadoc
mvn dependency:sources -DincludeArtifactIds=guava
mvn clean packget -U -f pom.xml -Dmaven.test.skip

安装本地包source :
mvn install:install-file -DgroupId=com.xxx -DartifactId=xxx -Dversion=0.11 -Dpackaging=jar -Dfile=xx.jar -DgeneratePom=true -Dclassifier=sources
-Dclassifier=javadoc
#从源码安装javadoc
mvn clean source:jar install -Dmaven.test.skip=true
# 安装本地包:
mvn install:install-file -Dfile=xxx.jar -DgroupId=com.xxx.xxx -DartifactId=xxx -Dversion=xxx -DcreateChecksum=true -Dpacking=jar -DgeneratePom=true [-Dclassifer=binary]

mvn install:install-file -Dfile=xx.jar -DpomFile=/path/to/java-memcached-2.6.2.pom
mvn eclipse:eclipse引入源码jar, 在
<plugin>
<groupId>org.apache.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>

</configuration>

Maven在仓库中的存储路径 = groupId + artifactId + version + classifier + extension(packaging)

Maven 仓库的分类:

maven的仓库只有两大类:1.本地仓库 2.远程仓库,在远程仓库中又分成了3种:2.1 中央仓库 2.2 私服 2.3 其它公共库 所有的maven项目都会继承超级pom,具体的说,包含了下面配置的pom我们就称之为超级pom
[html] view plaincopy



central
Central Repository
http://repo.maven.apache.org/maven2
default

false



三、远程仓库配置
配置远程仓库将引入新的配置元素:
元素下,可以使用 子元素声明一个或者多个远程仓库。

1
<project>   
  <!-- 配置私服地址 -->  
  <repositories>  
    <repository>  
      <id>nexus</id>  
      <url>http://localhost:8081/nexus/content/groups/public/</url>  
      <snapshots><enabled>true</enabled></snapshots>  
      <releases>
        <updatePolicy>daily</updatePolicy><!-- never,always,interval n -->  
        <enabled>true</enabled>
        <checksumPolicy>warn</checksumPolicy><!-- fail,ignore --> 
      </releases>  
    </repository>  
  </repositories>  
  <pluginRepositories>  
    <pluginRepository>  
      <id>nexus</id>  
      <url>http://localhost:8081/nexus/content/groups/public/</url>  
      <snapshots><enabled>true</enabled></snapshots>  
      <releases><enabled>true</enabled></releases>  
    </pluginRepository>  
  </pluginRepositories>   
<project>  
···

<updatePolicy>元素:表示更新的频率,值有:never, always,interval,daily, daily 为默认值
<checksumPolicy>元素:表示maven检查和检验文件的策略,warn为默认值
认证信息配置在settings.xml中:



same with repository id in pom 这里的id必须与POM中需要认证的repository元素的Id一致
username
pwd


1
将生成的项目部署到远程仓库

<?xml version=”1.0” encoding=”UTF-8” standalone=”no”?>





deployment
deployment
deployment123



mvn release:clean -P release
mvn release:prepare -P release
mvn release:prepare release:perform
mvn clean deploy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

### 正确的看待快照
之前我们在配置pom的时候,对于快照的配置都很谨慎,或者说很少用快照的版本,原因是它还很不稳定,极容易给我们的系统带来未知的错误,让我们很难查找。其实快照版本也并不是一无是处,快照最大的用途是用在开发的过程中,尤其是有模块依赖的时候,比如说AB两个模块同时开发,A依赖于B,开发过程中AB都是持续集成的开发,不断的修改POM文件和构建工程,这时候版本同步就成了一个很大的问题。使用快照就可以达到这一目的。
其实在快照版本在发布的过程中,Maven会自动为构件以当前时间戳做标记,有了这个时间戳,我们就可以随时找到最新的快照版本,这样也就解决刚才说的 协作开发的问题。
至于A如何检查B的更新,刚刚在讲配置的时候说过,快照配置中有一个元素可以控制检查更新的频率------updatePolicy
我们也可以使用命令行加参数的形式强制执行让maven检查更新:
mvn clean install-U

### maven从仓库解析依赖的机制
1. 当依赖的范围是system的时候,Maven直接从本地文件系统解析构件
2. 根据依赖坐标计算仓库路径后,尝试直接从本地仓库寻找构件,如果发现相应构件,则解析成功
3. 在本地仓库不存在相应的构件情况下,如果依赖的版本是显示的发布版本构件,则遍历所有的远程仓库,发现后下载使用
4. 如果依赖的版本是RELEASE或LATEST, 则基于更新策略读取所有远程仓库的元数据,将其于本地仓库的对应元数据合并后,计算出RELEASE或者LATEST的真实值,然后基于这个真实值检查本地仓库
5. 如果依赖的版本是SNAPSHOT, 则基于更新策略读取所有远程仓库的元数据, 将其与本地仓库的对应元数据合并后,得到最新快照版本的值,然后基于该值检查本地仓库或从远程仓库下载
6. 如果最后解析到的构件版本是时间戳格式的快照,则复制其时间戳格式的文件 至 非时间戳格式,并使用该非时间戳格式的构件
注:一定要记得<release> <enabled> & <snapshot> <enabled> ,对于快照也是一样
在POM的依赖声明的时候不推荐使用LATEST & RELEASE, 在Maven3中也不再支持在插件配置中使用LATEST & RELEASE, 如果不设置插件版本,那么最终版本和release一样,
maven只会解析最新的发布版本构建。



### maven plugins:
1. jar plugins






org.apache.maven.plugins
maven-jar-plugin



**/log4j.properties



true
xxxx.testing
dependency-jars/







```

  1. shade plugin:

参考:
http://psy-lob-saw.blogspot.com/2013/01/java-print-assembly.html
http://www.chrisnewland.com/images/jitwatch/HotSpot_Profiling_Using_JITWatch.pdf
https://dzone.com/articles/java-multi-threading-volatile-variables-happens-be-1
http://qifuguang.me/2015/09/02/%5BJava并发包学习七%5D解密ThreadLocal/
https://blog.codecentric.de/en/2014/01/useful-jvm-flags-part-8-gc-logging/
https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
http://psy-lob-saw.blogspot.jp/2013/05/using-jmh-to-benchmark-multi-threaded.html
http://iissnan.com/progit/html/zh/ch9_2.html
https://marklodato.github.io/visual-git-guide/index-zh-cn.html
https://marklodato.github.io/visual-git-guide/index-zh-cn.html
http://www.lxway.com/45419456.htm
http://github.com/javaee-samples/javaee7-simple-sample