Text File + JNLP - java

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

Related

How do I configure the server so that It stores the dynamically created files in the specified folder not under the bin folder?

I have developed a web application which will create an xml file based on the user Input. It has some more functionality. I configured my application to store the xml file(s) in the project root folder. When I run it through eclipse It stores in the specified location. But If I manually put the war file in apache tomcat and run the application those newly created xml files are going into bin directory since I used relative path. Now I dont want it to be created under bin directory. I want those files to be created somewhere local in the system. Is there any way to do it ? Or else what is the best way to deal with those xml files. I am using spring MVC.
You could use a variable in your code would contain the first part of the path (the real location where you want to write the file). And inject the value of that variable from a properties file, that way you wouldn't hardcode anything, and still would be able to provide only the relative path in your code.

How to refer a file system in Cloudbess?

I'm new to Cloudbees. I just opened an account and trying to upload a .JAR file which basically downloads a file to the location mentioned by user (through java command line arguments). So far I have run the .JAR in my local. So far, I was referring to my local file system to save the file. If I deploy my .JAR file to Cloudbees SDK, where can I save the downloaded file (and then process it).
NOTE: I know this is not a new requirement in java if we deploy the jar in UNIX/WINDOWS OS where we can refer the file system w.r.t to home directory.
Edit#1:
I've seen couple of discussions about the same topic.
link#1
link#2
Everywhere they are talking about the ephemeral (temporary) file system which we can access through System.getProperty("java.io.tempDir"). But I'm getting null when I access java.io.tempDir. Did anyone manage to save files temporarily using this tempDir?
You can upload a jar with the java stack specifying the class and classpath (http://developer.cloudbees.com/bin/view/RUN/Java+Container)
Our filesystem however is not persistent, so if you are talking about saving a file from within your application, you could save it in this path
System.getProperty("java.io.tmpdir")
but it will be gone when your application hibernates, scales-up/down or is redeployed.
If you want a persistent way to store file/images, you can use AmazonS3 from your cloudbees application: uploading your files there will ensure their persistence.
You can find an example of how to do that in this clickstart:
http://developer-blog.cloudbees.com/search?q=amazon+s3
More information here: https://wiki.cloudbees.com/bin/view/RUN/File+system+access

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");

A static resource file?

Android uses a static resource file R. This file (at least in eclipse) is automatically updated when ever you add new id's of any sort. How can I create/implement the same feature in a normal java application? Is it as simple as just writing an xml parser and just updating the resource file after the xml is modified?
In a way, yes. You need to create a custom build script/program which runs at the start of each build (before anything else), scans your resource folder files (and if they are XML files it needs to read in the XML files and parse out the string resources or whatever from those), then write it all to a Java file in some manner (e.g. R.string_name = "string value").
Make sure the XML files aren't actually packaged in your .jar, since all that information will be stored inside your Java resources file now.
For things which aren't XML files you could just store the filename as a string in the Java resources file.
You didn't specified the type or the use of the resources. I don't know android, but I'll try to help; If you just need to access some resource in your application you can use properties or resource, there are some differences see this other question Properties vs Resource Bundle

What is the proper way to use ResourceBundle.getBundle() in an Android application?

I want to know how I can use ResourceBundle.getBundle() in an Android application given that I use it in my Java applications. For example:
I have a properties file, "MyOrg.properties", which I've included in a JAR file named "MyOrg.jar". The path information in the JAR file associated with "MyOrg.jar" is "myorg\" (this is on a Windows system). I build my Java application using "myorg.jar" and note that the following line of code works as expected, which is that it loads the file "MyOrg.properties" from "MyOrg.jar" as a java.util.ResourceBundle:
ResourceBundle resources = ResourceBundle.getBundle( "myorg.MyOrg" );
Next, I place a modified copy of the file "MyOrg.properties" on the file system in the directory "c:\myorg", which is on my Java application's class path. I now rerun my Java application and note that the Resource.getBundle() returns, as expected, a bundle for the modified copy of "MyOrg.properties" (the one that is on the file system).
The behavior I've just described is what I would like to be able to accomplish with an Android application. However, ResourceBundle.getBundle() throws a MissingResourceException; it fails to find "MyOrg.properties" in either the JAR file or as a stand-alone file.
So I have two questions:
1) - Is it possible for an Android application to retrieve a resource from a JAR file using ResourceBundle.getBundle() (or any other way for that matter)?
2) - Is it possible for an Android application to retrieve a resource from a file using ResourceBundle.getBundle()?
Regarding 2): I'm using the nbandroid plugin with NetBeans 6.7.1 and I've placed copies of "MyOrg.properties" on the file system as follows prior to building my Android application:
MyProject
-- build
-- classes
myorg (directory contains "MyOrg.properties")
...
src
myorg (directory contains "MyOrg.properties")
you need to make sure the properties file makes it to the .apk file. your best bet is probably in res/raw/ or assets/. see also PropertyResourceBundle's constructors (since it's easy to get hold of an InputStream).

Categories