Permissions for Java application on Ubuntu - java

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

Related

Saving an install directory for software

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

JAVA always read the directory from where jar is executed

I have a small java app that updates files in a set location.
the app reads from a UpdateFiles folder, moves the files in this folder to the appropriate folder. the app works. what i want to know is how should i set my path if i want the app to always try and look for the UpdateFiles folder in same location that the app is? for example if the app is executed from desktop i want it to look for the UpdateFiles folder in desktop, same for any other location. The app runs on windows and AIX/linux enviroments
thank you / kind regards
You can access the system property that contains the current working directory:
String currentDirectory = System.getProperty("user.dir");
You can determine the location of the jar file, but this is not the same as the current working directory (the directory you get if you don't specify a path)
However the location of the jar is rarely a good place to store files and you don't want to mix released programs with files as this make upgrading your software much more complex.
I suggest using the user's home directory System.getProperties("user.home"); or a sub-directory This doesn't change if you upgrade you software is should always be writable.
You have to start your app from the dir where UpdateFiles is located, if necessary you can create a bat file (for Windows) and run it from any location
cd c:\path_to_UpdateFiles
java MyApp
do something similar in Linux

HSQLDB lock file in programs and files - file directory write permission

I have an application in JAVA that connects to HSQLDB and need to be installed, i made that app and works fine, but when i put my code on the Programs and files folder, the HSQLDB cannot edit the lock property and cannot open the software =(
i know that is Windows security, but, is there a way to make the folder who contain my database editable?(c:programs and files\mySoftware\database) Like in PHP, using chmod...
Thanks!
You are using the wrong approach. Instead of making a folder editable, you need to put your files to application-specific folder under \Users\All users\AppData\yourapplication (in Windows 7) or \Users\Profilename\AppData\yourapplication folder. The path to this folder is obtained via Windows API (don't know what Java offers in regards to Windows-specific API, sorry) function named SHGetFolderPath. You need CSIDL_APPDATA or CSIDL_COMMON_APPDATA paths there.

Dependency issues in deploying using Java Webstart

I am working on a project in Java which has a directory structure something like this:
MainFolder
/ | \
Folder1 Folder2 Folder3...
|
Program.jar|Run.sh
In Folder1 I have main jar file along with the shell script to run the program.
In Folder2 I'm having configuration files in xml which may later be modified by the program
and In Folder3 I'm having jar files that the main program depends on.
Now I want to deploy this program using Java web-start.My current understanding is that web start allows us to deploy programs using 1 or more jar files.My problem is that I need the directory structure also.Can anyone suggest a solution for this.
As mentioned by others, the shell script raises problems. What does it do specifically to 'run the program'?
For the configuration files - 'Folder 2', webstart provides the PersistenceService. I have a small demo. (1)
As far as the Jars in 'Folder 3' go. Move them, as well as the Jar's in folders 2 & 1 to a single directory named 'lib'. The main Jar and the configuration files will be required eagerly, which is the default for JWS. If any of the other Jars (ex. '3') might not be needed immediately or at all, they should be deployed as download='lazy'.
To access the local file system - for reading input supplied by the user or writing a new file they created - a JWS app. normally needs to be digitally signed and trusted. But JWS also provides the much more limited form of access through the FileContents object. For more details, see the demo. of the File Service in the page linked below. (1)
1) Demos of the JNLP API, including the PersistenceService & FileContents object.
I think you will have to make some changes to the structure for webstart deployment (possibly package it as a jar or set of jars), also the launching will be done via JNLP, by webstart and not Run.sh.
Additionally you will have to sign your deployment if you need permissions to write to the disk.
See the FAQ for webstart here
Also check out the developer guide on how to deploy using webstart
Java WebStart does not provide any help in making the filsystem as you need it - it only provides the program components for memory.
If you need this structure, you will need to maintain it yourself (and then, where?)
If the only thing you need is a shell script to run, you can keep the contents of that file as a resource inside your jar, create a temporary file at each run, put the desired contents inside, and execute it, and then delete the temporary file when you are done. Note that this brings you into the wonderful world of code signing which is rather tedious.

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