Maven常用参数

1.常用命令参数
进行编译

mvn compile

进行打包

#测试并打包
mvn package
#直接打包,不进行测试
mvn package -DskipTests=true
#打Jar包
mvn jar:jar
#打War包
mvn war:war
#打War包但不执行最后的压缩
mvn war:exploded

进行测试

#编译单元测试
mvn test-compile
#编译并允许单元测试
mvn test

安装到本地repository

mvn install
mvn install -DskipTests=true
mvn install -DskipTests=true --fail-at-end
#安装jar包到本地仓库
mvn install:install-file -DgroupId=groupId -DartifactId=artifactId -Dversion=1.0.0 -Dpackaging=jar -Dfile=xxx.jar

安装到远程repository

mvn deploy

进行清理

mvn clean

生成网站

#生成网站
mvn site
#生成网站并发布
mvn site-deploy

打包源码包

#打包源码
mvn source:jar
#下载项目源码
mvn dependency:sources -DdownloadSources=true -DdownloadJavadocs=true

打包测试源码包

mvn source:test-jar

拷贝依赖到target目录

#拷贝依赖
mvn dependency:copy-dependencies
#依赖分析
mvn dependency:analyze
mvn dependency:tree

生成ecplise项目

mvn eclipse:eclipse

生成ecplise项目

mvn idea:idea

生成文档

#单模块项目生成文档
mvn javadoc:javadoc
#多模块项目生成文档
mvn javadoc:aggregate

创建Jar项目

mvn archetype:create -DgroupId=gourpid -DartifactId=artifactId

创建War项目

mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=gourpid  -DartifactId=artifactId

2.settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"]

<localRepository>X:/Maven/repository</localRepository>

<servers>
<server>
<id>neo-public</id>
<username>username</username>
<password>password</password>
</server>
<server>
<id>neo-releases</id>
<username>username</username>
<password>password</password>
</server>
<server>
<id>neo-snapshots</id>
<username>username</username>
<password>password</password>
</server>
</servers>

<mirrors>
<mirror>
<id>neo-public</id>
<name>Neohope Nexux Public Mirror</name>
<url>http://192.168.xxx.xxx:8081/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>

<profiles>
<profile>
<id>myprofile</id>
<repositories>
<repository>
<id>neo-public</id>
<name>Neohope Nexux Public Mirror</name>
<url>http://192.168.xxx.xxx:8081/nexus/content/groups/public</url>
</repository>
</repositories>
</profile>
</profiles>

<activeProfiles>
<activeProfile>myprofile</activeProfile>
</activeProfiles>

</settings>

3.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>

<groupId>com.neohope.xxx</groupId>
<artifactId>xxx-xxx</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>xxx-xxx</name>
<url>http://neohope.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nexus.url>http://192.168.xxx.xxx:8081</nexus.url>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>neo-releases</id>
<name>Internal Releases</name>
<url>${nexus.url}/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>neo-snapshots</id>
<name>Internal Snapshots</name>
<url>${nexus.url}/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>

Maven Lifecycles

Maven有三大生命周期
default:默认生命周期,用于软件构建
clean:用于项目清理
site:用于生成项目网站

1、default

<phases>
  <phase>validate</phase>
  <phase>initialize</phase>
  <phase>generate-sources</phase>
  <phase>process-sources</phase>
  <phase>generate-resources</phase>
  <phase>process-resources</phase>
  <phase>compile</phase>
  <phase>process-classes</phase>
  <phase>generate-test-sources</phase>
  <phase>process-test-sources</phase>
  <phase>generate-test-resources</phase>
  <phase>process-test-resources</phase>
  <phase>test-compile</phase>
  <phase>process-test-classes</phase>
  <phase>test</phase>
  <phase>prepare-package</phase>
  <phase>package</phase>
  <phase>pre-integration-test</phase>
  <phase>integration-test</phase>
  <phase>post-integration-test</phase>
  <phase>verify</phase>
  <phase>install</phase>
  <phase>deploy</phase>
</phases>

2、clean

<phases>
  <phase>pre-clean</phase>
  <phase>clean</phase>
  <phase>post-clean</phase>
</phases>
<default-phases>
  <clean>
    org.apache.maven.plugins:maven-clean-plugin:2.5:clean
  </clean>
</default-phases>

3、site

<phases>
  <phase>pre-site</phase>
  <phase>site</phase>
  <phase>post-site</phase>
  <phase>site-deploy</phase>
</phases>
<default-phases>
  <site>
    org.apache.maven.plugins:maven-site-plugin:3.3:site
  </site>
  <site-deploy>
    org.apache.maven.plugins:maven-site-plugin:3.3:deploy
  </site-deploy>
</default-phases>

Windows下以兼容模式启动EXE

有两种常用的方式,可以让Windows可以以兼容模式启动EXE程序。

