Checking file permissions for a specified user account in Java - java

I'm running a Java application as a Windows Service and am using another Java application, which is executed by another user, to set a directory used by the Windows Service application.
Is there a way in Java to determine the file permissions of a directory for another user? In my case, I want to know the file permissions of the Windows Service application while running a separate Java application executed by another user.

This kind of filesystem support is not available in standard Java, because Java is cross-platform and filesystem security differs greatly across platforms (or may not exist at all). However, there are plans to add this support to Java 7 (which we have been waiting for years to get!)
If you are only using it on Windows and you know C/C++, you can use a JNI (Java Native Interface) like JNA to tap into the Windows DLLs and get this information. Otherwise, you can get a trial or a paid version of JNIWrapper which works out-of-the-box. I'm not sure if it provides support for file security, but it does provide other filesystem support - you'll need to review the feature list.

Related

How to register JAVA executable as Windows Service in Windows 10

All of the solutions I found on stackoverflow suggest wrappers to register java application as windows service. My requirement is totally different. Please don't suggest wrappers for the purpose. The question is very simple I have java executable and I want to register it as windows service.
Phyiscal Path
Service Properties
Unfortunately we don't have backup of previous setup that installed it as windows service at the first place. Do I need some setup program or anything like that.
Not necessarily.
It is difficult to advise you on precisely what you need to do without more information on what you actually still have; e.g. an application installer, application JAR files, wrapper scripts, etc. Alternatively, if you told us what the application was, then maybe we could give you some hints on where to get installers, etc.
However, I can tell you definitely that registering java.exe or javaw.exe directly as a Windows Service will not work. These are not the executables for your Java application. Rather they executables for as Java Virtual Machine that will run your (real) Java application.
It is so easy task in case of Visual Studio. I want same support in Eclipse or anything else.
Well Java doesn't work like that. Java compiles to platform independent bytecode files, not to platform-specific native code. Sure, there are third party tools to generate exe's. However, using them is neither necessary, or desirable:
Why is creating an .exe from a java program not recommended?
(And asking for recommendations on what tools to use to do this is off-topic.)
Finally, if you take an arbitrary Java program and turn it into an ".exe" file, it won't necessarily be immediately registerable as a Windows service. This Q&A talks about turning an ".exe" into a Windows Service.
Create Windows service from executable
However, I can't tell you if the advice given there is appropriate for an ".exe" file created from an arbitrary Java app by some unspecified 3rd-part tool.
My recommendation:
If you are starting from scratch, use a Java Service Launcher / Wrapper.
If not, talk with whoever supplied and/or installed this application in the first place.
If you can't find any information about the application and where it came from, or if the vendor has gone out of business ... you need to urgently look for an alternative.

Using Java Web Start with JavaFX's Native Bundles

