Does Java Web Start give a default program folder? - java

For Java Web Start is there a default place to store and access data related to my program? Or do I need to create a folder? For Java Web Start (assuming I don't get a program folder) is it standard to just create on in Program Files for window, Applications for mac, etc?

I would use a subdirectory in the users home directory. E.g. System.getProperty("user.home") + File.separator + ".myapp/"
But for that the user has to add extra permissions for the a web start application.
To persist you can use a properties file or XmlEncoder which are included in the JDK. Or use external libraries like XStream, Xvantage or the simple framework where it is simple as
xstream.save(anyObject)

In addition to the Preferences API for storing user settings there are a few services that can be found in the javax.jnlp package.
For your concrete requirement the PersistenceService would be particularly useful.
Alternatively you can simply provide all data that your application requires as part of your .jar files, reference them in your .jnlp file and customize how and when they are downloaded by using the DownloadService.

There is no specific default place to store and access data related to your program with webstart. However Java does have the Preferences API to provide a platform independant way of storing configuration without worrying about the specific storage location/format.

Related

How to wrap a Java Web Start in .exe?

I'm afraid that many users still don't know what Java Web Start, so they may get confused by the small, single .jnlp file. So is it possible to wrap it as a very normal application, i.e. Windows .exe(or OSX .app) with pretty icon?
"The shortcut element can be used to indicate an application's preferences for desktop integration." The desktop element in particular allows platform-specific integration in a way that users expect.
I wrote a script to fix-up the file association for executable .jar files. You could just modify my script and that would give your users a way to register the .jnlp extension if it wasn't yet registered on their system.
NOTE: In the case where you have a user who hasn't installed Java on their system, they wouldn't have this file association, and you could use this script to associate a "bundled jre" with .jnlp extensions without the user needing to install Java.
Basically JAVA runs on a virtual machine, but cross-compilers can be used to re-compile your java code , creating an .exe or .app file
if javafx is an option, linked article describes nice ways how to deploy the same application both as .exe and .jnlp
http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm#A1324980

Keeping history of items without using a database in java

I have a small java utility application which performs tasks on remote computers. This app will provide user with a dropdown/combobox where they can enter ip address or hostnames for the computers they wish to connect to. It would be nice if the users could have a history of items/hosts they had connected in the dropdown.
I thought that I can create a file inside the distributable jar and use it to maintain the history. But writing to a file inside the jar seems to be impossible? The alternate approaches would be to use text files, databases etc located outside the jar. But this is not quite I would like to do as my utility app is only one file and I would like it to be completely independent of any external files. Also its not nice to have a text file stick around your jar file or create a text file each time your app is run.
Considering this case what options can I use? Are there any apis that can help in storing or keeping history?
Why don't you store this info with an hidden file in the user home directory? Many application do the same thing.
You can get the user home directory in this way
String userhome = System.getProperty("user.home");
I'd recommend keeping some .dat file somewhere associated with the JAR. Could be in same directory, or in the user's home (as #dash1e recommends) to avoid any permissions issues. I think you'll find that's the simplest solution.
Another option would be to use a Java-based database solution which could be bundled into your JAR (see Apache Derby, et al). Note that this would create files somewhere, but you wouldn't have to worry about the file-level management, as you'd just be interacting with it as a database.
One final option, if you really insist on avoiding having to maintain your own file, would be to use the Java Preferences API which provides an OS-agnostic way of storing data on the system in some obfuscated location. This is arguably a bit of a misuse of the goal of this API, but would accomplish what you're asking for.

Common place for creating files on various platforms (non-user-specific)

I write cross-platform java app and I need some place where I can store some amount of files. These files will be used by another java application that may run under another user. This mean that I cannot use:
System.getProperty("user.home");
since I may have no permissions to read/write these files. What I need is some way to get non-user-specific folder where every app can create/read/delete files (something like "C:\ProgramData" for windows).
Is there a cross-platform way to get such folder(at least for Windows and Linux), or if there is no any - what is the best way to get such folders for Windows(should work on XP-7), Linux and Android.
Any pieces of puzzle are welcomed.
I'm not aware of such such a cross-platform folder which is additionally readable by all users. But you can:
Define a specific folder for each OS, commons-lang may help you determining the platform (see SystemUtils)
Check if the folder read/writeable for the current user during application start-up.
Using a central configuration (where the data exchange folder is defined for this installation) may also be an option, but this depends on the packaging of your project.

Java - where to put application data?

I'm writing a Java application which requires a number of resource files (there will be about 100 files of 20-40K each). They are not edited by the user, but will require periodic updates (the application will have a function to check for changes to the resource files and download them). Ideally, the application should be cross-platform.
Allowing write access to a subdirectory of the program directory is generally frowned upon. If I was doing it as a Windows application I might put them in Application Data, but that's not going to fly cross-platform. What would be the best place to put them?
I would typically create a directory (name starting with a period ".") in user's home directory (System.getProperty("user.home") if I am not mistaken) and use that for application specific storage. Alternatively, you could take the directory name from user at the time of application installation.
Have a directory you use to keep these files in. Put that information in a properties configuration file. When you start up load the configuration file from your application install directory. From that properties file it tells you where to find your file directory. When your installer runs it can write out this configuration file for the platform you are installing on, and that can be OS specific.
Provide a configurable location, but default to a directory in the user's home directory, or in an OS-specific location.
You'll have to deal with this in a platform-specific way no matter what. You have a few options under OS X, though. For unix-like systems either a home directory, or perhaps something under /var.
That said, I don't believe a program managing its own data in its own directory is a bad thing; consider a program with an embedded database or similar. It's much more reliable to use an app home directory.

Best location for properties file

I'm working on a small java application that needs to load/save configuration properties. At first I tried using a properties file that lived inside the jar but I was concerned if someone were to upgrade to a later version (replace the existing jar) they would loose all of their settings.
My next idea was to write the configuration file to the disk and reference it but I'm not sure what location I should save to. I don't want to use the current directory because the user could move the jar between directories and forget about the configuration file.
Is there a common location for configuration property files (specifically on windows)? If so how would I access it (I assume it would be some sort of wild card character like %appdata%\my app\config.properties)?
Thanks!
You might want to look into using the Preferences API instead. It provides a lightweight and simple way of storing application and user preferences, without directly accessing the file system.
Try the java.util.prefs Preferences API... as long as you are using Java 1.4 or newer. I think that will do what you want. I wrote a little post about them a while back: http://coffeaelectronica.com/blog/2009/07/java-preferences-api/
Hope this helps.
The user.home system property provides the path to a users home directory if you want to store on the file system.
There is also the Preferences API that was added to Java to solve this exact problem.

Categories

Resources