Hello.

For jar to work as a windows service I tried to use java wrapper. The application started normally. The application has access to the network folder. The application returns an error that the network folder does not exist. BUT if the application does not run through the wrapper, then everything works. I tried to start the service from my domain user (if you run 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 solve the problem.

Thank you in advance for your help.

  • one
    Well, at least you put the code with the trace - Senior Pomidor

1 answer 1

I decided by changing the logic of working with Samba Linux.

switched to fileToGet and BufferedInputStream / BufferedOutputStream

             NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication ("", Samba_User, Samba_Password);
             // folder where to pick up
             String SambaURL = "smb: //" + args [0];
             // folder where to copy
             File destinationFolder = new File (args [1]);
             File file = new File (args [2]);

             System.out.println ("Run with parameters.");
             System.out.println ("Samba with files:" + SambaURL);
             System.out.println ("Local folder with files for processing:" + destinationFolder);
             System.out.println ("Log work to file:" + file);
             System.out.println ("Reading files in the Samba folder:" + SambaURL);
             // create a folder if there is none
             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 + "]: Copied file -" + 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) {
                     }
                 }