Copie o código do código da seguinte forma:
importar java.io.File;
importar java.io.FileInputStream;
importar java.io.FileNotFoundException;
importar java.io.FileOutputStream;
importar java.io.IOException;
importar java.io.InputStream;
importar java.util.ArrayList;
importar java.util.List;
importar org.apache.log4j.Logger;
importar org.apache.poi.hssf.usermodel.HSSFCell;
importar org.apache.poi.hssf.usermodel.HSSFrow;
importar org.apache.poi.hssf.usermodel.HSSFSheet;
importar org.apache.poi.hssf.usermodel.HSSFWorkbook;
classe pública DeployByExcel {
Logger estático privado logger = Logger.getLogger (DeployByExcel.class);
final estático int BUFFER = 8192;
//Excel
pasta de trabalho HSSFWorkbook privada;
/**
* Leia o arquivo Excel e coloque a lista de arquivos na lista
* @param sheetNumber
* @param dir O diretório onde o arquivo Excel está localizado
* @retornar
* @throws FileNotFoundException
* @throwsIOException
*/
public List<String> getDatasInSheet(int sheetNumber,File dir) lança FileNotFoundException, IOException{
Arquivo[] arquivos = dir.listFiles();
List<String> resultado = new ArrayList<String>();
para (Arquivo f: arquivos)
{
if(!f.getName().toLowerCase().endsWith(".xls"))
{
continuar;
}
pasta de trabalho = new HSSFWorkbook(new FileInputStream(f));
//Obtém a tabela especificada
Planilha HSSFSheet = workbook.getSheetAt(sheetNumber);
//Obtém o número total de linhas de dados
int rowCount = sheet.getLastRowNum();
logger.info("contagem de linhas do Excel encontradas: " + rowCount);
if (contagem de linhas < 1) {
resultado de retorno;
}
//Lê os dados linha por linha
for (int rowIndex = 4; rowIndex <= rowCount; rowIndex++) {
//Obtém o objeto linha
Linha HSFRow = planilha.getRow(rowIndex);
if (linha! = nulo) {
List<Object> rowData = new ArrayList<Object>();
//Obtém o número de células nesta linha
int colunaCount = row.getLastCellNum();
//Obtém os dados em cada célula desta linha
Célula HSSFCell = row.getCell(1);
//Obtém os dados na célula especificada
String str = (String)this.getCellString(célula);
if (str!=nulo && str.length()>1)
resultado.add(str);
}
}
}
resultado de retorno;
}
cópia void privada (String sourcePath,String destPath,List<String> fileList,String webContent) lança IOException{
int num=1;
for (String str: lista de arquivos){
str = str.replace(".java", ".class");
if (str.indexOf("/")!=-1){
if (str.indexOf("src")==0){
str = str.replace("src", "WEB-INF/classes");
}else if (str.toUpperCase().indexOf(webContent.toUpperCase())==0){
str = str.replace(webContent+"/", "");
}
booleano f = copyFile(str,sourcePath,destPath);
se(f)
{
logger.info("O arquivo é:" + num);
num++;
String nomeArquivo1 = str;
interno n = 1;
while(fileName1.endsWith(".class"))
{
str = fileName1.replace(".class", "$" + n +".class");
if(!copyFile(str,sourcePath,destPath))
{
quebrar;
}
n++;
}
}
}
}
}
/**
* copie str para destPath
*
* @paramstr
* @param sourcePath
* @param caminhodest
* @return boolean isFile return true;else return false;
* @throwsIOException
*/
private boolean copyFile(String str,String sourcePath,String destPath) lança IOException
{
booleano f = falso;
String destFilePath = destPath+str;
String sourceFilePath = sourcePath+str;
Arquivo newDir = new File(destFilePath.substring(0,destFilePath.lastIndexOf('/')));
Arquivo sourceFile = new File(sourceFilePath.trim());
if(!sourceFile.exists())
{
retornar f;
}
logger.info("dest:"+destFilePath+" "+"source:"+sourceFilePath);
Arquivo destFile = new File(destFilePath.trim());
if (!newDir.exists()){
novoDir.mkdirs();
}
if(!sourceFile.isDirectory())
{
InputStream in=new FileInputStream(sourceFile);
FileOutputStream out=new FileOutputStream(destFile);
byte[] buffer=novo byte[1024];
int ins;
enquanto((ins=in.read(buffer))!=-1){
out.write(buffer,0,ins);
}
in.close();
fora.flush();
out.close();
f = verdadeiro;
}
retornar f;
}
/**
* Obtenha o conteúdo da célula
* @param célula
* @retornar
*/
objeto protegido getCellString(célula HSSFCell){
Resultado do objeto = null;
if (célula! = nulo) {
int cellType = cell.getCellType();
switch(cellType){
caso HSSFCell.CELL_TYPE_STRING:
resultado = cell.getRichStringCellValue().getString();
quebrar;
caso HSSFCell.CELL_TYPE_NUMERIC:
resultado=cell.getNumericCellValue();
quebrar;
caso HSSFCell.CELL_TYPE_FORMULA:
resultado = cell.getNumericCellValue();
quebrar;
caso HSSFCell.CELL_TYPE_ERROR:
resultado=nulo;
quebrar;
caso HSSFCell.CELL_TYPE_BOOLEAN:
resultado=cell.getBooleanCellValue();
quebrar;
caso HSSFCell.CELL_TYPE_BLANK:
resultado=nulo;
quebrar;
}
}
resultado de retorno;
}
/**
*
* @param args args[0]: diretório onde está localizado o arquivo Excel args[1]: diretório de origem (diretório do arquivo compilado args[2]: diretório de liberação);
* @throwsException
*/
public static void main(String[] args) lança exceção {
if(args == null || args.length <3 )
{
logger.info("arquivo não encontrado;");
logger.fatal("java cn.id5.deploy.DeployByExcel $0 $1 $2 $3 /n$0: diretório onde o arquivo Excel está localizado; $1: diretório de origem (diretório de arquivo compilado); $2: diretório de lançamento; $3: diretório onde jsp está localizado (o padrão é webContent, pode estar vazio)/nexiting.");
Sistema.exit(0);
}
Arquivo arquivo = new Arquivo(args[0]);
DeployByExcel implantar = novo DeployByExcel();
List<String> fileList = deploy.getDatasInSheet(0,arquivo);
String classPath = args[1];
String caminhodest = args[2];
String webContent = (args.length> 3 && args[3] != null && args[3].length() > 1) ?
implantar.copy (classPath, destPath, fileList, webContent);
///tmp/gboss /media/terry/doc/Project_ID5/gboss/WebContent/
}
}