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

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.

Related

Converted jar to exe file but not working after installation

I converted my first java swing app to exe using advanced installer and inno setup(Tried both no result).
Considering Inno Setup : on double clicking nothing happens
Considering : Advanced Installer -> On executing my app open but after providing credentials nothing happens so i assume it may be database issue.
About my app: It is a small swing based saving and retrieving data of employees payment.
Database used : MySQL
I had imported database schema to client PC and made .exe file of app so that after installing it can access data.
The Jar files runs successfully and able to access the data as well.
So i think while creating .exe is their anything to be done about database .
Please suggest me where i am mistaken .
Download Launcher4J Software and build Exe out of jar file!
This is the Best and all fixes will done!
I think this is more like an application issue rather than an installer generated one. Have you tried to debug your application code after it is deployed using a setup package?
Also, in Advanced Installer, under Java Products view of your project there is a Virtual Machine section where you can choose to save the output and error stream in a log file. The log file will be created at app runtime just beside the EXE launcher. Maybe this will help you to catch some errors logged.

How do I package a Java program for Ubuntu?

I have an application that currently a user downloads and runs an install script. I want to be able to take the JAR file and such that is generated by NetBeans and make it into a package that a user can download through a package manager. It needs to have menus implemented as well (the entries in the Debian menu that the user can click on).
Currently I am following through this tutorial: http://packaging.ubuntu.com/html/packaging-new-software.html
However, I am worried that I am going down some kind of rabbit hole in the wrong direction. Surely this must be something that is common?
What is the standard procedure for getting your JAR file to other people through packages?
I needed to:
Install dpkg.
Create a directory structure similar to how I would like it unpacked.
Create a shell script that would copy it there.
Run dpkg.

Java App unexpected behavior when exported

I have a very strange problem, that I can't figure out, the thing is that my aplication runs perfectly on the IDE (Eclipse), but not when exported, when I run the jar (double click) the aplication start but some functionality is missing (loading from a template file, but this does not happend when loading from a normal file), when I try to run it from console (java - jar my.jar) in order to see any error message it turns out that my aplication works perfectly fine! :S ...
Some more info:
My app is running over windows 7
I start the task manager, and I noticed that when I start my aplication using double click its under the name java.exe *32, and when I do it from command line its under the name java.exe (without "*32"), as far as I know I programmed nothing related to a 32 or 64 bits functionallity.
"Solved"
Well I was not able to solve it the way I wanted, as far as I was able to find, i found that there were a problem between the 2 java versions I was running x32 & x64, I deleted the 32 bit version and it start working as a charm, but I'm still not sure about what happend, I give my thanks to #Sajal Dutta one of its comments help me to understand part of the problem, thanks to all of you anyway, I'll keep searching until I find the problem...
When you create a jar from Eclipse, your assets don't get copied over to jar or location is not preserved. Open the jar and check if you have your templates in the right location or you have it at all.
To have the exported jar include your assets/resources-
Right click on your project in Eclipse. Then New -> Source Folder.
Name the source folder anything. e.g. template_src.
Copy or drag the entire directory of your template to template_src. Then make the jar.
Since it works via the command line but not when double-clicking the jar, it is likely that the working directory is different (and that you're loading the template with a relative path). When you run an executable jar by double-clicking, on some operating systems, the working directory is the home directory whereas when you run from the command line, it's the directory you're currently in.
The "files" in the jar are not handled by File, but are resources;
URL url = getClass().getResource("...");
InputStream in = getClass().getResourceAsStream("...");
Then, the file paths inside a jar, or on a non-Windows platform are case-sensitive.
"Template_A.xml"
is not
"template_a.xml"
Also you might inspect the jar with 7zip or WinZip.

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

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.

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

Categories

Resources