Java Web Start: How to write files to windows UNC Path? - java

I have an Java application for copying large amounts of data from users' workstations to a server. The java.io.File class is supposed to work with UNC paths very well and in fact it does but only when I run the app in standard execution model.
When the application is launched via Web Start I get a FileNotFoundException when trying to open a FileOutputStream with "The network path was not found" in message. Again everything works fine when I download the jar to the PC and lauch it from command line.
My app is signed and i define all-permissions in JNLP.
Edit: I have also discovered that when I map the UNC path to a drive letter it works too.

There is no solution to this. I ended up mounting the path as a named volume and using it trough the volume.

Related

How can I make my java code machine independent

I have written a very small java code on Eclipse which will automate a small process of logging into a web system. The employees of my company use this web system to connect to office network if they are working from home.
I have converted my java project on Eclipse into an exe file, my intention is to log into that system by just a double click on the exe file.I have parameterized the userID and password and have stored it in an excel file on my local machine.
The problem am having is, My exe file will not run in any other systems except mine as my code is referring to the excel file(which has userID and password) path on my local machine. I would greatly appreciate the developers on this forum who could help me out to come up with a solution for this problem.
What about looking for the excel file in a well defined folder like C:\Users\\my-tool\credentials.xls. Or maybe look for it in the same dir as the executable?
You can get the path of the home folder of the current user with this command:
String homeDir = System.getProperty("user.home");
With that you cann assemble your custom lookup path:
Path xlsPath = Paths.get(System.getProperty("user.home"))
.resolve("my-tool")
.resolve("credentials.xls");

java desktop and web application using the same filepath

I wrote a desktop java application with a class (say ClassA) that reads the content of a file, processes it and returns some results. The filename was specified relative to the project using
File input = new File("config.xml");
Now, I want to upgrade the project into a web project. I wrote a servlet which calls the same java class (i.e. ClassA) for reading the content of the same file but this time I get an error message saying file not found.
How do I refactor my code so that both the desktop and the web versions run smoothly.
Just copy the file config.xml into the proper location on the web server e.g. public_html/www/
The "working directory" of a web application is different - depends on the configuration of the web server you are deploying it to.
If you read a file without specifying a path, it is read from the current dir, which you can access with System.getProperty("user.dir");
So you can try to find out what value is returned by System.getProperty("user.dir") in your web app and place the file there.
But this may differ depending on the environment and servlet server (Tomcat etc.) and may be not a reliable solution.
Another way is to change your code, so it reads the file from the user.home directory and place the file there.

Do we need seperate file path for window and linux in java

I have a file on linux ubuntu server hosted with path name /home/kishor/project/detail/.
When I made a web app in window to upload and download file from specified location i used path "c:\kishor\projects\detail\" for saving in window.
For my surprise when i used window file path name in my server i am still able to get files and upload them, i.e, "c:\kishor\projects\detail\".
Can anyone explain why it is working (as window and linux both use different file path pattern).
I've seen this work too. What linux does is create a file whose name is literally c:\kishor\projects\detail\
If you say, you can "upload" files... perhaps there is now a new folder structure.
Some months ago i saw a similar thing: Under /home/webadmin was an new structure "/c:/Users/...."

Creating directory Structure in a UNC path with java

I'm trying to Create a directory structure with java, in a remote UNC location.
java is running in a linux machine and the windows network path is mapped with SAMBA server.
Issue is :
When creating the directories it creates the first directory : OK
Try to create the first sub directory inside the first directory : FAILS
Because it takes some time (nearly 2 seconds) to show up the first directory through samba.
This could be due to the slowness of the network (but it's unavoidable )
If i execute the same code step by step (debugging) it works normally and create the directory structure.
Please help me.
I need some mechanism which will wait java mkdir() function until the initially created directory
get showed up in the UNC path.

how to read geolitecity file path from linux server?

My development environment is windows, using JSP,Apache server 5.5. I developed an application with the help of geolitecity provided by MaxMind. I have uploaded geolitecity.dat into my server in the same folder of my website(I dont know its the correct procedure, I am doing it first time).And I used
String systemPath=new java.io.File(".").getCanonicalPath();
to get the current directory path, so that I can read from it. But I am not getting the full path. am only getting upto tomcat5.5.3\bin. Is it possible to read the file with this path? I dont have much knowledge in linux.
In Servlet/JSP:
String path = getServletContext().getRealPath("/yourfilename.txt");
This will give you complete path of given file name.
Note: It will work when you will deploy it in tomcat and run from out side eclipse. As eclipse has its own internal structure when it deploy the web application [if not changed].

Categories