方法1、修改注册表,永久模式(右键-》属性-》兼容模式,也是通过修改注册表达到兼容模式启动EXE的)
A、以WINXPSP3兼容模式,注册表命令行

reg.exe Add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "PATH_TO_EXE" /d "WINXPSP3"

B、以WINXPSP3兼容模式,注册表文件

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"PATH_TO_EXE"="WINXPSP3"

方法2、设置环境变量,单次运行

#注意:__COMPAT_LAYER前面是两个下划线
#两个LayerName之间用空格隔开
#!表示不可以使用该兼容模式
set __COMPAT_LAYER=[!]LayerName1 [LayerName2 ...]

#用WinXPsp3兼容模式启动程序
set __COMPAT_LAYER=WINXPSP3

#用WinXPsp3兼容模式启动程序,并禁用主题
set __COMPAT_LAYER=WINXPSP3 DISABLETHEMES

#以管理员身份、用WinXPsp3兼容模式启动程序,并禁用主题
set __COMPAT_LAYER=WINXPSP3 DISABLETHEMES RUNASADMIN

#禁用兼容模式
set __COMPAT_LAYER=

可用的设置选项有:

LayerName 含义
兼容模式(Compatibility Modes)
WIN95 Windows 95
WIN98 Windows 98
WIN4SP5 Windows NT 4.0 SP5
WIN2000 Windows 2000
WINXPSP2 Windows XP SP2
WINXPSP3 Windows XP SP3
VISTARTM Vista
VISTASP1 Vista SP1
VISTASP2 Vista SP2
WIN7RTM Windows 7
WINSRV03SP1 Windows Server 2003 SP1
WINSRV08SP1 Windows Server 2008 SP1
显示设置(Display Settings)
DISABLETHEMES 禁用主题
640X480 以640×480分辨率进行
HIGHDPIAWARE 高DPI设置时,禁用显示缩放
256COLOR 以256色运行
DISABLEDWM 禁用桌面组合
权限设置(Privilege Level)
RUNASADMIN 管理员权限运行EXE
RUNASINVOKER 以调用者权限运行EXE
RUNASHIGHEST 以用户最高权限运行EXE
Win8
ELEVATECREATEPROCESS 子进程将获取一个UAC提升权限对话框
PINDLL DLL内存常驻
DISABLEUSERCALLBACKEXCEPTION 禁用用户回调异常
VIRTUALIZEDELETE 该模式拦截受保护文件上的删除操作,防止应用由于未处理删除操作中的异常而失败
WRPMITIGATION 当应用尝试写入、修改或删除Windows受保护文件或注册表项时,该模式返回成功(实际上没有完成该操作)
DXMAXIMIZEDWINDOWEDMODE 该模式标识进入全屏模式的应用并指将这些应用重定向到最大化Window模式

Git01常用命令

Git基本没有主次仓库之分,十分适合团队开发;
Git的分支功能比SVN要强悍很多。

1.全局设置

#用户
git config --global user.name "your name" 
#邮箱
git config --global user.email "your email" 
#编辑器
git config --global core.editor "your editor path"

2.新建库
备份,并cd到项目目录

#初始化
git init
#添加文件
#忽略文件列表添加到文本文件.gitignore
git add .
#提交
git commit
#或快速提交
git commit -m "message"

3.提交更新

#添加文件
git add filename
#或添加所有文件
git add .
#提交
git commit -a

4.查看日志

#日志
git log
#详细日志
git log --stat --summary
#显示某一版本日志
git show vidhead
#显示某一版本前一个版本
git show vidhead^
#显示某一版本前4个版本
git show vidhead~4

5.版本恢复

#恢复某个文件
git reset vidhead filelist

6.克隆git库
cd到新的项目路径

git clone source-path

7.合并git库
cd到自己的项目路径

#将别人的库合并到自己的库
git pull source-path
#将自己的库合并到别人的库
git push target-path

8.建立赤裸仓库

git --bare init --shared

9.项目分支

#列出分支
git branch
#新建分支
git branch branchname
#切换分支
git checkout branchname
#合并分支
git merge branchname
#删除分支
git branch -d branchname
#强制删除分支
git branch -D branchname

Windows安装Bugzilla步骤

1.安装mysql
为Bugzilla新建一个Database,
新建用户bugs,为该用户分配Bugzilla的所需权限。

2.安装ActivePerl或StrawberryPerl
新手推荐ActivePerl,StrawberryPerl需要自己做一些配置

3.下载Bugzilla最新版,并解压
在cmd下,执行

    perl checksetup.pl

命令行会提示缺少的包,有可选的和必须的两种。

对于Strawberry你可以按提示安装所有包

    perl install-module.pl --all

也可以只安装必须的包。

