Search code examples
javaipip-addresstomcat8hard-drive

Access secondary hard drive from IP in Java application in Apache Tomcat 8.0


I have a Java web application that has to access a file in a hard drive different than the one the application is installed in.

I have the address configured in my Web.xml, this data is accessed from the Java code.

<param-value>//USERNAME:PASSWORD@IP_ADDRESS/HARD_DRIVE_LETTER/FOLDER_NAME/</param-value>

USERNAME: User of the computer I want to access to
PASSWORD: Password of the mentioned user
IP_ADDRESS: Internet Protocol v4 Address of the Computer
HARD_DRIVE_LETTER: I want to access to J: hard drive
FOLDER_NAME: Name of the folder I want to access

I have tried this way with no result:

<param-value>//USERNAME:[email protected]/J:/Documents/</param-value>

I have been able to use this URL locally because my test computer had only one Hard Drive:

<param-value>//USERNAME:[email protected]/Documents/</param-value>

So I could access the files in C:\Documents with this method with no problem.

Now, I had to export my application to a different computer, so I had to install Apache Tomcat 8.0 (Version 8.0.30) in that computer, in Hard Drive I:
And the data that my application has to access is stored in Hard Drive J:

How can I properly entry the right URL to access the data from my application?


Solution

  • I managed to solve my own problem. The issue was that I was not writing properly the name of the hard drive I wanted to access.

    To know the real name (or shared name) of a resource, I had to search here:

    Right click on Windows logo or Start button Choose "Manage Equipment" System Tools > Shared Folders > Shared Resources Here you can see the promer "Resource Name" with its "Folder Access Route" So, to access drive J:, I had to type the IP address of the computer + "/" + "J$"

    <param-value>//USERNAME:PASSWORD@IP_ADDRESS/J$/FOLDER_NAME/</param-value>
    

    In my code, I used SMBFile to access the file, so I had to create a String adding "smb:" to the beginning of that parameter:

    String fileAddress = "smb:" + fileLocationParam;
    

    Where I obtained "fileLocationParam" from the Web.xml

    This way, I was able to access the file using SMBFile