11 Replies Latest reply: Nov 7, 2011 2:42 PM by 898268 RSS

    problems with distributing java applciation

    898268
      Hi,

      I'm having some problems which I hope you could help me with. I just finished my first desktop application in netbeans, and now I would like tot est it on another computer. The application uses also other .jar files (libraries). I found some instructions on the internet on how to make an executable .jar file, and I did it. The file is now on my computer. Then I zipped myApp.jar and the ldirectory lib, where other .jar files are located and unzipped this into a folder on another PC.

      On my computer it runs properly. If I run it from cmd with the command java -jar myApp.jar, it works and it also works if i double click the myApp.jar file. But it doesnt work on another PC. I checked the java version, it wasn't ok so I updated it, but it still doesnt work. In task manager I can see that when I run the file, for approximatly 30 seconds the javaw.exe appears like the program is trying to run, but then it dissappears, like something went wrong.

      Here is the manifest, which is in myApp.jar file:

      Manifest-Version: 1.0
      Ant-Version: Apache Ant 1.8.1
      Created-By: 1.6.0_22-b04 (Sun Microsystems Inc.)
      Main-Class: virtcomui.VirtcomGUIOsnova
      Class-Path: lib/beansbinding-1.2.1.jar lib/jcalendar-1.4.jar lib/mysql
      -connector-java-5.1.17-bin.jar lib/sqljdbc4.jar lib/edtftpj.jar lib/l
      og4j-1.2.16.jar
      X-COMMENT: Main-Class will be added automatically by build

      What am I doing worng? I woudl like it to start running on just a double-clicl, so it is friendly to the user (no using of command prompt or thigs like that).

      Thans for the help.
        • 1. Re: problems with distributing java applciation
          898268
          I solved the problem above already, it was my source code that was the problem. But I have another question... When I build my project to a .jar file, the properties file that I'm using to store some information is not in it... I tried all possible ways of doing it (i searched on the internet), but I can't seem to solve the problem...

          Say my project folder is named MyProject and it contains a src folder, where all my packages are, and in a package called virtcomui I have my main class called MainClass.java. Where should I put the properties file (let's call it foo.properties), so that I'd be able to include it in my jar, so that when I run the program on another computer it can read and store data in the properties file? And then how do I load the properties file in my source code?

          I tried putting the foo.properties in to the src folder (src/foo.properties), and when I build it in a .jar, if I unzipped the jar it was directly in the jar root. But I could not access it from my program. It keeps saying it cannot find the file...

          Please, help, I don't know what to do anymore.

          Edited by: 895265 on Nov 6, 2011 2:05 PM
          • 2. Re: problems with distributing java applciation
            EJP
            If it's in the JAR file it's a resource, not a file.
            • 3. Re: problems with distributing java applciation
              898268
              So I read it using ResourceBundle and this works, but how do I store values in it then?? which method, which class?
              • 4. Re: problems with distributing java applciation
                EJP
                You don't. The JAR file is read-only. It's not a file system.
                • 5. Re: problems with distributing java applciation
                  898268
                  Sorry, but could you at least point me to the right direction here pls? When I run the program, I read some information from the database and I need to store them to my properties file. So then how could I do this, to be able to read and write into the file? Maybe have .properties outside the .jar, in the lib folder? Or where? And then how to I access it??

                  Unfortunately only a yes/no answer isn't really what I need, I need some ideas or instructions on how to do this to make it work, since I obviously can't figure it out myself.

                  Thanks.
                  • 6. Re: problems with distributing java applciation
                    796440
                    895265 wrote:
                    Sorry, but could you at least point me to the right direction here pls? When I run the program, I read some information from the database and I need to store them to my properties file. So then how could I do this
                    Why do you need to store them in a properties file if they're already in the database?

                    Assuming you really have this requirement and you can't change it, some options are:

                    1) Make the properties file a temp file that gets re-created on each startup. (See the two createTempFile() methods and the deleteOnExit() method in java.io.File.)

                    2) From the DB or from a System property (specified with -Dprop=value at startup), obtain a location on the file system where you can write the properties file.

                    3) Use java.util.prefs instead of a properties file.
                    • 7. Re: problems with distributing java applciation
                      gimbal2
                      jverd wrote:
                      2) From the DB or from a System property (specified with -Dprop=value at startup), obtain a location on the file system where you can write the properties file.
                      Or for an incredibly simple solution, create the file in the user home folder (System.getProperty("user.home")) which is guaranteed to exist and write-enabled and is of course bound to a single user only in stead of all users on the system.

                      You'd reason that it is bad practice to pollute the user home dir with config files, but so many apps, Java or otherwise, already do so anyway :/
                      • 8. Re: problems with distributing java applciation
                        DrClap
                        gimbal2 wrote:
                        You'd reason that it is bad practice to pollute the user home dir with config files, but so many apps, Java or otherwise, already do so anyway :/
                        If you did have that twinge of guilt, you could create a folder in the user's home directory where your application could dump all its rubbish, I mean store its config file.
                        • 9. Re: problems with distributing java applciation
                          898268
                          Mostly I need the properties file to save some decisions my user will make. Like for instance, when he tries to open a scan, he can choose a folder with his scans and he will see this folder every time he opens file chooser. And the program needs to remember what the user has chosen even after the user exits. And I can only do that with properties file as far as I know.

                          What about the option of reading a .properties file from .jar. For instance, i have a .jar file which contains my classes. The .jar file is in a directory called InstallationFolder, and the .properties file is there also. So the structure would be sth like this:
                          InstallationFolder/
                          myApp.jar
                          lib/
                          filename.properties

                          In myApp I have a mainClass, which contains a method writePropFile and readPropFile. Could I access the properties file from these two methods from mainClass? How could I include the .properties file classpath to mainfest file? Because now netbeans creates manifest file on it's own and classpath only includes libraries.

                          Could sth like that work? How could I access the properties file then?
                          • 10. Re: problems with distributing java applciation
                            796440
                            895265 wrote:
                            Mostly I need the properties file to save some decisions my user will make. Like for instance, when he tries to open a scan, he can choose a folder with his scans and he will see this folder every time he opens file chooser. And the program needs to remember what the user has chosen even after the user exits. And I can only do that with properties file as far as I know.
                            Databases can do that as well. So can java.util.prefs.
                            What about the option of reading a .properties file from .jar. For instance, i have a .jar file which contains my classes. The .jar file is in a directory called InstallationFolder, and the .properties file is there also. So the structure would be sth like this:
                            InstallationFolder/
                            myApp.jar
                            lib/
                            filename.properties
                            You can read from the jar, yes, but you cannot write to it. It's not a file system. I thought this was your problem in the first place--that you knew how to read from a jar but were trying to write to it as well.
                            In myApp I have a mainClass, which contains a method writePropFile and readPropFile. Could I access the properties file from these two methods from mainClass? How could I include the .properties file classpath to mainfest file? Because now netbeans creates manifest file on it's own and classpath only includes libraries.

                            Could sth like that work? How could I access the properties file then?
                            You can read it if it's on your classpath, using getResource or whatever, but you can't write to a classpath resource.
                            • 11. Re: problems with distributing java applciation
                              898268
                              Ok, I will try with java.Util.pref and tell u how ti works. Thanks, I'm still a beginner in java, so thanks for the patience :)