HSQLDB lock file in programs and files - file directory write permission - java

I have an application in JAVA that connects to HSQLDB and need to be installed, i made that app and works fine, but when i put my code on the Programs and files folder, the HSQLDB cannot edit the lock property and cannot open the software =(
i know that is Windows security, but, is there a way to make the folder who contain my database editable?(c:programs and files\mySoftware\database) Like in PHP, using chmod...
Thanks!

You are using the wrong approach. Instead of making a folder editable, you need to put your files to application-specific folder under \Users\All users\AppData\yourapplication (in Windows 7) or \Users\Profilename\AppData\yourapplication folder. The path to this folder is obtained via Windows API (don't know what Java offers in regards to Windows-specific API, sorry) function named SHGetFolderPath. You need CSIDL_APPDATA or CSIDL_COMMON_APPDATA paths there.

Related

Java application requires Admin Access to run when placed in Program Files

I am working on a Java (JavaFX) desktop app. I am converting it to exe with launch4j tool and then later creating a setup package using Inno Setup Compiler (default installation path set to C:\Program Files (x86))
The application itself don't need any admin privileges and runs fine when I copy the exe on desktop or run it on drives other than C. (Also works fine if I run it in local appdata folder)
But I need to place it in Program Files (x86) directory.
The app doesn't open if I install it in that directory so I had to create a manifest file for launch4j so that it asks admin access each time it opens. It works fine that way but admin access is asked everytime in this case.
I need to make this application run without asking admin access each time.
If there is any solution, please guide me through it.
Any help will be appreciated.
Ok so I kind of figured that out. I guess the jar was having trouble reading from system directories and I had to do some read/write operations on a config file. So I changed the config path to:
String path = Controller.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "\\Data\\";
Now it creates a folder named "Data" inside jar file and read/write from there. I don't know if this is a bad practice or not but it seems to work pretty good for me.
Thanks a lot to #user31601 who gave me some hint that helped me figure this solution out.

Access derby database in executable jar

I have been looking for a while now but haven't found exactly what I want. So, I have a project written in Java and have created a small Derby database that I have embedded in the project. Now when creating an executable jar of the project, I cannot access the database anymore unless I put the derby database files in the same directory of where the executable jar is located. However, I do not want this, I really want that the database files are INSIDE the jar.
I have tried to put the database files in a package and reference it like that, without any luck. Could someone point out how I can get this to work please?
Thanks!
EDIT
The goal here is that I want to create more than one executable JAR file and upload them to a Sun Grid Engine and execute each jar with different parameters. However, they all need to be able to access the database and until now I get an error when 1 application already booted the derby database, another application cannot access it. Therefor ALL jar files need to have their own database.
Do you use the jdbc:derby:jar protocol to access your database?
According to the documentation what you're after should be possible.
Inside your app (the one going into the executable jar) you must access the database using the jdbc:derby:jar protocol.
Create the database with the desired content.
When you have built your jar, you can use jar commands to add the database dir to your jar.
All of this could go in your build script, obviously..
There may be issues related to jar sealing and such, YMMV.

Java Web Start and Folders

We currently have an Java application that can be deployed on clients or run as a shortcut from the server. We have intermittently received ClassNotFound exceptions when running the JAR from the server which looks like Windows dropping the network connection with only part of the classes from the JAR loaded (user opens a different screen then the problem is apparent).
I am currently looking at the Web Start technology to allow us to run a single shortcut.
However the application has several folders it requires to be in the same folder the JAR is launched (for configuration, logs, etc.). These folders will require full access for all users to allow them to write log files. There are lots of configuration files under the configuration folder hierarchy.
The application also requires access to environment user settings (such as getting their user folder). It also requires certain command line parameters (including which folder to use for configuration, log file location, java memory usage, etc.)
Edit
The application also contains a reference to 2 signed JARs. These are:
jh.jar
mail.jar
It looks like these are signed by SUN Microsystems. jh is used for help integration in our application whilst mail is used for email integration.
I have now downloaded the latest versions of these files from java2s.com which do not have the signed equivalents.
end edit
The application is developed in Netbeans which compiles a single JAR file and copies the dependant JARs to the dist/lib folder. I enabled the Web Start functionality in Netbeans for the application and it generates the JNLP file.
Bearing everything in mind is Web Start the way to go for an application like this?
Can you include folders in a Web Start deployment? I could not find anything to do this in the XML structure for a JNLP file.
Cheers,
Andez
Yes, you could use WebStart for this.
Permission:
If you need permission to the file system, you have to sign your jars and put the all-permissions tag in your jnlp.
Arguments:
Arguments can be provided by using the arguments elements in application_desc.
Folders:
I'm don't think you can include folders in the WebStart application, but you could put the config files in a jar and read them from there, or extract them on startup.
ClassNotFoundError:
We have intermittently received
ClassNotFound exceptions when running
the JAR from the server which looks
like Windows dropping the network
connection with only part of the
classes from the JAR loaded
Does not sound plausible to me. per default, all jars will be downloaded before the application starts. If you set "download" to "lazy", the jar will be downloaded when first needed, but I would guess it will be downloaded completly then.
You can provide read-only resources for Java WebStart. Getting the log back is harder. I would suggest looking into a centralized logging solution, using one of the standard appenders in the log framework you use.
For a Java Web Start application it is always advised not to create files or folders in the class path. Recommend user's home directory to store your settings or database files.

Permissions for Java application on Ubuntu

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

Dependency issues in deploying using Java Webstart

I am working on a project in Java which has a directory structure something like this:
MainFolder
/ | \
Folder1 Folder2 Folder3...
|
Program.jar|Run.sh
In Folder1 I have main jar file along with the shell script to run the program.
In Folder2 I'm having configuration files in xml which may later be modified by the program
and In Folder3 I'm having jar files that the main program depends on.
Now I want to deploy this program using Java web-start.My current understanding is that web start allows us to deploy programs using 1 or more jar files.My problem is that I need the directory structure also.Can anyone suggest a solution for this.
As mentioned by others, the shell script raises problems. What does it do specifically to 'run the program'?
For the configuration files - 'Folder 2', webstart provides the PersistenceService. I have a small demo. (1)
As far as the Jars in 'Folder 3' go. Move them, as well as the Jar's in folders 2 & 1 to a single directory named 'lib'. The main Jar and the configuration files will be required eagerly, which is the default for JWS. If any of the other Jars (ex. '3') might not be needed immediately or at all, they should be deployed as download='lazy'.
To access the local file system - for reading input supplied by the user or writing a new file they created - a JWS app. normally needs to be digitally signed and trusted. But JWS also provides the much more limited form of access through the FileContents object. For more details, see the demo. of the File Service in the page linked below. (1)
1) Demos of the JNLP API, including the PersistenceService & FileContents object.
I think you will have to make some changes to the structure for webstart deployment (possibly package it as a jar or set of jars), also the launching will be done via JNLP, by webstart and not Run.sh.
Additionally you will have to sign your deployment if you need permissions to write to the disk.
See the FAQ for webstart here
Also check out the developer guide on how to deploy using webstart
Java WebStart does not provide any help in making the filsystem as you need it - it only provides the program components for memory.
If you need this structure, you will need to maintain it yourself (and then, where?)
If the only thing you need is a shell script to run, you can keep the contents of that file as a resource inside your jar, create a temporary file at each run, put the desired contents inside, and execute it, and then delete the temporary file when you are done. Note that this brings you into the wonderful world of code signing which is rather tedious.

Categories

Resources