What is the exploded path of a jar downloaded by jnlp? - java

I have a web app. packaged as a jar file and served by Java Web Start using jnlp. When the user runs my program, it generates an excel file, which is to be shown by a web page within the same app.
The question is: where should my java class write the excel file so that the web page is able to locate/serve it? Obviously, web page can read from within the web app only (sandbox). But the only handle that I can get to the jnlp downloaded app is the jar file (which is not modifiable at runtime) and not EXPLODED jar file contents. If I am able to locate and write to the exploded jar file contents, I can write my excel file there to be picked up by the web page.
Any help? Any alternatives?

..where should my java class write the excel file so that the web page is able to locate/serve it?
Write it to a sub-directory of user.home. Either that or to the temp.dir (spelling?).
Either of those apps. should be writable be a Java app. without special permissions (e.g. running as root).

Related

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.

Where to put an excel file in a dynamic web project so that I can write and read it.(use it as DB)

I have a dynamic web project where I have login and register user and I am using POI to read and write the details in an excel file.
I want to deploy this project as WAR file on tomcat.
But the issue here is Tomcat is not able to find the excel file's path.
So where should I place the excel file.
Right approach would be to
Make a directory on your OS outside of the tomcat.
Write a startup servlet which will check if the directory already exists.
If the directory exists, go ahead and create the excel file into that directory, instead of keeping an already build file, that way you make sure that the excel file is not tampered by any developer accidentally and is only constructed by the application.

How can I programmatically find the path of JNLP file? I am using Java Web Start to generate the JNLP file

How can I programmatically find the path of JNLP file?I am using Java Web Start to generate the JNLP file.
I know that manually you can find the JNLP file in the Java Cache Viewer in Resources with the name launch.jnlp, but I really need to know if there exists a Java class that can programmatically find the jnlp file by searching the in-memory cache.
How can I programatically find the path of JNLP file?
It is hidden deliberately. If you can find it from within code (shorting of asking the user to browse to it), the JRE has a security bug.
..for launching the installer I need the application jar files path
No you don't.
Put the installer inside a Jar.
Add the Jar to the resources of the app.
Get an URL using getResource(String).
Read the byte[] and write it to a temporary file at a known location (e.g. java.io.tmpdir).
Launch the installer from the known location.
String jnlpPath = System.getProperty("jnlpx.origFilenameArg");

Text File + JNLP

I’m trying to figure out how to include a reference to a external data file (in text form) that I want distributed along with my application via Web Start (JNLP). Sifting through the documentation for the JNLP structure, I see that you can include references to JAR, nativelib, and extensions – however, I don’t see a means to include a text file resource. How can I accomplish this so that Web Start will download the text file from the server and store it locally along with my application?
I don't believe you can do that.
You can, however, put it on your classpath (in a jar) and reference it through getResourceAsStream().
i just checked that jnlp file is also available as jar file also and as exe file also, so can i open these in a java gui and load my xml file

Java applet error

I am doing a project on applets. I designed the applet using netbeans. After building the project in netbeans, I took the directory "classes" and a .html file from the "build" directory and moved it to another new directory. This .html file includes the applet. The .html file displays the applet correctly, when it is viewed from my desktop.
I uploaded the "classes" folder and the .html file to my free server (host4ufree.com) using FileZilla. If I try to view the webpage online, I get the following error instead of the applet getting displayed:
java.lang.ClassFormatError: Extra bytes at the end of class file
I am using JDk 1.6.0 update 18, and uploaded the file using FileZilla both ASCII and binary format manner. Yet, I am not able to solve the error problem. Does anybody know the solution to this? Is there something wrong in the manner in which I'm trying to add the applet to my webpage?
The question is quite unclear :S Anyway...
I uploaded the "classes" folder and the .html file to my free server
(host4ufree.com) using FileZilla.
If your applet contains more that one class I do not recommend upload the project classes folder itself but wrap your applet classes to jar file before delpoying it.
Report if that helped

Categories