(在生成的jar中打包所需的库)正在将我的属性文件加载到类路径中,但是(将所需的库提取到生成的jar中)却没有加载它。能否请我知道在提取时将属性文件加载到类路径中的正确方法(将所需的库提取到生成的jar中) 我的项目结构的PFB代码。project structure in STS IDE
public class ExcelReaderWithThread
{
static String timeStamp = new SimpleDateFormat("MM_dd_HH_mm").format(new java.util.Date());
private static String Log_output;
public static void main(String[] args) throws IOException, Exception
{
int i=0,total_row_count=0;
InputStream in = ExcelReaderWithThread.class.getClassLoader().getResourceAsStream("app.properties");
Properties prop = new Properties();
prop.load(in);
prop.getProperty("Source_File");
prop.getProperty("Output_log_path");
prop.getProperty("Threads");
String t=prop.getProperty("Threads");
int threads = Integer.parseInt(t);
ExecutorService executor = Executors.newFixedThreadPool(threads);
String Source_File =prop.getProperty("Source_File");
String Output_path =prop.getProperty("Output_Path");
String Output_fileName =prop.getProperty("Output_FileName");
String log_name_1="output.csv";
String log_name_2="Details.log";
String Log_output_1= Output_path+timeStamp+"_"+log_name_1;
String Log_output_2= Output_path+timeStamp+"_"+log_name_2;
PrintStream logfile_1 = new PrintStream(new File(Log_output_1));
PrintStream logfile_2= new PrintStream(new File(Log_output_2));
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
long startTime = System.currentTimeMillis();
File dir = new File(Source_File);
File[] files = dir.listFiles();
for (File file : files)
{
i++;
Runnable worker= new Writer(file);
executor.execute(worker);
logfile_2.println(file);
System.setOut(logfile_2);
}
executor.shutdown();
long stopTime = System.currentTimeMillis();
System.out.print("Total number of file:"+i);
System.setOut(logfile_1);
}
}
class Writer implements Runnable
{
File source;
public Writer(File source) throws Exception
{
this.source = source;
}
@Override
public void run()
{
try
{
String content = readFromFile(source.getAbsolutePath());
}
catch (Exception e)
{
e.printStackTrace();
}
}
static synchronized String readFromFile(String filename) throws Exception
{
String timeStamp = new SimpleDateFormat("MM_dd_HH_mm").format(new java.util.Date());
String file_name = null;
int nu=0, total_row_count=0,count=0;
StringBuilder sb = new StringBuilder();
StringBuffer content = new StringBuffer();
try
{
Thread t1 = Thread.currentThread();
File file= new File(filename);
file.setWritable(true);
FileInputStream inputStream = new FileInputStream(new File(filename));
Workbook workbook = new XSSFWorkbook(inputStream);
workbook.close();
Sheet sheet = workbook.getSheetAt(0);
nu= sheet.getLastRowNum();
total_row_count += nu;
file_name=file.getName();
sb.append(file_name);
sb.append(',');
sb.append(nu);
sb.append('\n');
System.out.println(file_name+","+nu);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
return content.toString();
}
}