I have been trying to package my javafx application for windows but every time I run the programm after packaging it just don't run as expected and end up giving the error "child process exited with code 1"
here is my code inside the controller class
`
@Override
public void initialize(URL url, ResourceBundle rb) {
Calendar calendar = new GregorianCalendar();
Date toSql = calendar.getTime();
lblCopy.setText("Copyright \u00a9"+df.format(toSql)+",All right reserved.");
try {
splashView();
} catch (InterruptedException | SQLException | IOException ex) {
Logger.getLogger(SplashController.class.getName()).log(Level.SEVERE, null, ex);
}
}
//threads for the splash screen
public void splashView() throws InterruptedException, SQLException, IOException{
//doTasks();
}
//using the task class implementation
public void doTasks() throws InterruptedException, SQLException, IOException{
createEnvironmentOnStart();
verifyDatabase();
TaskExecuter tasker = new TaskExecuter();
Thread thread = new Thread(tasker);
thread.isDaemon();
thread.start();
progBar.progressProperty().bind(tasker.progressProperty());
progressLoading.textProperty().bind(tasker.messageProperty());
tasker.setOnSucceeded((WorkerStateEvent event) -> {
// create a new thread to run another task
Thread thread1 = new Thread(() -> {
//executeMain();
Platform.exit();
});
thread1.start();
});
}
// loading the main App dashboard.
public void executeMain(){
Platform.runLater(() -> {
try {
Parent root =FXMLLoader.load(getClass().getResource("/SalesDataSheets/sds.fxml"));
Scene scene = new Scene(root);
Stage stage = new Stage();
stage.setScene(scene);
stage.setTitle("SalesDataSheets\u2122");
stage.getIcons().add(new Image(SalesDataSheets.class.getResourceAsStream("images/sdslogo.png")));
stage.show();
splashPane.getScene().getWindow().hide();
} catch (IOException ex) {
Logger.getLogger(SplashController.class.getName()).log(Level.SEVERE, null, ex);
}
});
}
//checking for expiredate and out of stock goods.
public void verifyDatabase() throws SQLException{
Calendar calendar = new GregorianCalendar();
Date toSql = calendar.getTime();
TreeMap<String,Date> expireNote = new TreeMap<>();
TreeMap<String,Integer> outstokeNote = new TreeMap<>();
msgToMsg = new ArrayList<>();
con = DriverManager.getConnection(newDB);
state = con.createStatement();
rs = state.executeQuery(sql2);
while(rs.next()){
String prod = rs.getString("product");
int stoke = Integer.parseInt(rs.getString("stoke"));
Date date = rs.getDate("Expire_Date");
if(date != null){
expireNote.put(prod, date);
}else{
expireNote.put(prod, null);
}
outstokeNote.put(prod, stoke);
}
Set<Map.Entry<String,Date>> me = expireNote.entrySet();
Set<Map.Entry<String,Integer>> mu = outstokeNote.entrySet();
for(Map.Entry<String,Date> element : me){
String prod = element.getKey();
Date date = element.getValue();
long interval =(date.getTime()-toSql.getTime())/consta;
if(interval > 30){
System.out.println("The product "+prod+" is still at safe zone");
}else if((interval>=0) && (interval<30)){
System.out.println("The product " +prod+" is about "+interval+" days to expire");
String nearlyExp = "The product " +prod+" is about "+interval+" days to expire";
msgToMsg.add(nearlyExp);
}else{
System.out.println("The product " +prod+" has expired for about "+interval+" days now,please remove it from the DataBase");
String Expired = "The product " +prod+" has expired for about "+(-1*interval)+" days now,please remove it from the DataBase";
msgToMsg.add(Expired);
}
System.out.println(interval);
}
for(Map.Entry<String,Integer> element : mu){
String prod = element.getKey();
int stoke = element.getValue();
if(stoke>50){
System.out.println("the item is still available");
}else if((stoke>0)&&(stoke<50)){
System.out.println("The product "+prod+" is about to be out of stoke, for now only "+stoke+" items has remained");
String nearlyOut = "The product "+prod+" is about to be out of stoke, for now only "+stoke+" items has remained";
msgToMsg.add(nearlyOut);
}else if(stoke ==0){
System.out.println("The product "+prod+" is OUT OF STOKE");
String Out = "The product "+prod+" is OUT OF STOKE";
msgToMsg.add(Out);
}else{
}
}
System.out.println(msgToMsg);
}
public void createEnvironmentOnStart() throws IOException, SQLException{
//here all the files that are associated with the program resource and storage are created on first installation
String dirPath = System.getProperty("user.home") +"\\Documents\\SalesDataSheets";
String maker = "CREATE TABLE Table1 (ID AUTOINCREMENT PRIMARY KEY,product TEXT(255),purchase CURRENCY,sales CURRENCY,stoke INTEGER,ExpireDate DATETIME)";
String maker2 = "CREATE TABLE Table3 (ID AUTOINCREMENT PRIMARY KEY,Product TEXT(255),Units INTEGER)";
String maker3 = "CREATE TABLE Table4 (ID AUTOINCREMENT PRIMARY KEY,Expense TEXT(255),ExpenseAmount CURRENCY)";
String maker4 = "CREATE TABLE Table5 (ID AUTOINCREMENT PRIMARY KEY,essuedAt DATETIME,totalSales CURRENCY,grossProfit CURRENCY,totalExpense CURRENCY,profloss CURRENCY)";
Directory = new File(dirPath);
dataBaseSub = new File(dirPath+"\\DataBase");
filesSub = new File(dirPath+"\\SalesDatum");
database = new File(dataBaseSub.getAbsolutePath()+"\\SalesDataDB.accdb");
if(Directory.mkdirs()){
boolean b1 = dataBaseSub.mkdirs();
boolean b2 = filesSub.mkdirs();
System.out.println("the file system created : "+b1+" : "+b2);
try (Connection conn = DriverManager.getConnection(newDB+";newdatabaseversion=V2010")) {
DatabaseMetaData dmd = conn.getMetaData();
try (ResultSet rs1 = dmd.getTables(null, null, "Clients", new String[] { "TABLE" })) {
if (rs1.next()) {
System.out.println("Table [Clients] already exists.");
} else {
System.out.println("Table [Clients] does not exist.");
try (Statement s = conn.createStatement()) {
s.executeUpdate(maker);
System.out.println("table 1 create successively");
s.executeUpdate(maker2);
System.out.println("table 3 create successively");
s.executeUpdate(maker3);
System.out.println("table 4 create successively");
s.executeUpdate(maker4);
System.out.println("table 5 create successively");
}
}
}
}
}else{
System.out.println("the file system is adequate");
System.out.println(System.getProperty("user.home"));
}
}
}
also the task excuter is nothing but this
public class TaskExecuter extends Task<Integer> {
@Override
protected Integer call() throws Exception {
int state = 0;
for(int i=0;i<=100;i++){
state = state +i;
updateValue(state);
updateProgress(i,100);
updateMessage("Loading..."+String.valueOf(i)+"%");
Thread.sleep(100);
}
return state;
}
}
jpackage --type exe --input . --dest . --main-class SalesDataSheets.SalesDataSheets --main-jar .\SalesDataSheets1.jar --module-path "C:\Program Files\Java\javafx-jmods-18.0.1" --add-modules javafx.controls,javafx.fxml --icon "E:\Netbeans\SalesDataSheet\sdsIcon.ico" --win-shortcut
any help to solve this will be appreciated because this part make my whole app to fail although everything is on ide running problems only after packaging.
I tried creating a different program and make the package and it work fine but not with the sql and threads on it.