Answer the question
In order to leave comments, you need to log in
Java Wrapper why network resources are not available?
Hello.
For jar to work as a windows service, I tried to use java wrapper.
The application started up fine.
BUT the application has access to a network folder.
The application returns an error that the network folder does not exist, although it does.
BUT if the application is not run through the wrapper, then everything works.
I tried to run the service from my domain user (if you run it under it, then everything works), the result is negative.
I also tried to connect the ball as a network drive, BUT the result is also negative.
Please help me solve the problem.
Thank you in advance for your help.
Answer the question
In order to leave comments, you need to log in
Decided by changing the logic of working with Samba Linux.
switched to fileToGet and BufferedInputStream/BufferedOutputStream
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", Samba_User, Samba_Password);
// папка откуда забирать
String SambaURL = "smb://" + args[0];
// папка куда копировать
File destinationFolder = new File(args[1]);
File file = new File(args[2]);
System.out.println("Запущено с параметрами.");
System.out.println("Samba с файлами: " + SambaURL);
System.out.println("Локальная папка с файлами для обработки: " + destinationFolder);
System.out.println("Log работы в файл: " + file);
System.out.println("Чтение файлов в папке Samba: " + SambaURL);
// создаем папку если ее нет
if (!destinationFolder.exists()) {
destinationFolder.mkdirs();
}
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS_");
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy");
Date date = new Date();
int StartTime = (int) new Date().getTime();
String StartDateTime = dateFormat.format(date);
SmbFile dir = new SmbFile(SambaURL, auth);
for (SmbFile f : dir.listFiles()) {
try {
child = new File(destinationFolder + "/" + f.getName());
fileToGet = new SmbFile(SambaURL + f.getName(), auth);
fileToGet.connect();
in = new BufferedInputStream(new SmbFileInputStream(fileToGet));
out = new BufferedOutputStream(new FileOutputStream(child));
byte[] buffer = new byte[4096];
int len = 0; //Read length
while ((len = in.read(buffer, 0, buffer.length)) != -1) {
out.write(buffer, 0, len);
}
out.flush(); //The refresh buffer output stream
try {
printlnAppen(file, "[" + StartDateTime + "]: Скопирован файл - " + f.getName() + ".");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} catch (Exception e) {
String msg = "The error occurred: " + e.getLocalizedMessage();
System.out.println(msg);
} finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (Exception e) {
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question