I have the following methods at my disposal:
- A method to get the running JAR file’s path. (The path of the file to copy).
- A method to get the current operating system. (Mac, Windows, Linux, or Unknown).
How would I go about writing a method to copy the JAR file to the startup directory based on the type of computer?
The concept of a “startup directory” that you can drop executables into to run at startup time does not make sense for Linux / UNIX.
In a typical Linux system, tasks performed on system startup are controlled by the
initprocess based on shell scripts that are typically installed in/etc/init.d. Thechkconfigprogram manages a bunch of links in “run level” directories that tellinitwhat to run for each system run level.The init.d scripts are not just any old script.
chkconfigprogram when the script should be run; i.e. at what run levels, and in what order.I believe that modern UNIX systems work roughly the same way, though I known that some older versions did this differently.
Update in 20012: It gets worse. Recent Linux distros are replacing
init.dscripts withupstartscripts. Sigh.The above deals with system startup. There is no general concept of a “startup directory” for users either.
I guess, a window manager could implement a “startup directory”, but a typical Linux user is free to choose and configure the window manager, or use no window manager at all.
The normal way to configure things to happen when the user logs in is via shell initialization scripts; e.g.
~/.bashrc,~/.bash_loginand so on. It is a BAD IDEA for an installer to modify those files because it would be next to impossible to get it right in all circumstances … given the weird and wonderful things it is possible to do in a shell initialization script.The bottom line though is that if you are writing installers to install your software for a number of platforms, you have to understand those platforms. You need hands on experience using them and (to some level) administering them, and specific knowledge of the “right way” to do software installation. Clearly you don’t have that knowledge yet for Linux / UNIX.
Writing installers without adequate knowledge and adequate testing is really, really dangerous. An installer has to be run at a privilege level that means that it can do serious damage to the target system if something goes wrong.