当前位置: 代码迷 >> Web前端 >> 封装war
  详细解决方案

封装war

热度:559   发布时间:2012-11-01 11:11:33.0
打包war
假定有一个Web应用:C:\myHome
myHome/WEB-INF/……
myHome/files/……
myHome/image/……
myHome/src/……
myHome/index.jsp
在命令行窗口下执行如下命令:
C:\>cd myHome
C:\myHome\>jar   cvf   myhome.war   */ .
解释:jar   cvf   [A=》 war包名 ].war   [B=》 资源文件及文件夹 ]   [C=》 将要生成war包的目标文件夹 ]
“*/”(B=》)代表当前目录(C:\myHome)下的所有文件及文件夹。
“.” (C=》)表明将要在当前目录中生成war包。

操作完成后,找到C:\myHome下新生成的myhome.war,将其拷入TOMCAT_HOME/webapps/下。然后启动Tomcat即可。

编辑URL


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception{
URL url = new URL("http://www.gdlottery.cn/lot11x5.do?method=to11x5kjggzst");
URLConnection urlCon = url.openConnection();
HttpURLConnection httpCon = (HttpURLConnection) urlCon;
Properties prop = System.getProperties();
// 设置http访问要使用的代理服务器的地址
prop.setProperty("http.proxyHost", "10.17.171.10");
// 设置http访问要使用的代理服务器的端口
prop.setProperty("http.proxyPort", "8080");
// 用户名密码
//prop.setProperty("http.proxyUser", "www");
//prop.setProperty("http.proxyPassword","www");
httpCon.setDoOutput(true);
httpCon.setDoInput(true);
httpCon.setUseCaches(false);
httpCon.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(httpCon.getInputStream(), "GBK"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
String data = sb.toString();
Pattern pattern = Pattern.compile("<strong>[\\d\\s,]*</strong>");
Matcher matcher = pattern.matcher(data);
List<String[]> matcherData = new ArrayList<String[]>();
String[] ballNo = null;
int i = 1;
while (matcher.find()) {
ballNo = matcher.group().replace("<strong>", "").replace("</strong>", "").trim().split(",");
System.out.println(i++ + "--->" + Arrays.toString(ballNo));
matcherData.add(ballNo);
}
reader.close();
httpCon.disconnect();
}

}

