Does anyone knows how to unmount a drive in java in OSx
I am trying to unmount a sdcard from java. I am using java Swing class and the drive gets mounted automatically, but how do I unmount it.
The concept of mounting/unmounting is not platform agnostic, so it doesn't exist directly within the Java APIs. You will most probably have to issue a command line call to unmount by using Runtime.exec()
There might be open source libraries available that wrap this exec call for you, but I'm not positive.
You could call umount using Runtime.exec. Of course, this solution is not portable.
Related
My Environment is OSX BIG SUR.
For space reasons, I need to move files from my Hard disk to a NAS (on my local network).
The current applications accessing these files (en read mode) were developed in Java.
I suppose I should use a Mount command in programs with the SMB protocol, but how to do this without be prompted for password with the SUDO command ?
So I'm looking for some examples.
You have a few ways to go:
Have java execute the smb mount command
This is a walking disaster; you don't want your java process to gain root privileges to do this.
Have java be an smb client
Possible... use JCifs-ng. The docs are lacking, and this would have been a lot simpler if it had integrated into the new files / filesystem API, but it doesn't. You'll have some coding to do.
Learn sysops
All you really need is for the OS to have that samba share mounted someplace and then, to your java process, it's all just files on a filesystem. Don't make the smb mount happen in java, ensure it's already set up before your java process even starts.
Could anyone please tell me how to make a symbolic link (in the same way MKLINK does) and/or remove a symbolic link with Java. I have found solutions that use Java as a wrapper and use a Windows native program to accomplish this, but I really want a pure Java solution. Thank you in advance!
Since Java 7 you can do this easily using the NIO package.
Path target = Paths.get("target");
Path link = Paths.get("link");
Files.createDirectory(target);
Files.createSymbolicLink(link, target);
Do remember that you do need the correct privileges for this. In my unit test I had to run eclipse as an administrator to make it work (same as that I couldn't create a link from a normal cmd.exe)
As far as I know window does not have real symbolic links like Unix-like system do.
However Windows has the following relevant tools:
You can map network drive, i.e. attach drive letter to specified network path. You can definitely do this using WMI. To access WMI from java take a look on tools like JaWin, Jinterop, Jintegra or write WMI script in JScript o VBScript and execute is from Java.
You can use command subst that assigns letter to local file system path. This is the closest approach to Unix soft link.
You can create desktop shortcut. Create one manually and take a look on it. Shortcut is actually regular text file (as far as I remember in INI format). You can easily create one using any language you want including java. This is not soft link but it is clickable.
I'm afraid that many users still don't know what Java Web Start, so they may get confused by the small, single .jnlp file. So is it possible to wrap it as a very normal application, i.e. Windows .exe(or OSX .app) with pretty icon?
"The shortcut element can be used to indicate an application's preferences for desktop integration." The desktop element in particular allows platform-specific integration in a way that users expect.
I wrote a script to fix-up the file association for executable .jar files. You could just modify my script and that would give your users a way to register the .jnlp extension if it wasn't yet registered on their system.
NOTE: In the case where you have a user who hasn't installed Java on their system, they wouldn't have this file association, and you could use this script to associate a "bundled jre" with .jnlp extensions without the user needing to install Java.
Basically JAVA runs on a virtual machine, but cross-compilers can be used to re-compile your java code , creating an .exe or .app file
if javafx is an option, linked article describes nice ways how to deploy the same application both as .exe and .jnlp
http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm#A1324980
I have a program, written in Java, which originally used its directory in Program Files to write files accessible to all users of this program. This required our users to run as administrator all the time. In an effort to alleviate that, we decided to move files which needed to be written during regular usage to the ProgramData folder using the %ALLUSERSPROFILE% environment variable. Using a subfolder in this directory for our application works great if it is designated as writable during the installation process, which works fine using NSIS.
The problem comes with upgrading existing users. The Java File API provides setWritable but this does not appear to work after testing on development machines. It looks as though the new file API with Java 7 would solve this problem, but with no release date on the horizon I would rather not wait.
It seems the simplest solution would be to use JNA to call the appropriate Windows API call to set this directory writable. Since upgrading the software necessitates admin rights, similar to installing, it should let this change go through fine. However, I'm unsure where to start, having never used JNA before or the Windows API. Suggestions as to which Windows library to load and what functions to call would be appreciated, especially if someone has encountered a similar problem before.
Well, I'm glad you gave some background...You could use JNA, but the easier way would be to execute a call to the command-line utility cacls. It's included by default in Windows XP installations, I believe, so it should do the trick for you. Try Runtime.getRuntime().exec("C:\\Windows\\System32\\cacls.exe"+options)
Check out the documentation here -> http://technet.microsoft.com/en-us/library/bb490872.aspx
I use the follow line:
Runtime.getRuntime().exec( "C:\\Windows\\System32\\icacls.exe \"%ProgramData%\my application" /grant *S-1-5-32-545:(OI)(CI)(W,M)" );
S-1-5-32-545 is the SID for BUILTIN\Users because the name work only on English systems. https://support.microsoft.com/de-de/kb/163846
This give the BUILTIN\Users write access to all files in the given directory independent which user has create it.
I want to create a program using Java for Automatically copied USB's data when it's insert to machine. How I do it?
There is no such thing as "USBs data", the very concept doesn't exist.
There is nothing specific in Java SE for do this job.
I may think of two ways to get that working:
Write a Java program that starts on boot (maybe a service), the prog scans continously available "drives" (D:,E:,F: ... in Windows, mount on Linux), the USB flash may be marked with a specific folder/file name (eg. COPY_USB_). That can be done with the File class.
Write a Java program that get invoked on plug-in. I know that can be done on Linux with hotplug-script support.