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");
Related
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
I am trying to install WFDB Toolbox system-unspecifically in my systems (Ubuntu Linux 64bt/OS X El Capitan/Windows 10 education). I need to get the Matlab Path i.e. set in /usr/local/MATLAB/R2016a/toolbox/local/pathdef.m by Java/Matlab own means. However, I did not find an approach for that.
Pseudocode
matlabpath=char(java.lang.System.getProperty('user.path'));
where I tried in path also matlabpath.
I have specific locations where I keep sufficient permissions for Matlab.
I need the approach i.e. user.path such that I know where I need to keep sufficient privileges.
Warning that I get when installing WFDB in Ubuntu Linux 64 bit and Matlab 2016a, which is a complication of not being able to manage the path non-system-specifically
Warning: Unable to save path to file '/usr/local/MATLAB/R2016a/toolbox/local/pathdef.m'. You
can save your path to a different location by calling SAVEPATH with an input argument that
specifies the full path. For MATLAB to use that path in future sessions, save the path to
'pathdef.m' in your MATLAB startup folder.
> In savepath (line 169)
Java would be the best solution for this, but Matlab's own solution is ok too.
How can you get Matlab's path by Java/Matlab?
The "MATLAB Startup Folder" can mean many things depending upon the user's configuration as well as the operating system.
The Mathworks has a whole page about this here.
One way is to ensure that the startup folder is the same as the userpath (how you do this depends on your OS so see the link above). Then you can access that from within MATLAB using the userpath command.
folder = userpath
If you're on Linux, you can ensure that the userpath is used as the Startup Folder by following this excerpt from the link above.
Default Folder on Linux Platforms
On Linux® platforms, the default startup folder is the folder from which you started MATLAB.
To specify the userpath as the startup folder, set the value of the environment variable MATLAB_USE_USERWORK to 1 before startup. By default, userpath is userhome/Documents/MATLAB, and MATLAB automatically adds the userpath folder to the top of the search path upon startup. To specify a different folder for userpath, and for other options, use the MATLAB userpath function.
There is another option (on newer versions of MATLAB) that would allow the user to set their startup path to whatever they want and you still be able to determine it.
Since R2014b, users can specify the initial working path in the preferences (MATLAB General -> Initial Working Folder). You can check if the user has specified a custom initial working directory using the following commands
settings = Settings;
folder = settings.matlab.workingfolder.InitialWorkingFolder;
Disclaimer: This functionality was discovered by looking at MATLAB's own matlabrc file and while there is some documentation for Settings it's likely not officially supported, so use at your own risk.
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
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
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.