1. I have a template template.docx
2. The program is supposed to create a word document , copy the template in and then replace some parts of the document.
When I execute it while coding, or using a jar , it works very well but when I make an .exe (I used jpackage) the program doesn t work.
I tried to find where exactly things go wrong. It seems the program dies on this line
Document doc= new Document();
It doesn't execute anything after this line. Can someone help?
This is the function that is called
- Code: Select all
public void buildFirstPart() {
System.out.println("Le systeme cherche la difference entre les K");
bigDifferenceWarning();
System.out.println("Le systeme commence a formuler les elements de path...");
String name=fioValue.getText().trim();
String[] nameS=name.split(" ");
String initiales=" ";
String dossier=nameS[0];
for(int i=1; i<nameS.length; i++) {
String str=nameS[i];
String toAdd=str.substring(0, 1).toUpperCase();
if(!toAdd.equals(""))
initiales+=toAdd;
if(i!=nameS.length-1)
initiales+=".";
}
if(!initiales.trim().equals(""))
dossier+=initiales;
String timeStam=new SimpleDateFormat("yyyy_MM_dd").format(Calendar.getInstance().getTime());
System.out.println("Tous les elements reunis on va creer un dossier à "+main.getDirectoryPath()+"/"+dossier);
File patientDir= new File(main.getDirectoryPath()+"/"+dossier);
if(!patientDir.exists())
patientDir.mkdirs();
else { //soit le patient exite deja ou les 1er nom se ressemble
System.out.println("Le dossier existe.. alors on verifie si c est le meme patient");
File[] files=patientDir.listFiles();
if(files.length>0) {
File file=files[0];
if(file.isDirectory()) {
File[] fs=file.listFiles();
if(fs.length>0) {
int j=0;
File f=null;
String n="";
do {
f=fs[j];
n=f.getName();
j++;
}while((n.contains("small") || n.contains("~$")) && j<fs.length);
if(!n.equals("")) {
String[] nomEtPrenom=n.split("_");
boolean same=true;
for(int i=0; i<nameS.length; i++) {
if(!nameS[i].equals(nomEtPrenom[i]))
same=false;
}
if(!same) {
int appendix=1;
String nomDossier=main.getDirectoryPath()+"/"+dossier;
boolean created=false;
do {
patientDir= new File(nomDossier+"."+appendix);
if(!patientDir.exists()) {
created=patientDir.mkdirs();
appendix++;
}
}while(!created);
}
}
}
}
}
}
System.out.println("Dossier cree de toute facon \n -- On va creer le sous dossier --la date du jour");
File sousPatientDir=new File(patientDir.getPath()+File.separator+timeStam);
if(!sousPatientDir.exists())
sousPatientDir.mkdirs();
String path=sousPatientDir.getPath()+File.separator;
String smallPath=path+"small_table_";
for(int i=0; i<nameS.length; i++) {
path+=nameS[i]+"_";
smallPath+=nameS[i]+"_";
}
String eye=valeurDeLOeil.getSelectionModel().getSelectedItem().name();
path+=eye+"_";
smallPath+=eye+"_";
String path2=path;
String path3=path2+".txt";
String timeStamp=new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(Calendar.getInstance().getTime());
path+=timeStamp+".docx";
path2+=timeStamp+"-stream.docx";
smallPath+=timeStamp+".docx";
System.out.println("on va creer les documents");
File document= new File(path);
File document2= new File(path2);
File textDoc= new File(path3);
try {
document.createNewFile();
document2.createNewFile();
textDoc.createNewFile();
} catch (IOException e) {
e.getCause();
}
if(smallTable.isSelected()) {
File smallDocument= new File(smallPath);
try {
smallDocument.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
this.smallFileName=smallDocument.getAbsolutePath();
this.buildSmallTableFirstPart();
}
fileName=document.getAbsolutePath();
System.out.println("On commence a chercher les parties remplacantes");
String[] toReplace= {"##fio##", "##glaz##", "##astigmatism##", "##k1##", "##k1ker##",
"##k2##", "##k2ker##", "##od_lenstar##", "##od_exo##", "##od_okt##",
"##os_lenstar##", "##os_exo##", "##os_okt##"};
String [] replaceWith= new String[13];
//populate the replace with--
[b]System.out.println("on va creer un document avec Spre Doc");
Document doc= new Document();[/b] [u] ---the exe program stops here[/u]
System.out.println("Document cree");
System.out.println("getting source as a stream and loading from file");
InputStream iolTable=IolMain.class.getResourceAsStream("sources/iolTable.docx");
doc.loadFromStream(iolTable,FileFormat.Docx_2013);
System.out.println("Loaded - start replacing");
for(int i=0; i<13; i++) {
doc.replace(toReplace[i], replaceWith[i], true, true);
}
System.out.println("Replacing finished");
doc.saveToFile(fileName);
}
=> RESULT when executed from jar or code
///
Le systeme cherche la difference entre les K
Le systeme commence a formuler les elements de path...
Tous les elements reunis on va creer un dossier à C:\IOLS/Kigdoi
Dossier cree de toute facon
-- On va creer le sous dossier --la date du jour
on va creer les documents
On commence a chercher les parties remplacantes
on va creer un document avec Spre Doc
Document cree
getting source as a stream and loading from file
Loaded - start relacing
Replacing finished
File saved
//
RESULT USING AN .EXE FILE
//Le systeme cherche la difference entre les K
Le systeme commence a formuler les elements de path...
Tous les elements reunis on va creer un dossier à C:\IOLS/Jennifer
Dossier cree de toute facon
-- On va creer le sous dossier --la date du jour
on va creer les documents
On commence a chercher les parties remplacantes
on va creer un document avec Spre Doc