2.8.1. 一个简单实例¶
编译实例:
#!/bin/sh
# 定义常量
PRO_SERVER=<project_name>
PROJECT_PATH=/home/gordon/project #项目路径
JAR_PATH=$PROJECT_PATH/lib #jar包路径
BIN_PATH=$PROJECT_PATH/bin #bin路径
SRC_PATH=$PROJECT_PATH/src/$PRO_SERVER #src路径
# 如果存在sources.list文件,先删除再重新创建
rm -f $SRC_PATH/sources.list
find $SRC_PATH -name *.java > $SRC_PATH/sources.list
# 如果存在bin目录,先删除再重新创建
rm -rf $BIN_PATH/$PRO_SERVER
mkdir $BIN_PATH/$PRO_SERVER
# 编译项目
javac -d $BIN_PATH/$PRO_SERVER -classpath $JAR_PATH/<jar1>.jar:$JAR_PATH/<jar2>.jar @$SRC_PATH/sources.list
运行实例:
#!/bin/sh
# 定义常量
PRO_SERVER=<project_name>
PROJECT_PATH=/home/gordon/project
JAR_PATH=$PROJECT_PATH/lib
BIN_PATH=$PROJECT_PATH/bin
# 使用后台进程运行些项目
nohup java -classpath $BIN_PATH:$JAR_PATH/<jar1>.jar:$JAR_PATH/<jar2>.jar com.<project>.<www> &
最简单实例:
mkdir -p com/xinxi/www
mkdir classes
//编辑文件Hello.java
package com.Javasoft;
public class Hello{
public static void main(String[] args){
System.out.println("Hi ?");
}
}
//编译
javac -d classes com/xinxin/www/Hello.java
//运行
java com.xinxi.www.Hello