I am writing an application in Java 8 at the moment and have hit a critical point.
Thus far I have got 3 jar files with the following functions:
- JavaFX GUI
- BaseX Database API which can query a BaseX database, create and run queries, and use JAXB to translate xml into Java Objects
- An abstraction for converting database output into MS Word or MS Excel documents
- 1 Jar per implementation of the above.
My brain starts to melt when putting all of these into a single application.
Do I keep these as separate jars (projects in Netbeans)? Or is this what the Java 9 module system designed to solve?
It is difficult to say anything without knowing the application design (functionality and packaging) and the size. Also, how it is designed and the various components interact with each other.
If its a small application one can put the application together into a single jar file. For example, I have had an experience working with a small GUI application which stores data in a database. The application had about 80 classes organized in 6 packages. I had the application in two jar files one has the application's classes and a database implementation jar file. The application also had components like user manual and icon files. The application needed a JRE to run it by a user. It was sufficient that way for that application.
About using Java 9: It needs good understanding of how the modularity works and also various features provided by it - to think, design and implement an application using the module system. It needs a good study of how that system is to be used. I don't have any experience about using it yet. But, I have been studying and this is my first thought about it.
What, specifically, is the issue that you're uncertain about? Lots of applications consist of multiple jar files. If for some reason you need them packaged into a single jar file, then there are tools that will do that for you. That in itself is not a reason to combine them into a single NB project, or to consider modules.
That sounds to me like an application still in development; do yoiu need it in separate .jars? Can you unzip the .jars and then reassemble them into one .jar? It does sound that making the GUI .jars accessible only as “internal” parts of the app might be a good idea, in which case modules would help.
How much do you know about modules?
Campbell Ritchie wrote:It does sound that making the GUI .jars accessible only as “internal” parts of the app might be a good idea.
If this was a library to be called by other people's code I could see a benefit in hiding the internal classes from client code. But for a GUI app - the code of which is unlikely to be called from elsewhere -, not so much.
Thank you all for your responses... I think I was suffering from "analysis paralysis", and it has helped me go in a firm direction.
As it is just me coding this application, I think I was overcomplicating the design of a relatively small piece of work. I decided to merge all the packages from the various JARs into one larger JAR. Seems I was getting into bad habits with grouping classes by packages and had many more packages than I realised (some with 1 or 2 classes in).