一

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


  • Home

  • Archives
  • Search

maven resources inheritance problem

Posted on 2016-06-09   |   In java

如果maven项目中父项目pom.xml里的build > resources项有配置,而子项目pom.xml中的build > resources没有配置时,则子项目直接继承父项目的配置内容。

如果子项目中有配置build > resources,则会覆盖父项目中的全部配置,即父项目中pom.xml中关于build > resources的配置就无效了,不会再被子项目继承,这不同于dependencies > dependence和build > plugins > plugin,这二个会完整的继承父项目的设置,并且会覆盖相同的配置,合并不同的配置。

所以maven官方JIRA中很多人认为这是一个bug,因为这与继承的直观印象相左,很容易误用,不过这个问题并没有被进一步修正过,状态为CLOSED。

以下就采用stackoverflow.com上用户的提问来简单说明一下:

Example

项目结构如下:

parent-pom.xml

└── child-pom.xml

parent-pom.xml

Read more »

application connections configuration using hosts

Posted on 2016-06-01   |   In linux

应用程序需要连接到其他服务器时,程序中就需要配置相应的连接信息,比如是mysql服务器,如果直接使用ip的话,发生变动就需要更新重启所有相关的应用,所以建议使用域名或者是主机别名来代替ip,并且使用相同的配置文件,就可以同时适用开发环境和生产环境。

Read more »

git log查看版本历史

Posted on 2016-05-31   |   In linux

以下脚本用于生成多分支的git log,通过git log --oneline --decorate --graph --all查看分支提交及合并示意图。

git config --global alias.co checkoutgit config --global alias.br branchgit config --global alias.ci commitgit config --global alias.st status[ -a git-branch-test.git ] && rm -rf git-branch-test.git[ -a git-branch-logs ] && rm -rf git-branch-logsgit init --bare git-branch-test.gitgit clone git-branch-test.git git-branch-logscd git-branch-logsecho v1 > v1.txtgit add -Agit commit -m v1-mastersleep 2sgit checkout -b br1git branchecho v2 > v2.txtgit add -Agit commit -m v2-br1sleep 2sgit branchgit checkout -b br2echo v3 > v3.txtgit commit -m v3-br2sleep 2sgit add -Agit commit -m v3-br2sleep 2sgit checkout -b br3echo v4 > v4.txtgit add v4.txtgit commit -m v4-br3sleep 2sgit checkout mastergit merge br3 -m "merge br3 into master"git checkout br3echo v5 > v5.txtgit add -Agit commit -m v5-br3sleep 2sgit checkout masterecho v6 > v6.txtgit add -Agit commit -m v6-mastersleep 2sgit checkout br1echo v7 > v7.txtgit add -Agit commit -m v7-br1sleep 2sgit checkout masterecho v8 > v8.txtgit add -Agit commit -m v8-mastersleep 2secho v9 > v9.txtgit add -Agit commit -m v9-mastersleep 2sgit checkout br2echo v10 > v10.txtgit add -Agit commit -m v10-br2sleep 2secho v11 > v11.txtgit add -Agit commit -m v11-br2sleep 2secho v12 > v12.txtgit add -Agit commit -m v12-br2sleep 2sgit checkout br3echo v13 > v13.txtgit add -Agit commit -m v13-br3sleep 2sgit checkout br1echo v14 > v14.txtgit add -Agit commit -m v14-br1sleep 2secho v15 > v15.txtgit add -Agit commit -m v15-br1sleep 2sgit checkout mastergit merge br3 -m "merge br3 into master"git merge br1 -m "merge br1 into master"git merge br2 -m "merge br2 into master"git log --oneline --decorate --graph --all
Read more »

java 命令行工具之 keytool篇

Posted on 2016-05-31   |   In java

以下http client 4.5版本实现https请求的例子,实际运行过程中会碰到一些问题。

Https Client example

package org.apache.http.examples.client;import java.io.File;import javax.net.ssl.SSLContext;import org.apache.http.HttpEntity;import org.apache.http.client.methods.CloseableHttpResponse;import org.apache.http.client.methods.HttpGet;import org.apache.http.conn.ssl.SSLConnectionSocketFactory;import org.apache.http.conn.ssl.TrustSelfSignedStrategy;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClients;import org.apache.http.ssl.SSLContexts;import org.apache.http.util.EntityUtils;/** * This example demonstrates how to create secure connections with a custom SSL context. */public class ClientCustomSSL {    public final static void main(String[] args) throws Exception {        // Trust own CA and all self-signed certs        SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new File("my.keystore"), "changeit".toCharArray(), new TrustSelfSignedStrategy()).build();        // Allow TLSv1 protocol only        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier());        CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();        try {            HttpGet httpget = new HttpGet("https://httpbin.org/");            System.out.println("Executing request " + httpget.getRequestLine());            CloseableHttpResponse response = httpclient.execute(httpget);            try {                HttpEntity entity = response.getEntity();                System.out.println("----------------------------------------");                System.out.println(response.getStatusLine());                EntityUtils.consume(entity);            } finally {                response.close();            }        } finally {            httpclient.close();        }    }}

以上httpclient 4.5版本自带的示例https request运行时,访问https://httpbin.org/后抛出如下错误:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

解决方案

需要在浏览器中将对应的https://httpbin.org/请求域名的CA证书从浏览器里导出另存为httpbin.org.cer,然后用keytool命令导入到上述java代码指定的my.keystore文件中,my.keystore文件是一个包含公钥的truststore文件。

 keytool -import -trustcacerts -alias httpbin.org -file httpbin.org.cer -keystore my.keystore -storepass changeit

以上代码中的my.keystore文件是使用java自带的工具keytool生成的,另外需要注意的是这里生成的这份my.keystore文件,只能运行https://httpbin.org的请求,而不能运行其他如https://www.google.com的HTTPS请求。

下面介绍一下这个工具其及使用方法。

Read more »

git remote error receive.denycurrentbranch

Posted on 2016-04-14   |   In linux

在线上服务器已经有文件的目录里通过以下操作:

 git init git add -A git commit -m "create git repository by existing files"

初始化了一个git仓库,并将目录下面的文件全部加入仓库版本管理库中,然后远程切出此仓库,并修改内容后,通过git push命令上传到线上服务器时,报了以下错误:

Read more »
1…212223…99
yuweijun

yuweijun

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