I have developed a JavaFX app and I am going to distribute it as a Native Package to avoid headaches with users having a Java version lower than 7 (and thus, without JavaFX) or having no Java at all.
However, I also want to be able to deliver updates of my application. One solution is for the app to call home (its already communicating with the backend via XMLRPC), fetch a JAR and self-update. I can see potential problems with the actual update process though (would need to build a separate updater program, but how do you update the updater?).
I know about and would love to use Java Web Start. However, I have no idea if this will work with the Native Package thing. If the user already has Java installed, it will disregard my bundled JRE. If he has no Java... well, he can't use Java Web Start, right?
How can I solve this problem in an elegant way that will not have a detrimental effect on user experience? (and preferably won't be very long to implement)
note: I am using e(fx)clipse as build tool.
If he has no Java... well, he can't use Java Web Start, right?
True, but as mentioned in the JWS tag Wiki:
Java Rich Internet Applications Deployment Advice. Describes the deployJava.js
script designed to ensure a suitable minimum version of Java is installed before
providing a link to a
JWS app.
or launching an
applet.
Note that JWS also offers fine grained versioning as detailed in Java Web Start - Runtime Versioning.
Saying that, JWS can allow you to support earlier systems by adding the JavaFX 2 API selectively to those earlier systems. That is achieved using a version based resources section in the launch file.
So, JWS combined with deployJava.js would actually be 'the alternative' to the Native Package that page discusses.

"virtual" files

I want to create a "virtual" file that, when accessed, will be d/l (by my background application). This should work if the file is accessed by windows explorer, or by other application (e.g Microsoft Word...)
What is the best way to implement it?
EDIT:
Can this be implemented by Shell Extensions?
It sounds as if you're about to write a virtual file system driver. That's a pretty hard task in pure C, limited debugging support and many reboots.
If I'm not mistaken, the task is so hard that there are several commercial offerings that provide tools and libraries that considerably simplify the implementation.
Update:
A starting point is Microsoft's Installable File System Kit, which is a part of the Windows Driver Kit.
What you're describing sounds a lot like WebDAV. There are already servers that support this protocol (including Apache), and Windows appears to support it either natively or via an add-in feature.
You can also choose to implement an CIFS/NFS server instead. I don't know about the current state of Alfresco's JLAN, but they did open source (some of?) the code. Perhaps ask for an update here: Open Java SMB server implementation

Java Desktop application

This is a single question, but with a couple of sub questions. I am planning a Desktop application using Java and I am using NetBeans as the IDE. Questions:
Why are there so many versions of Java? Java, Java SE, Java EE, Java Me
I want the application to store data locally, what is best Java DB or SQLite?
Do I need anything extra to create a setup file for my clients to install the application?
Is it there a Java solution similar to .Net OneClick to keep the clients updated to the latest version of the application?
I have plan to run the application in Windows, but if I have to ported to Mac or Linux how hard can it be?
There are different java libraries for different purposes. Java ME for instance, is designed for cell phones / mobile devices. You'll probably be fine with java SE, unless you need some of the features from EE.
Depending on how complex your data storage is going to be, you may not even need a "database." In java, any object which implements the "serializable" interface can be written directly to a file. So, if you're just trying to store things such as user settings, etc, you can create an object to store them, implement Serialiazable, and write it to disc.
Only if your application links to code libraries which you don't want packaged in the same directory. You can package it as a self-executing JAR from netbeans, it'll be similar in function to an .exe
(Shrug.)
If you are careful not to use operating system specific paths, a self-executing jar will work immediately on any operating system with the JVM installed. There may be a couple other quirks, but Java is built to be extremely portable.
Because you don't really need everything everywhere. For example you don't really need to use GPRS or SMS from you computer, or ORM from you phone. Each edition is targeted to a specific environment. This way you can have a lighter environment for mobiles, and a lot more components for enterprise applications (which you don't really need of a standard application).
I would advise you to use JavaDB (or Derby) but it really depends on you
Not really, you could offer a nice solution to install your application, but it's not necessary.
There is (I don't remember, but other answers will certainly help)
It's really easy, in particular for unix application, the executable creation will basically be a .sh file launched directly (you could of course have a real executable on UNIX, but it's really common and easyier to maintain to have .sh files) (you could also use .bat file on windows, but let's say that's just less common)
I re-read the question and might have not really answered the last point (I was still on .exe creation) so here is a second shot :
5.It's the main goal of java, to be ported everywhere. As long as your code doesn't use specificity of your system (or it's protected with ifs) your code will work everywhere. Of course you have to use the same java edition (edition, not version) and the same libraries or you could have problems.
Why so many Javas? Java, Java SE, Java EE, Java Me
So many environments. The first two are desktop, EE is server side, ME is phones.
..3. Do I need anything extra to create a setup file for my clients to install the application?
Use Java Web Start.
That also covers 4. & 5.
I have no opinion on which is the 'best' DB, but note that for small amounts of data, JWS provides mechanisms where even sand-boxed apps. can store and retrieve information, alternately the installer-desc element can be included in the launch file to install/set up the DB.

How to distribute a Java desktop application?

What is the alternative to distributing Java?
I don't want to add JRE in my extracted files.
I don't want to give away my .jar file to the user.
The end user just install and use application.
Which database to use so that the user don't need to configure like SQL Server.
How to decrease execution time of my application? It takes more time to execute.
Edit
It is an application without a database.
There should be a setup file which installs in Program Files and shortcut on the desktop and some registry entry to start it with start up application.
You can deliver Java desktop apps as Applets and (more recently) Java Web Start apps. Using these technologies means that users don't need to manually handle files.
As for RDBMS, there is a pure Java RDBMS going by the names JavaDB and Derby which might meet your needs.
There are many ways to improve the execution time of a program, it depends on what you've coded and what it does, for a start. I think you'll need to ask a specific question on that to get a useful answer.
Java Web Start works well as a distribution mechanism. Host the .jar on your site and your clients can download (provided they have a JRE). It'll select the appropriate JRE to use and allow you to update the application at your end with automatic downloads.
If you want a database, check out JavaDB. It's pure Java and comes as standard with Java 6. Your application can check for an existing db on start-up, and initialise/configure if not present. That will then remain for future invocations.

Categories

Resources