I'm developing a JavaFX application for both Windows and Linux (Debian/Ubuntu distributions), currently on Linux Mint (I honestly don't have any experience with other distros than Mint). The application should be able to open folders with the system's file manager.
While on Windows I use this with no problems:
Desktop dt = Desktop.getDesktop();
dt.open(path);
This doesn't seem to work on Linux, so I thought of simply using Bash commands like:
ProcessBuilder builder = new ProcessBuilder("sh", "-c", "nemo " + path);
But this only works on Linux Mint Cinnamon, since KDE and other editions may come with different "default" file managers (like Dolphin or Nautilus).
Now is there a way, either programmatically with Java or with Bash, to get the associated file manager?
You need to find the default file manager.
You can use the xdg-mime command for that.
xdg-mime query default inode/directory return the default file manager.
Output if it's dolphin : dolphin.desktop
OR
xdg-open <directory> but it can start the wrong file manager sometimes.
See the documentation for more.
xdg-open <directory> has been deprecated
use 'gio open' instead. see source
you have to double think things... what is for you to open a folder ??? What does it mean? different operating systems (like windows, mac, or the like) have different file managers, so the mechanisms are subject to differences (mostly as they have evolved from previous environments, sharing nothing in common and without java in mind). Even there are operating systems with no file manager at all, as for example linux console applications don't assume a desktop is running at all and cannot call the file manager to open a window (where? no windows at all, only the black console screen) and show the files contained there.
Windows applications user the file Explorer to show folder contents and the communication with the explorer follows a path that doesn't share anything in common (while the mechanism is similar, anyway) with the one used in linux.
In linux you have the added problem that there are several (better said, many) desktop environments competing and doing things differently between each other.
The java support doesn't dig so deep in the desktop environment to allow for the task you face on in a desktop environment independent way.
Anyway, there are several file managers written in java that do the same and can be run in either environment (java, windows and the mac), so you can run other route, and use a common file manager for the task. And probably communicating with a program written in java is easier from your application.
Related
I've made an application by java similar to notepad as a jar file then I make it exe file,,so what I want is to make this application appears in the right-click windows menu in the open with menu that can open for example any text file..
For example I have a text file on the desktop then when I right click on it and click open with my application should appear with the other available programs that can run this kind of files..
What should I do !
Windows has a thing called a "registry". It's an ancient and problematic system component that stores a wide range of data related to your computer, users, installed software, configuration and much more.
Part of the function of the registry is to associate file extensions (say, ".txt") with programs that can process files with that extension.
You've made an executable, and that's great. Now you need to tell windows that your executable can process files ending in certain letters. To do that you must modify the registry.
You could look into doing that with Java (there are answers here on SO) but I suggest that if your application is for consumption by other people, then the usual "done thing" on windows is to have an installer. My favourite is InnoSetup - free, fast, high quality.
Whichever tool you use (even a shell script) can set registry entries for you.
I have created a java application.
I also created another java application which install the first application.
The program runs perfectly.
However the program isn't displayed in control panel->programs.
I also want to create an uninstaller (let's say unintaller.bat). But i want to works like any other uninstaller. When someone goes to Control Panel->serach program->uninstall this program it will run the uninstaller.bat
In other words, the concept is how to declare the java application in windows...
Any idea???
Installing an application doesn't necessarily mean registering it with the operating system. For example, for a Mac, I can open an App without having it added to the Applications folder.
Same with Windows. Just because a new file can be added to the Start menu, it doesn't mean it was registered.
Use a Windows installer. There are tons that are open source, and even MS provides a free one: http://support.microsoft.com/kb/942288.
This will allow you to install an uninstall an application using standard tools. Yes. It can be called from a bat file.
Java open source installers: http://java-source.net/open-source/installer-generators
I have a Java application that lives in the system tray that I compile to a executable jar file. I would like to add the option within my program to add to the system startup items.
As I do not know of any uniform way to do this for all operating systems I assumed I would have to write code to do it for each one I intend to support so I started with Windows.
When I attempted to add it to the registry at [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] using the code available here I discovered that under Windows 7 and 8 unless I have administrator privileges (by running from an elevated command prompt) my edits to the registry do not apply.
Then I spent a day trying to figure out how to get the Jar to relaunch itself with admin privileges before I gave up on that hacky workaround.
Can the task I'm trying to achieve even be accomplished and if so how?
For the most part, you're actually looking to add the feature of auto starting on user login, rather than on system startup. For windows, if you add the registry entry under:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
This location does not suffer from permissions issues when run as an ordinary user, and has been supported for a long time under Windows (I'm thinking Windows 95 time frame here), so should be a safe change across all systems.
For Linux, assuming that the operating system is following the Open Desktop AutoStart specification, then you need to create the appropriate .desktop file in $HOME/.config/autostart/ and it should autostart on login in that case.
For Mac OS X, you need to create a launch agent plist in $HOME/Library/LaunchAgents. The Daemons and services documentation details how to construct this file.
Working around user privileges is not a good idea. The registry entry is the preferred way to go. Also keep in mind that the jar by itself is not executable, it requires the jvm, so what you might want to do is use a wrapper and register that.
Is there any way to change the system volume on Windows with Java or CMD programmatically?
I've found some command lines for Linux and Mac, but so far nothing for stupid Windows.
Take a look at a form post on oracles website https://forums.oracle.com/thread/2390172 you can see it is not possible from inside java using native libraries.
Quote from the oracle post: "Because Java is cross-platform, it cannot do platform-specific stuff like changing the volume or whatever you want to do to control the OS. You need to use the operating system's unique API layer to do it."
For command line I found this utility that seems to have what you are looking for http://www.nirsoft.net/utils/nircmd.html
If you don't want to rely on 3rd party executables you could either make your own exe or make a dll and look into using JNI.
I developed small cross-platform (Windows and Mac) SWT desktop application. It is distributed with WebStart. So far so good, everything works.
I've got a new requirement to make my app start on system startup (with no user interaction). What is the best way to accomplish that?
In JNLP file I've got this:
<shortcut online="false">
<desktop/>
<menu submenu="CompanyName"/>
</shortcut>
On Windows WebStart creates a desktop link [app_name].lnk and it points to
javaws.exe and then some Java cache file as a parameter with funny name like ..\Sun\Java\Deployment\cache\6.0\4\2c0a6a781-213476. I can possibly programmatically find that link on user's machine by name... erm... and then copy it into user's Startup folder. I can see a problem here though as user can disable WebStart desktop shortcut creation option all together.
On Mac WebStart pops up a dialog to prompt user for the location where to create an [app_name].app (user is allowed to change link name there!) file that launches an application. On Mac I don't event know where the Startup folder is located (and it seems to be much more complex there).
Is there Java library out there that abstracts start app on system startup concept on different platforms as SWT does for GUI abstraction?
There is, but it's very new, so it's not widely available.
The IntegrationService was introduced in 1.6.0u18. The method of interest is requestShortcut.
You can take a look at Java Service Wrapper. This can wire your program as a windows service.
Bump!
Seems like http://yajsw.sourceforge.net/ is the currently active project that achieves this.