Saving an install directory for software - java

I have a software tool that I am working on in Java. It will be deployed to both Windows and Linux. I am at the phase where I am trying to determine the best course of action for saving the user's installation directory (where i will store all external files). Ideally I want the user to be able to move the program to any directory they choose (even after installation) and it will still be able to find the installation directory.
I have considered using environment variables to save the path but I am not sure if that is the best practice.
What is the standard practice for saving a path to an installation directory on Linux and Windows? (I am open to making different install logic for each OS)
Edit
After a bit more research, I have found that the /etc folder for linux is where I should store data and the Registry for windows. Can anyone confirm this?

In Windows, registry works great. Here's an example from a product I use (evo5.0 with eurovoiceHMP):
Locations of config and logging folders can be configured manually via the registry,
eurovoiceHMP and evo5.0 then "find" these folders under registry:
HKLM/Software/eurovoice
Specific registry setting examples:
HKLM/Software/eurovoice/HMP:
evoHMPLicencePath C:\ProgramData\eurovoice\HMP\Config\Licences.txt
InstallPath E:\hmpTest
HKLM/Software/eurovoice/evo50:
evo50SystemVoiceFilesDir C:\TeleSage\sysvox
InstallPath C:\Program Files\evo5.0
evo50LogDir C:\TeleSage\Logs

Related

Build user-specific izpack installer during server runtime

I am looking for a freeware OS independent installer.
Users can configure the application from web interface and then download it. Server should build the installer with default files and include user configured files. All files are stored in a database.
Does anybody know if it is possible to build the installer during server runtime with user-specific configuration files with izpack, And what would be the sequence of the events?
eg. load all files (incl user configuration) from database, write files to file system, modify izpack installation file to contain the resources, execute command to build the installer, load the installer from file system, serve it to user, remove files.
Thanks,
ozooner
The short answer is yes, we do something similar for our build system
The long answer would be, work out the normal workflow you would need in order to build the package manually and automate it
Off the top of my head...
Layt out the files in the required structure
Update the izPack script to meet the requirements of the Custer
Run izPack to build the package

Saving a file with Spring MVC

I'm running an application from within the Tomcat container. The user clicks a link and this ultimately causes a method in a helper class to create a file and save it to the file system. When this code is run from a unit test / eclipse it saves the file in the applications root directory but when this is run from the browser / in Tomcat the file is stored in Tomcat's bin directory.
How can I find the applications root so I can choose where the save the file from there?
I need to programatically find the root so this can be deployed onto other environments running tomcat.
Thanks
You should not rely on the position of your Tomcat installation, and your application should not write into the Tomcat installation folder, never. It is quite possible that the Tomcat installation is not even writable for the user running Tomcat in a production environment.
Therefore, use full (absolute) paths only.
To avoid file permission issues you may want to use the user's home directory using System.getProperty("user.home"). That way it will work consistently across environments and operating systems.

user working directory: XP vs Vista

I have a Java desktop application that I have written.
During the execution I create folders and files at the default path name defined in the system.
Java.io.files clearly states: By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.
In addition, I am using IzPack to enable installation and shortcuts creation.
When I'm running my application on my XP computer, after the installation I get a desktop shortcut, and the mentioned files and folders creation are at the location that Izpack installed the Jar. which is the expected behavior.
But when I test this out on a Vista machine, the folders and files are created on the desktop! even though the Jar is at the correct location (c:\program files.. etc).
I want those files to be created at the same folder the Jar is in, and most certainly not at the desktop.
Can anyone give me any insights on what is going on here?
It's because in Vista/Seven, writing to the Program Files folder requires administrative interference, so JVM looks for the next writable location as a fallback: the Desktop (or the User Documents directory). You can easily determine the User home directory in a unified manner on all OSs, though, which is way better than just letting the JVM pick a -- hopefully -- reasonable location.
Since this is a known bug for JVM on Windows, if that doesn't help, the fallback is to check the System Environment variable USERPROFILE which should point at the correct user home folder:
String userHome = System.getenv("USERPROFILE");

Permissions for Java application on Ubuntu

