0

I want to deploy (create myapp.jar and from this .jar create myapp.exe file for installer) a java swing application.

I have a some packages:

  • resource package (net.myapp.ui.resource) inside i have .png, .wav, ... files)
  • output report package (net.myapp.ui.jasper.output.report) inside i have exported files (report1.pdf, report2.pdf, etc.)
  • config package (ne.myapp.ui.config) which contain config.properties file which can by updated after app have been installed because this file contain **persistence.xml** properties to create an EntityManagerFactory dynamically depending on the database server info.

From NetBeans IDE i can run app and it's work without problem; but when I build app, a .jar file is created: in dist directory i only have :

 --> myapp.jar
 --> lib folder

So i'm unable to access config.properties to setup database server IP and other parameters to be used in persistence.xml at runtime.

The question is : How do not put resources, output report, config ... in the classes package tree, but outside and access every resource from code using getResources() or getResourceAsStream() or ClassLoader ?

I want this strucure (after netbeans project build):

dist (folder)
  /myApp.jar
  /lib/lots-of-jar’s
  /config/config.properties
  /resources/my_cat.jpg
  /output/report/report1.pdf, ...
  ....

Thank you for your help.

aristos
  • 129
  • 3
  • 14
  • What exactly is the question? How to get this structure with NetBeans, or how to load resources? If the former: use a real built tool, like gradle. If the latter, just make sure the dist directory is in the classpath, and use `SomeClass.class.getResourceAsStream("/config/config.properties")` – JB Nizet Jan 08 '18 at 17:30
  • Thanks for your answer. Actually config.properties is in `net.myapp.ui.config` package. So I can read this config file easily with like this: `SomeClass.class.getResourceAsStream('/net/myapp/ui/config/config.properties')` – aristos Jan 08 '18 at 18:04
  • @JB Nizet, Thanks for your answer. Actually config.properties is in `net.myapp.ui.config` package. So I can read this config file easily with like this: `SomeClass.class.getResourceAsStream('/net/myapp/ui/config/config.properties')`. The problem is when a build my app netbeans create myApp.jar file with embed fonfig.properties files. So I can't have access the file to edit it. I want : 1) delete `net.myapp.ui.config` package, 2) create config folder within config.properties on project root, 3) tell to netbeans: when you generate myapp.jar, generate also config folder within config.properties – aristos Jan 08 '18 at 18:17
  • 1. is trivial to do. 2. is trivial to do. 3. is easy to do with a decent build tool: gradle, Maven, ant, etc. NetBeans is not a build tool. It's an IDE. – JB Nizet Jan 08 '18 at 20:30
  • Problem resolved see [read properties file outside jar file](https://stackoverflow.com/questions/8775303/read-properties-file-outside-jar-file). Thank you for your comments. – aristos Jan 10 '18 at 14:02

0 Answers0