Program.jar created does not run!

I made the following program in java to automatically exchange a file in a computer directory:

public static void main(String[] args) throws IOException {

        if (!new File("C:\\ProgramData\\Microsoft\\Network\\Connections\\Pbk").exists()) {
            new File("C:\\ProgramData\\Microsoft\\Network\\Connections\\Pbk").mkdirs();
        } else {

        }

File r = new File("C:\\Users\\ALMIRANTE\\Desktop\\rasphone.pbk");
File d = new File("C:\\ProgramData\\Microsoft\\Network\\Connections\\Pbk\\ra
sphone.pbk");

        if (d.exists())
        d.delete();

        FileChannel rChannel = null;
        FileChannel dChannel = null;


        try {
            rChannel = new FileInputStream(r).getChannel();
            dChannel = new FileOutputStream(d).getChannel();
            rChannel.transferTo(0, rChannel.size(),
            dChannel); //System.out.println("ok");

       } finally {
            if (rChannel != null && rChannel.isOpen())
            rChannel.close();
            if (dChannel != null && dChannel.isOpen())
            dChannel.close();//System.out.println("ok");
       }
 }


}

Worked properly by Netbeans. But when building it, go to the folder "dist " and click on the file .generated jar, nothing occurs, that is, the program does not do what it should do. Only a black screen of windows itself opens and closes quickly.

From my research I saw that it could be something related to the main class, especially that the same certainly would not be defined. However, I have already defined the class, which is: rasphonefile.RasphoneFile .

When going into cmd and putting java-jar RasphoneFile.jar, the following error occurs:

Unable to access jar file RasphoneFile.jar

When executing, also at the command prompt, the Code java TFV RasphoneFile.jar, which tests the contents of the file, it is stated that could not locate nor Load Master Class.

Does anyone know what the possible causes of this? Thank you!!!!!!

Author: A. Silva, 2019-09-29

1 answers

I did the whole process in .bat: much simpler and more functional, since the systems themselves already have the support to read this type of file.

Https://www.devmedia.com.br/introducao-a-arquivos-bat-e-programacao-em-lotes/24800

Follows the Code:

@echo off
xcopy  "%userprofile%\Desktop\ARQUIVOS\arquivo.pdf" "C:\ProgramData\Adobe\" /y 
exit

@echo off allows no command lines to be displayed on the screen.

Xcopy : is a command that copies files and directories, including subdirectories.

"%userprofile% \ Desktop \ files\file.pdf " : is the path of the source file, which I wanted to copy. The part "%userprofile% " of it, serves to be able to run the program on any computer, since if I created it using the default path of the John machine: "c:\users\Joao\Desktop\arquivo.txt " , and I would run on Mary's machine, whose user is Mary, it would not work, because the way could be: ' c:\users\Maria\Desktop\arquivo.txt " . With this generic code, it works with any name, because it already searches for the specific user of the machine.

"C:\ProgramData\Adobe\" : is the destination directory, i.e. where I want to save that file. Note that the last folder, the "Adobe", has a \ at the end, to indicate that it is a directory. If you put only Adobe , it could give error.

/y : xcopy has several parameters. One of them is /Y, which blocks the batch permission request to overwrite the existing Target file. They have / and , which copies all directories, even if they are empty, /T, which copies only directories (with or without files, and in the latter case you should use /and next to it).

Exit : just to close the screen!

Follows parameter link and more information, as well as other commands in batch (.bat).

Https://docs.microsoft.com/pt-br/windows-server/administration/windows-commands/xcopy

To create a file.bat, just open Notepad, make the code and save as .bat. If you need to edit it, right-click it and go to edit.

Follows one more .bat I did. Through it I imported a task without having to open the scheduler (which takes a long time).

Follows the Code:

@echo off
schtasks.exe /Create /XML %userprofile%\Desktop\ARQUIVOS\tarefamaluca.xml /tn "TAREFA MALUCA"
exit

Schtasks.exe / Create XML means that the scheduler will be executed (schtasks.exe )

/Create : a task will be created / imported (which, before becoming a task, is an XML document;

XML so have XML there, because it will be imported;

%userprofile% \ Desktop \ files\taskmaluca.xml / TN : indicates the path of the task, being the name of that "taskmaluca.xml";

"crazy task" is the name / title you assign to task;

 2
Author: A. Silva, 2019-09-29 17:56:03