1.设置maven
安装包:maven, ideal, java
MAVEN_HOME
D:\ProgramData\apache-maven\apache-maven-3.3.9\
%MAVEN_HOME%\bin;
JAVA_HOME
D:\Program Files\Java\jdk1.8.0_251\
%JAVA_HOME%\bin;
mvn config:
<localRepository>D:\Users\xxx\.m2\repository_aliyun</localRepository>
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
linux:
tar zxvf apache-maven-3.6.1-bin.tar.gz
mv apache-maven-3.6.1-bin /opt/maven/maven
开始配置环境变量,编辑文件/etc/profile
在最下面添加以下内容(MAVEN_HOME是刚才解压maven的路径)
export MAVEN_HOME=/opt/maven/apache-maven-3.6.1
export PATH=$MAVEN_HOME/bin:$PATH
运行source /etc/profile,刷新环境变量
运行mvn –v可以看到maven信息说明安装成功
|
然后编辑/etc/profile 文件,在文件末尾添加
1 2 3 |
|
查看mvn 的库目录:
mvn help:effective-settings
windows查看域名对应的ip:
nslookup
2 java启动进程
public class RunProcess {
public static void Sample() {
String commandList = "ls";
RunProcess.run(commandList);
//exec方法无法执行带 | > 等特殊字符的命令,如 ps -ef | grep java 。此时要把整个命令作为 /bin/sh 的参数执行,如:
try {
List<String> commandArr=new ArrayList<>();
commandArr.add("/bin/sh");
commandArr.add("-c");
commandArr.add("ps -ef | grep java");
run2(commandArr.toArray(new String[commandArr.size()]));
}
catch (IOException e){
e.printStackTrace();
}
}
//
public static boolean run(String cmd)
{
Runtime run = Runtime.getRuntime();
try {
Process process = run.exec(cmd);
// 解析输出
String result = convertStreamToStr(process.getInputStream());
System.out.println(result);
}
catch (IOException e)
{
e.printStackTrace();
}
return true;
}
public static boolean run2(String command) throws IOException {
Scanner input = null;
String result = "";
Process process = null;
Runtime run = Runtime.getRuntime();
try {
process = run.exec(command);
try {
//等待命令执行完成
process.waitFor(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
InputStream is = process.getInputStream();
input = new Scanner(is);
while (input.hasNextLine()) {
result += input.nextLine() + "\n";
}
result = command + "\n" + result; //加上命令本身,打印出来
System.out.println(result);
}
finally {
if (input != null) {
input.close();
}
if (process != null) {
process.destroy();
}
}
return true;
}
//exec方法无法执行带 | > 等特殊字符的命令,如 ps -ef | grep java 。此时要把整个命令作为 /bin/sh 的参数执行,如:
public static String run2(String[] command) throws IOException {
Scanner input = null;
String result = "";
Process process = null;
try {
process = Runtime.getRuntime().exec(command);
try {
//等待命令执行完成
process.waitFor(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
InputStream is = process.getInputStream();
input = new Scanner(is);
while (input.hasNextLine()) {
result += input.nextLine() + "\n";
}
result = command + "\n" + result; //加上命令本身,打印出来
} finally {
if (input != null) {
input.close();
}
if (process != null) {
process.destroy();
}
}
return result;
}
public static String convertStreamToStr(InputStream is) throws IOException {
if (is != null) {
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
is.close();
}
return writer.toString();
} else {
return "";
}
}
}
3. 修改hosts
cd C:\Windows\System32\drivers\etc
vi /etc/hosts
10.212.33.44 test.com