New Docker file
FROM java:8
COPY hello.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar", "pkg.hello"]
Ok after lots of trial and error I found one solution, there might be more than one. I want to explain a bit for those who are not very expert like me,
As we know docker makes a something like a mini OS inside the container, I mean the required libraries and files + the application we developed. I tried to run and see what is inside my directory when running in docker. by running on eclipse on windows it shows the regular path, E:\Java\.... . But when I ran it on docker it shows only "/". and then I tried to see the contents. on windows the files and folders inside the current Dir but on docker it shows some folders same as LINUX root path folders, bin sbin mnt proc etc. So I realized that there is a mini linux. I knew this fact but never seen this result. So obviously the in.txt is not there in docker file system. now we see the docker features like -v. it allows us to copy/paste one directory from host, which is windows, to docker container file system. After running this command I saw that a new folder called data is added to docker folders
docker run -v ${pwd}:/data img
the whole contents of pwd (current directory on Win) is copied to data directory, along with in.txt. now my java program is supposed to be run inside the docker, So i need to change the hard-coded path.
String fileName ="data//in.txt";
definitely it does not work on windows because there is not \data\in.txt in my folders.
I could do it by getting some arguments and skip the hard-code, no matter. there are plenty of ways. I added my codes to see the Dir status, you may want to try.
String d = System.getProperty("user.dir");
File f = new File(d);
File filesList[] = f.listFiles();
for(File file : filesList) {
System.out.println("File name: "+file.getName());
System.out.println("File path: "+file.getAbsolutePath());
if (file.getName().equals("data")==true)
{
File filesList2[] = file.listFiles();
for(File file2 : filesList2) {
System.out.println("File name: "+file2.getName());
System.out.println("File path: "+file2.getAbsolutePath());
}
}
System.out.println(" ");
}