/****************************************/

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class MainControl {
private static Set<String[]> dataSet = new LinkedHashSet<String[]>();
private static List<String[]> dataList = new ArrayList<String[]>();
private static List<String[]> filterList = new ArrayList<String[]>();
private static List<String[]> filterArrLs = new ArrayList<String[]>();

private static String[] ballArr = null;
private static int numArr = 5;
private static final int MAX_NUM = 11;

private static int tenToTwenty;
private static int twentyToThirty;
private static int thirtyToFourty;
private static int fourtyToFifty;

public static void main(String[] args) {
init();
initFilter();
filterAll();
filterLinkGreatThree(false);
}

private static void filterLinkGreatThree(boolean isRound) {
int tmpNum = 0;
String[] tmpArr = null;
int index=0;
for (String[] dataArr : dataList) {
index++;
filterList.clear();
for (String dataStr : dataArr) {
tmpNum = Integer.parseInt(dataStr);
if (tmpNum >= 10) {
if (isRound) {
if (tmpNum == 10) {
tmpArr = new String[] {"01","11"};
} else if (tmpNum == 11) {
tmpArr = new String[] {"01","02"};
}
} else {
continue;
}
} else {
tmpArr = new String[] {convertStr(tmpNum + 1), convertStr(tmpNum + 2)};
}
filterList.add(tmpArr);
}
for (String[] filterArr : filterList) {
if (containAll(dataArr, filterArr)) {
filterArrLs.add(dataArr);
}
}
}
dataList.removeAll(filterArrLs);
int i = 1;
for (String[] dataArr : dataList) {
totalArr(dataArr);
System.out.println(i++ + ":  " + Arrays.toString(dataArr));
}
System.out.println("10多:" + tenToTwenty);
System.out.println("20多:" + twentyToThirty);
System.out.println("30多:" + thirtyToFourty);
System.out.println("40多:" + fourtyToFifty);
}

private static void totalArr(String[] strArr) {
int sumArr = 0;
for (String str : strArr) {
sumArr += Integer.parseInt(str);
}
switch (sumArr/10) {
case 1:
tenToTwenty++;
break;
case 2:
twentyToThirty++;
break;
case 3:
thirtyToFourty++;
break;
case 4:
fourtyToFifty++;
break;
}
}

private static String convertStr(int num) {
if (num <= 9) {
return "0" + num;
}
return "" + num;
}

private static void initFilter() {
String[] filterArr = null;
//任一
filterArr = new String[] {"11"};
filterList.add(filterArr);
//任二
filterArr = new String[] {"02","11"};
filterList.add(filterArr);
filterArr = new String[] {"05","10"};
filterList.add(filterArr);
filterArr = new String[] {"04","05"};
filterList.add(filterArr);
//任三
filterArr = new String[] {"02","08","11"};
filterList.add(filterArr);
filterArr = new String[] {"05","09","10"};
filterList.add(filterArr);
filterArr = new String[] {"01","05","06"};
filterList.add(filterArr);
//任四
filterArr = new String[] {"04","05","08","09"};
filterList.add(filterArr);
filterArr = new String[] {"01","02","04","11"};
filterList.add(filterArr);
filterArr = new String[] {"02","03","04","05"};
filterList.add(filterArr);
//任五
filterArr = new String[] {"01","02","04","10","11"};
filterList.add(filterArr);
filterArr = new String[] {"02","04","05","10","11"};
filterList.add(filterArr);
filterArr = new String[] {"01","05","08","10","11"};
filterList.add(filterArr);
//任六
filterArr = new String[] {"01","03","04","07","08","09"};
filterList.add(filterArr);
filterArr = new String[] {"02","03","04","05","09","10"};
filterList.add(filterArr);
filterArr = new String[] {"01","03","05","08","10","11"};
filterList.add(filterArr);
//任七
filterArr = new String[] {"01","02","04","05","06","07","08"};
filterList.add(filterArr);
filterArr = new String[] {"02","03","04","05","06","08","11"};
filterList.add(filterArr);
filterArr = new String[] {"02","03","04","06","08","09","11"};
filterList.add(filterArr);
//任八
filterArr = new String[] {"01","02","04","05","07","09","10","11"};
filterList.add(filterArr);
filterArr = new String[] {"01","02","03","05","06","07","09","11"};
filterList.add(filterArr);
filterArr = new String[] {"01","02","04","05","06","07","08","11"};
filterList.add(filterArr);
}

private static int combination(int m) {
return factorial(MAX_NUM)/factorial(m)/factorial(MAX_NUM-m);
}

private static int factorial(int n) {
if (n == 1)
return 1;
return n * factorial(n-1);
}

private static void filterAll() {
for (String[] dataArr : dataSet) {
boolean state = true;
for (String[] filterArr : filterList) {
int lenA = dataArr.length;
int lenB = filterArr.length;
if (lenA > lenB) {
if (containAll(dataArr, filterArr)) {
state = false;
break;
}
} else {
if (containAll(filterArr, dataArr)) {
state = false;
break;
}
}
}
if (state) {
dataList.add(dataArr);
}
}
}

private static boolean containAll(String[] arrayA, String[] arrayB) {
List<String> setA = Arrays.asList(arrayA);
Collections.sort(setA);
List<String> setB = Arrays.asList(arrayB);
Collections.sort(setB);
return setA.containsAll(setB);
}

private static void init() {
while(dataSet.size() < combination(numArr)) {
ballArr = obtainArr(numArr);
autoElement();
}
}

private static String[] obtainArr(int numArr) {
List<String> strCopy = new ArrayList<String>();
for (int i = 1; i <= 11; i++) {
strCopy.add(convertStr(i));
}
int random = 0;
for (int i = 0; i < 11 - numArr; i++) {
random = (int)(Math.random() * strCopy.size());
strCopy.remove(random);
}
return strCopy.toArray(new String[numArr]);
}

private static void autoElement() {
sort();
if (dataSet.size() == 0) {
dataSet.add(ballArr);
return;
}
for (String[] tempArr : dataSet) {
if (equal(ballArr, tempArr)) {
return;
}
}
dataSet.add(ballArr);
}

private static boolean equal(String[] arrA, String[] arrB) {
for (int i = 0; i < arrA.length; i++) {
if (!arrA[i].equals(arrB[i])) {
return false;
}
}
return true;
}

private static void sort() {
String tmpBall = null;
int len = ballArr.length;
for (int i = 0; i < len; i++) {
for (int j = 0; j < len - i - 1; j++) {
if (Integer.parseInt(ballArr[j]) > Integer.parseInt(ballArr[j+1])) {
tmpBall = ballArr[j];
ballArr[j] = ballArr[j+1];
ballArr[j+1] = tmpBall;
}
}
}
}
}


  相关解决方案