批处理 bat文件制作
@echo 1. 配置好环境变量后,运行
@set classpath=%classpath%;.;.\lib\*;
@set PATH=%JAVA_HOME%\bin;%PATH%;
@java -server -Xms256m -Xmx1024m ImportCVE
@if errorlevel 1 (
@echo ----------------------------------------------
@echo ****错误***: 请设置好JAVA_HOME环境变量再运行或者检查你的classpath路径
@pause
)
:end
java文件 (执行main方法)
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
public class ImportCVE {
public static Client getClient() {
return new TransportClient().addTransportAddress(new InetSocketTransportAddress("10.56.4.41", 9300));
}
//创建索引
public void createCVEIndex(String index,String type) throws IOException{
getClient().admin().indices().prepareCreate(index).execute().actionGet();
//索引主事件
XContentBuilder mapping = null;
mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject(type)
// .startObject("settings").startObject("_source")
.startObject("_id").field("path","id").field("store", "yes").field("index", "not_analyzed").endObject()
.startObject("properties")
.startObject("name").field("type", "string").field("store", "no").field("index","not_analyzed").endObject()
.startObject("status").field("type", "string").field("store", "no").field("index","not_analyzed").endObject()
.startObject("description").field("type", "string").field("store", "no").endObject()
.startObject("references").field("type", "string").field("store", "no").endObject()
.startObject("phase").field("type", "string").field("store", "no").endObject()
.startObject("votes").field("type", "string").field("store", "no").endObject()
.startObject("comments").field("type", "string").field("store", "no").endObject()
.endObject()
.endObject()
.endObject();
PutMappingRequest mappingRequest = Requests.putMappingRequest(index).type(type).source(mapping);
getClient().admin().indices().putMapping(mappingRequest).actionGet();
// client.close();
}
public static String getValue(XSSFCell cell){
if(cell==null)
return "";
return cell.getStringCellValue();
}
private void saveToCVEIndex(String index, String type,File file) throws IOException {
InputStream is = new FileInputStream(file);
XSSFWorkbook hssfWorkbook = new XSSFWorkbook(is);
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
XSSFSheet hssfSheet = hssfWorkbook.getSheetAt(0);
XSSFRow hssfRow;
XSSFCell xh;
// 第3个sheet
hssfSheet = hssfWorkbook.getSheetAt(0); // 每天上报数据
System.out.println("总行数"+hssfSheet.getLastRowNum());
// 分两部分, 前半部分 数据转换封装
Client cli= getClient();
BulkRequestBuilder bulkRequest = cli.prepareBulk();
int i = 0;
for (int rowNum = 0; rowNum <=hssfSheet.getLastRowNum(); rowNum++) {
// for (int rowNum = 10; rowNum <= 10000; rowNum++) {
hssfRow = hssfSheet.getRow(rowNum);
/* CommonVulnerabilitiesExposures commonVulnerabilitiesExposures=new CommonVulnerabilitiesExposures();
commonVulnerabilitiesExposures.setName(getValue(hssfRow.getCell(0)));
commonVulnerabilitiesExposures.setStatus(getValue(hssfRow.getCell(1)));
commonVulnerabilitiesExposures.setDescription(getValue(hssfRow.getCell(2)));
commonVulnerabilitiesExposures.setReferences(getValue(hssfRow.getCell(3)));
commonVulnerabilitiesExposures.setPhase(getValue(hssfRow.getCell(4)));
commonVulnerabilitiesExposures.setVotes(getValue(hssfRow.getCell(5)));
commonVulnerabilitiesExposures.setComments(getValue(hssfRow.getCell(6)));*/
Map<String, Object> o = new HashMap<String, Object>();
o.put("name", getValue(hssfRow.getCell(0)));
o.put("status",getValue(hssfRow.getCell(1)));
o.put("description",getValue(hssfRow.getCell(2)));
o.put("references",getValue(hssfRow.getCell(3)));
o.put("phase", getValue(hssfRow.getCell(4)));
o.put("votes", getValue(hssfRow.getCell(5)));
o.put("comments", getValue(hssfRow.getCell(6)));
bulkRequest.add(cli.prepareIndex(index,type)
.setSource(o));
//cli.prepareIndex(index,type).setSource(o).execute();
if(rowNum%1000==0|| rowNum == hssfSheet.getLastRowNum())
{
BulkResponse resp = bulkRequest.execute().actionGet();
System.out.println(rowNum+" "+resp);
cli.close();
cli=getClient();
bulkRequest = cli.prepareBulk();
}
}
}
public void deleteindex(String index){
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(index);
deleteIndexRequest.listenerThreaded(false);
getClient().admin().indices().delete(deleteIndexRequest);
}
public void deletedata(String index, String type){
DeleteResponse response = getClient().prepareDelete(index,type, "AVILx1OATt0HqWzvaooe")
.execute()
.actionGet();
}
public void createCVEIndexShijian(String index,String type) throws IOException{
getClient().admin().indices().prepareCreate(index).execute().actionGet();
//索引主事件
XContentBuilder mapping = null;
mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject(type)
// .startObject("settings").startObject("_source")
.startObject("_id").field("path","id").field("store", "yes").field("index", "not_analyzed").endObject()
.startObject("properties")
.startObject("solution").field("type", "string").field("store", "no").endObject()
.startObject("description").field("type", "string").field("store", "no").endObject()
.startObject("keyword").field("type", "string").field("store", "no").field("index","not_analyzed").endObject()
.startObject("eventname").field("type", "string").field("store", "no").field("index","not_analyzed").endObject()
.endObject()
.endObject()
.endObject();
PutMappingRequest mappingRequest = Requests.putMappingRequest(index).type(type).source(mapping);
getClient().admin().indices().putMapping(mappingRequest).actionGet();
// client.close();
}
public static void main(String[] args) throws IOException {
Scanner s=new Scanner(System.in);
String name=s.next();
System.out.println("开始导入CVE数据");
//修改 es 地址
ImportCVE client = new ImportCVE();
String indexcve="cve";
// String indexeventbase="eventbase17";
//创建索引
//client.createCVEIndex(indexcve, indexcve);
//System.out.println("索引: "+indexcve +"已创建");
//eventbase
//client.createCVEIndexShijian(indexeventbase,indexeventbase);
//System.out.println("索引: "+indexeventbase +"已创建");
//导入数据
String fileName=name+".xlsx";
System.out.println(fileName);
File cvexlsx=new File(fileName);
// cvexlsx.createNewFile();
client.saveToCVEIndex(indexcve,indexcve,cvexlsx);
// client.deleteindex(indexcve);
//
// client.deleteindex(indexeventbase);
// client.createCVEIndex(index, type);
// client.deletedata(index, type);
System.out.println("导入CVE数据结束");
}
}
分享到:
相关推荐
运行时还要到控制台下去使用 java 命令来运行,如果需要直接双击运行必须写 Windows 的批处理文件 (.bat) 或者 Linux 的 Shell 程序。因此,许多人说,Java 是一种方便开发者苦了用户的程序设计语言。
任何时候只要您想编写简单的程序来测试代码或进行其他操作,请使用我制作的这些批处理文件。 它们比打开IDE并输入所有内容进行测试要快得多。 然后,批处理文件“ RunJavaCode”创建一个.class文件(字节码),然后...
里还提供了一个*.cmd文件,该文件是一个批处理文件,运行该文件可以运行 相应的Java程序,例如DatabaseMetaDataTest.java对应的*.cmd文件为 runDatabaseMetaDataTest.cmd。 (4) 光盘根目录下提供了一个“Java...
里还提供了一个*.cmd文件,该文件是一个批处理文件,运行该文件可以运行 相应的Java程序,例如DatabaseMetaDataTest.java对应的*.cmd文件为 runDatabaseMetaDataTest.cmd。 (4) 光盘根目录下提供了一个“Java...
applications和applet,applications可以在控制台直接运行,与其他高级编程语言没有太大区别,而java的特色在于它具有编制小应用程序的功能,applet可以在internet上传输并在兼容java的web浏览器中运行的程序;...
里还提供了一个*.cmd文件,该文件是一个批处理文件,运行该文件可以运行 相应的Java程序,例如DatabaseMetaDataTest.java对应的*.cmd文件为 runDatabaseMetaDataTest.cmd。 (4) 光盘根目录下提供了一个“Java...
本书是第II卷,以开发人员在项目开发中经常遇到的问题和必须掌握的技术为中心,介绍了应用Java进行桌面程序开发各个方面的知识和技巧,主要包括Java语法与面向对象技术、Java高级应用、窗体与控件应用、文件操作...
BAT:批处理文件 BIN:二进制文件 BINHex:苹果的一种编码格式 BMP:Windows或OS/2位图文件 BOOK:Adobe FrameMaker Book文件 BOX:Lotus Notes的邮箱文件 BPL:Borlard Delph 4打包库 BSP:Quake图形文件 ...
用法使用java -jar TicTacToe.jar (或通过下面的“批处理和外壳脚本”部分中提供的脚本)运行代码,并按照屏幕上的说明设置主板尺寸并选择两种播放器模式或AI模式。 注意:如果您选择3x3以上的电路板尺寸,则AI将...
10.9.6 实例的内部运行逻辑 第11章 其他高级功能 11.1 JDBC2.0和JDBC数据库连接池 11.1.1 JDBC2.0新功能概述 11.1.2 结果集增强功能 11.1.3 批处理更新 11.1.4 对Java对象的持久性 11.1.5 数据库连接池使用...
10.9.6 实例的内部运行逻辑 第11章 其他高级功能 11.1 JDBC2.0和JDBC数据库连接池 11.1.1 JDBC2.0新功能概述 11.1.2 结果集增强功能 11.1.3 批处理更新 11.1.4 对Java对象的持久性 11.1.5 数据库连接池使用...
10.9.6 实例的内部运行逻辑 第11章 其他高级功能 11.1 JDBC2.0和JDBC数据库连接池 11.1.1 JDBC2.0新功能概述 11.1.2 结果集增强功能 11.1.3 批处理更新 11.1.4 对Java对象的持久性 11.1.5 数据库连接池使用...
10.9.6 实例的内部运行逻辑 第11章 其他高级功能 11.1 JDBC2.0和JDBC数据库连接池 11.1.1 JDBC2.0新功能概述 11.1.2 结果集增强功能 11.1.3 批处理更新 11.1.4 对Java对象的持久性 11.1.5 数据库连接...
由于我们打包的是javaweb项目,实现的目标是在一台没有javaweb项目运行环境下,可以通过一键安装后执行我们的项目客户机上,那么,我们需要准备如下文件 1、jdk -- 可以直接将你本机下安装好的jdk中拷贝,如 2、...
实现批处理的完全无人值守运行; 注册Exe程序为Windows系统服务; BIOS设置图解教程AMI BIOS.doc; BIOS设置图解教程Award BIOS.doc; CMD设置恢复为中文显示状态.txt; DOS NetWork网络命令.txt; GHOST使用教程....