对于ActivePerl,只需一条一条的执行安装即可。

   ppm install TimeDate
   ppm install DateTime
   ppm install DateTime-TimeZone
   ppm install Template-Toolkit
   ppm install Email-Send
   ppm install Email-MIME

4.再次运行

    perl checksetup.pl

在Bugzilla目录下会生成localconfig文件,
修改其中的数据库配置,

第三次运行

    perl checksetup.pl

会向你询问一些信息,并自动生成数据库中的表及初始数据

5.下载并安装Apache,修改conf/httpd.conf
将下面一行的注释去掉

    AddHandler cgi-script .cgi

并添加虚拟目录

    Alias /Bugzilla D:/BugZilla
    <Directory "D:/BugZilla"&#93;
        Options ExecCGI All
        AllowOverride All
        ScriptInterpreterSource Registry-Strict 
        Order allow,deny
        Allow from all
    </Directory>

在注册表中配置Perl路径

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.cgi\Shell\ExecCGI\Command]
@="D:\\Perl\\bin\\perl.exe -T"

6.重启Apache,查看http://localhost/Bugzilla
用户名为第5步中输入的邮箱地址

7.如果有问题,用Bugzilla下的脚本可以判断问题所在

    perl testserver.pl  http://127.0.0.1/Bugzilla

VC计算CString摘要

1、VC计算字符串MD5摘要

//输入:要计算摘要的字符串
//输出:128位MD5摘要
#include <wincrypt.h>
CString szResult;

CString CDigestDlg::CalcMD5(CString strContent)
{
  DWORD dwLength=0;
  BYTE* pbContent=NULL;

  dwLength = (DWORD)strContent.GetLength();
  pbContent = new BYTE[dwLength];
  memcpy(pbContent,strContent.GetBuffer(dwLength),dwLength);

  //计算MD5编码
  HCRYPTPROV hCryptProv; 
  HCRYPTHASH hHash; 
  BYTE byteMD5[16]; 
  DWORD dwHashLen=16;
  CString szResult;

  if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) 
  {
    if(CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash)) 
    {
      if(CryptHashData(hHash, pbContent, dwLength, 0))
      {

        if(CryptGetHashParam(hHash, HP_HASHVAL, byteMD5, &dwHashLen, 0)) 
        {
          szResult.Format(TEXT("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"),
            byteMD5[0],byteMD5[1],byteMD5[2],byteMD5[3],byteMD5[4],byteMD5[5],byteMD5[6],byteMD5[7]
            ,byteMD5[8],byteMD5[9],byteMD5[10],byteMD5[11],byteMD5[12],byteMD5[13],byteMD5[14],byteMD5[15]);
        }
        else
        {
          szResult=TEXT("Error getting hash param");
        }

      }
      else
      {
        szResult=TEXT("Error hashing data");
      }
    }
    else
    {
      szResult=TEXT("Error creating hash");
    }
  }
  else
  {
    szResult=TEXT("Error acquiring context");
  }

  CryptDestroyHash(hHash); 
  CryptReleaseContext(hCryptProv, 0); 
  delete[] pbContent;
  pbContent=NULL;

  return szResult;
}

2、VC计算字符串SHA1摘要

//输入:要计算摘要的字符串
//输出:160位SHA1摘要
#include <wincrypt.h>
CString szResult;

CString CDigestDlg::CalcSHA1(CString strContent)
{
  DWORD dwLength=0;
  BYTE* pbContent=NULL;

  dwLength = (DWORD)strContent.GetLength();
  pbContent = new BYTE[dwLength];
  memcpy(pbContent,strContent.GetBuffer(dwLength),dwLength);

  //计算MD5编码
  HCRYPTPROV hCryptProv; 
  HCRYPTHASH hHash; 
  BYTE byteSHA1[20]; 
  DWORD dwHashLen=20;
  CString szResult;

  if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) 
  {
    if(CryptCreateHash(hCryptProv, CALG_SHA1, 0, 0, &hHash)) 
    {
      if(CryptHashData(hHash, pbContent, dwLength, 0))
      {

        if(CryptGetHashParam(hHash, HP_HASHVAL, byteSHA1, &dwHashLen, 0)) 
        {
          szResult.Format(TEXT("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"),
            byteSHA1[0],byteSHA1[1],byteSHA1[2],byteSHA1[3],byteSHA1[4],byteSHA1[5],byteSHA1[6],byteSHA1[7],
            byteSHA1[8],byteSHA1[9],byteSHA1[10],byteSHA1[11],byteSHA1[12],byteSHA1[13],byteSHA1[14],byteSHA1[15],
            byteSHA1[16],byteSHA1[17],byteSHA1[18],byteSHA1[19]);
        }
        else
        {
          szResult=TEXT("Error getting hash param");
        }

      }
      else
      {
        szResult=TEXT("Error hashing data");
      }
    }
    else
    {
      szResult=TEXT("Error creating hash");
    }
  }
  else
  {
    szResult=TEXT("Error acquiring context");
  }

  CryptDestroyHash(hHash); 
  CryptReleaseContext(hCryptProv, 0); 
  delete[] pbContent;
  pbContent=NULL;

  return szResult;
}