I have a NetBeans RCP application that's currently working on Windows and I'm trying to make Linux compatible. The application creates folders and files and modify files as well.
It works fine on Windows without any modification but on Ubuntu it fails creating folders during start up. I know it's a permission issue.
What are my options?
Can the application itself assign the permissions it needs like by running a script using ProcessBuilder?
Thanks in advance!
It all depends on who you are when running the process on Ubuntu, and the path of the folders that you're trying to create. Does this user have permissions to create the folders in that directory? What sort of data are you writing out to disk? Can you use a platform neutral mechanism thats user oriented, like Java Preferences or perhaps:
System.getProperty("user.home")
-or-
System.getProperty("java.io.tmpdir")?
You either need to create required folders as part of a setup process or restrict your IO to folders you have access to (the users home and the temp folder). Notice that on Linux there are standard locations where many folders should be placed and that administrators will frown upon applications that do not follow these standards.
Can you tell what files/folders you need for what purpose?
Looks like the cause of the problem is the difference in path delimiter between Windows and Linux. On linux you should use normal slashes. The error mentions the path:
/home/javier\marauroa.trace.db
As the \ is not a path delimiter but the escape character it is trying to create a file in the folder /home where it does not have permissions.
The path should be:
/home/javier/marauroa.trace.db
You might want to consider putting your apps files in a subfolder called .yourappname so then it would become
/home/javier/.yourappname/marauroa.trace.db
This is what many unix applications do and hide it in normal file listings. To get the path seperator for the system your application is running on you can use the following static field:
java.io.File.seperator

Java development in Ubuntu

I'm a newbie to Linux systems and recently I started using Ubuntu 10.04. When I do java development in Windows, I usually keep my project files under some drive (D: for example) and under my development folder, such as D:\projects\myproj. But I'm bit confused with Ubuntu's folder structure. So, I just want to know how do you organize your projects in Ubuntu? Under which folder do we keep our projects file?
You can do anything you want, but typically if you develop in a directory that is not under your home directory, you'll probably need administrator (root) permissions to set up the directories. Another reason to use a sub-directory under your home directory is that in larger companies, the home directories are often stored on a separate file server, which is backed up on a regular basis.
I usually create a directory workspace in my home directory, and then create project directories under that. Other developers may use src or projects.
On Unix-like operating systems (including Ubuntu, other Linux distributions, Mac OS X, Solaris, FreeBSD, etc.), you normally store everything under your home directory (typically /home/username in Ubuntu and many other Unix-like OSes, where username is ofcourse your username); not in an arbitrary folder in the root of your filesystem like you do in Windows.
Unix-like operating systems are multi-user systems at heart, unlike Windows, which is a single-user system at heart - that's why you're supposed to store all your own stuff only under your own home directory.
For example, make a folder /home/username/projects/myproj for your project.
To learn more about the Ubuntu directory structure, see LinuxFilesystemTreeOverview in the Ubuntu Community documentation.
Wherever you are comfortable with. e.g. /home/yourAccount/projects/yourProj
I've setup a different mount point to store user profiles. That way, even if the OS wont reboot after an update (I tend to use Alpha builds) user profiles are left intact.
I'm not sure how to do this after the installation procedure however, sorry.
I suggest Eclipse, like above, if you're looking for a perfect IDE.
I keep my main workspace in the home folder, then create projects, following the wizard (creates folders).
I keep them in my home folder under a work subdirectory. My default workspace directory for Eclipse is /home/tiwe/work/workspace
Use symlinks for shortcuts
I would just use Eclipse, go into the software installer for Ubuntu and find Eclipse under the programming section.
As other have stated, private stuff typically goes in your $HOME directory and I create all my projects under /home/pascal/Projects/. I then import them from there into an IDE. In other words, I don't store anything in Eclipse's workspace folder (I don't want to rely on anything IDE specific and I actually may use more than one IDE for my projects).
If really you want to use a separate partition (other than the one hosting /home), you can do so and mount it (typically under /mnt) and create a directory tree for your projects (and set user and group permissions, depending on the file system used). But I don't really see the point unless you're running out of space in your home, the other partition is faster or has a different backup policy.

Categories

Resources