0

Project is Developed in Netbeans IDE in Java Language. Database connected to it is MySql that runs using Xampp. The project is complete. Now I want to launch it. I do not know.. 1. How to create the setup which will install this project on clients Windows. 2. How this setup will use the database that I have created and Install it on clients PC. 3. How the database will start automatically on his PC as on my PC I have to run Xampp manually first in order to make connection through code with project.

I have tried using clean and build but when I run that result file it waits for a second and then nothing happens.

Nothing appears on screen when I run build file unlike when I run my project in Netbeans. How to solve this issue?

1 Answers1

1

The database and xampp are two different things. Xampp provides a database (MariaDB if im not wrong) and thats all. Java doesn't create "installable" outputs. it creates a jar which can be run with java (something like java -jar your-jar.jar )

So for your setup you can either install xampp and use its database or install a database as a standalone service and use it. The boot with the system depends on the database but xampp is the easiest as you have to boot the db when xampp opens and you can put xampp to open when windows startup.

As for the jar file it depends on what your program does. Is it a service? then it needs to start-up on its own and you will need to provide a service for windows. Is it an app that a user will run? Create a wrapper or a configuration that will setup the system to run jar files with double click as the user shouldn't need to learn java -jar the-jar.jar ( have a look at this Running JAR file on Windows )

Lastly about the db / java connection. If your program does not require the database to start up then try to "Delay" the call until its needed. Else you will need to create a retry logic to try and connect to the database after a failure instead of failing the program.

I hope that helped!

Michael Michailidis
  • 1,002
  • 1
  • 8
  • 21
  • Okay! Firstly, I have created .jar file of my app(not a service) and it does not open as nothing happened. Secondly, my app (Store management system with login and things like that) is connected to MySql database file which has been created using Xampp app and runs only when I start Apache and Admin from Xampp. we can work on why my .Jar file is not running first, then we can move on to database part later because it happens to every jar file which is not even using database. –  Aug 06 '19 at 10:32
  • when you write java -jar your-jar.jar what is the console response? Thats the baseline to see if your compile was correct – Michael Michailidis Aug 06 '19 at 10:34
  • C:\Users\Zayn Jutt\Documents\NetBeansProjects\App\dist>java -jar App.jar Run Exception in thread "main" java.lang.NoClassDefFoundError: org/netbeans/lib/awtextra/AbsoluteLayout at app.Look.initComponents(Look.java:34) at app.Look.(Look.java:18) at app.App.main(App.java:7) Caused by: java.lang.ClassNotFoundException: org.netbeans.lib.awtextra.AbsoluteLayout at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) –  Aug 06 '19 at 10:44
  • This is another simple project I just created to test whether only my project.jar isn't running or every .jar file isn't running on my Laptop. So, This also did not run meaning my every Jar file isn't running. I showed you the error of this new project which I ran through cmd. –  Aug 06 '19 at 10:48
  • This means that it cannot find a class. So its a classpath error. Do you use a build tool for your project? ( please say yes :P ) You will need to configure it to include everything in the classpath and create something called "fat jar" – Michael Michailidis Aug 06 '19 at 10:49
  • This is the error in my main project. C:\Users\Zayn Jutt>java -jar "C:\Users\Zayn Jutt\Documents\NetBeansProjects\Store Management System\dist\Store_Management_System.jar" Exception in thread "main" java.lang.NullPointerException at java.desktop/javax.swing.ImageIcon.(ImageIcon.java:217) at store.management.system.LoginMenu.initComponents(LoginMenu.java:146) at store.management.system.LoginMenu.(LoginMenu.java:20) at store.management.system.StoreManagementSystem.main(StoreManagementSystem.java:8) –  Aug 06 '19 at 10:57
  • I did not use any build tool for my project I just click on clean and build project which creates the .jar file in dist folder along with libs filder which contains all imported libraries. –  Aug 06 '19 at 11:00
  • This is a nullPointerException meaning it cannot find the image for your ImageIcon constructor. Your resources should be either be in the resource folder or in a predefined folder in the system which you will have to create and populate in some way – Michael Michailidis Aug 06 '19 at 11:00
  • how can i configure this to create fat jar? –  Aug 06 '19 at 11:01
  • Then you will need to check that the output jar does have all the dependencies / resources packed with it. A build tool simplifies this job as it contains multiple plugins that make your life easier ( Like Maven / Gradle ) – Michael Michailidis Aug 06 '19 at 11:01
  • this.setIconImage(new ImageIcon(getClass().getResource("/sms.png")).getImage()); i think it is showing null pointer exception for this case right? but when i run the code in the Netbeans it runs normally. PS: I have created a folder for images and I am using all icons form there. –  Aug 06 '19 at 11:05
  • I don't know about these tools I created this project as simple java application and just kept on creating new JFrames and JPanels and they run from a object from previous Frames and like that. you know I have worked really hard for this project and it works fine but not in jar file mode. All i need is to deploy this as soon as possible but jar is not working. So what do I need to do about this now? help me please I stuck here for almost a week now. –  Aug 06 '19 at 11:12
  • yes because NetBeans add extra things when you run it. Also it doesn't run the project from jar but directly from classes. ( look in your /target and you will see all the compiled classes ) . To load resources from jar you need getResourceAsStream – Michael Michailidis Aug 06 '19 at 11:12
  • where is this "/target" ? can you please explain a bit about getResourceAsStream? I mean obviously i don't know this and I showed you the code I wrote but it has a problem with .jar but not netbeans. So, Can you suggest me something that will solve this jar issue and teach me about how to load resources for jar? this is just the start what if there are other errors for jar which seems normal in netbeans because i have a really big project. –  Aug 06 '19 at 11:23
  • when you run your project from netbeans there is a new folder created which works as temporary dir for your compiled data to go. This link shows you how to load resources from your jar https://stackoverflow.com/questions/20389255/reading-a-resource-file-from-within-jar. Errors like "nullPointerException" are pretty straight forward to find with a debugger and can be caused by a lot of ways. You were kind of lucky that this one was obvious without the code to tell you were it was originated. – Michael Michailidis Aug 06 '19 at 11:30
  • try { this.setIconImage(new ImageIcon(getClass().getResourceAsStream("/sms.png")).getImage()); } catch (Exception e) { // System.out.println("RunError"); } this is not possible because getResourceAsStream cannot be converted to string as getResource only returns string –  Aug 06 '19 at 11:49
  • Well you are trying to convert an inputStream to a String. You should try and reading a bit more around this convert and look in your debugger as it gives a lot of helpful tips – Michael Michailidis Aug 06 '19 at 12:37
  • ok I have checked in my project I assigned these icons to labels using label properties graphically in Netbeans. But these icons are inside a Images folder in this project. There are a lot of icons like this in this project and the code behind these is written by Netbeans itself and it is not editable because I added these icons graphically. If this is preventing the jar file from running. Then what is the point in placing these options at first for users? I think there is a way around and we are missing something else. Can you help me understand what is that? –  Aug 06 '19 at 13:04
  • We are really getting close for me to actually see code. I have to work with Netbeans since 7 was released so I am not really familiar with its ways. The UI is supposed to help users but not replace the whole work. Also it may assume you load the icons from external resource so the jar wont be huge due to the resource files. Try to remove the icons from the graphic environment if you cant edit them and recreate them with code. – Michael Michailidis Aug 06 '19 at 14:04