VC计算文件摘要

1、VC计算文件MD5摘要

//输入:文件路径
//输出:128位MD5摘要
#include <wincrypt.h>
CString szResult;

CString CMD5AndSHA1Dlg::CalcMD5(CString strFilePath)
{
  //读取文件
  CFile inFile;
  CFileException ex;
  DWORD dwLength=0;
  BYTE* pbContent=NULL;
  BOOL bRet;

  bRet=inFile.Open(strFilePath,CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite,&ex);
  if(bRet==FALSE)
  {
    return TEXT("Error opening file");;
  }

  dwLength = (DWORD)inFile.GetLength();
  pbContent = new BYTE[dwLength];
  if(pbContent==NULL)
  {
    return TEXT("Error not enough memory");;
  }
  inFile.Read(pbContent,dwLength);
  inFile.Close();

  //计算MD5编码
  HCRYPTPROV hCryptProv; 
  HCRYPTHASH hHash; 
  BYTE byteMD5[16]; 
  DWORD dwHashLen=16;
  CString szResult;

  if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) 
  {
    if(CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash)) 
    {
      if(CryptHashData(hHash, pbContent, dwLength, 0))
      {

        if(CryptGetHashParam(hHash, HP_HASHVAL, byteMD5, &dwHashLen, 0)) 
        {
          szResult.Format(TEXT("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"),
            byteMD5[0],byteMD5[1],byteMD5[2],byteMD5[3],byteMD5[4],byteMD5[5],byteMD5[6],byteMD5[7]
            ,byteMD5[8],byteMD5[9],byteMD5[10],byteMD5[11],byteMD5[12],byteMD5[13],byteMD5[14],byteMD5[15]);
        }
        else
        {
          szResult=TEXT("Error getting hash param");
        }

      }
      else
      {
        szResult=TEXT("Error hashing data");
      }
    }
    else
    {
      szResult=TEXT("Error creating hash");
    }
  }
  else
  {
    szResult=TEXT("Error acquiring context");
  }

  CryptDestroyHash(hHash); 
  CryptReleaseContext(hCryptProv, 0); 
  delete[] pbContent;
  pbContent=NULL;

  return szResult;
}

2、VC计算文件SHA1摘要

//输入:文件路径(文件必须小于2^64bit)
//输出:160位SHA1摘要
#include <wincrypt.h>
CString szResult;

CString CMD5AndSHA1Dlg::CalcSHA1(CString strFilePath)
{
  //读取文件
  CFile inFile;
  CFileException ex;
  DWORD dwLength=0;
  BYTE* pbContent=NULL;
  BOOL bRet;

  bRet=inFile.Open(strFilePath,CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite,&ex);
  if(bRet==FALSE)
  {
    return TEXT("Error opening file");;
  }

  dwLength = (DWORD)inFile.GetLength();
  pbContent = new BYTE[dwLength];
  if(pbContent==NULL)
  {
    return TEXT("Error not enough memory");;
  }
  inFile.Read(pbContent,dwLength);
  inFile.Close();

  //计算MD5编码
  HCRYPTPROV hCryptProv; 
  HCRYPTHASH hHash; 
  BYTE byteSHA1[20]; 
  DWORD dwHashLen=20;
  CString szResult;

  if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) 
  {
    if(CryptCreateHash(hCryptProv, CALG_SHA1, 0, 0, &hHash)) 
    {
      if(CryptHashData(hHash, pbContent, dwLength, 0))
      {

        if(CryptGetHashParam(hHash, HP_HASHVAL, byteSHA1, &dwHashLen, 0)) 
        {
          szResult.Format(TEXT("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"),
            byteSHA1[0],byteSHA1[1],byteSHA1[2],byteSHA1[3],byteSHA1[4],byteSHA1[5],byteSHA1[6],byteSHA1[7],
            byteSHA1[8],byteSHA1[9],byteSHA1[10],byteSHA1[11],byteSHA1[12],byteSHA1[13],byteSHA1[14],byteSHA1[15],
            byteSHA1[16],byteSHA1[17],byteSHA1[18],byteSHA1[19]);
        }
        else
        {
          szResult=TEXT("Error getting hash param");
        }

      }
      else
      {
        szResult=TEXT("Error hashing data");
      }
    }
    else
    {
      szResult=TEXT("Error creating hash");
    }
  }
  else
  {
    szResult=TEXT("Error acquiring context");
  }

  CryptDestroyHash(hHash); 
  CryptReleaseContext(hCryptProv, 0); 
  delete[] pbContent;
  pbContent=NULL;

  return szResult;
}