0

I have a program which simply creates a table with 2 columns, left column is set to right orientation. When I test in eclipse the program works fine, it creates the table with the borders (as I have defined in the program itself) and the style (font, spacing, etc) set in the styles.xml.

However once exporting to .jar all styles disappear. The program still works, it creates the table and the word document, except the style is the default style (calibri, size 11, line space) and the table is the default style, meaning it has got no borders. This is kinda strange because I define the table style in the program, and not in the styles.xml.

Anyone got this problem?

styles.xml: http://pastebin.com/htmKVjGP

Complete source code (just enter whatever in the fields, then click on the button, it'll generate the doc on your desktop):

AllemandWord.java: http://pastebin.com/jKXGRZn0

Fenetre.java: http://pastebin.com/U5x02Vws

Edit: solution was to use the docx4j zip instead of importing from github.

Zezombye
  • 321
  • 4
  • 16
  • settings.xml? Please expand your question by including your source code. Compare your classpaths (inside versus outside Eclipse). – JasonPlutext Mar 03 '16 at 23:37
  • Was styles.xml actually. I included my source code, as for the classpaths I can't find the styles.xml inside the jar, but if it was only the styles.xml that was missing my tables would still be with borders, and they aren't. – Zezombye Mar 04 '16 at 06:28
  • you define the table style in styles.xml at line 436 of http://pastebin.com/htmKVjGP Unzip the resulting docx. What is in its styles.xml? – JasonPlutext Mar 04 '16 at 06:45
  • The resulting docx actually has nothing other than document.xml in the word folder, weird o_o And the problem is indeed the styles.xml missing since my table declaration refers to it. So how can I make sure to include the styles.xml and the others .xml? – Zezombye Mar 04 '16 at 12:02
  • createPackage() should add a styles part. Something odd seems to be happening. What docx4j jar are you using and where did you get it? What version of Java & JAXB are you using? What do the logs say? Turn on debug level logging if necessary. – JasonPlutext Mar 04 '16 at 12:10
  • Logs: http://pastebin.com/tLvC45ci so basically it doesn't find the styles.xml. I imported the docx4j library from github. So my problem is basically Eclipse not importing the required xml files into the jar. – Zezombye Mar 04 '16 at 16:47
  • build the jar using mvn install, with -DskipTests=true if necessary... – JasonPlutext Mar 04 '16 at 20:58
  • How exactly do I do that? I searched but I don't understand anything, command line doesn't recognize mvn and when I do right click on project and select "run as" there's no "maven install". – Zezombye Mar 05 '16 at 14:39
  • Installed it, now what? Sorry if I ask obvious questions but I don't know how I would make my .jar using maven, mvn install doesn't work (thinks install is a path) and what should I use it on anyway, my .java files? – Zezombye Mar 08 '16 at 16:39
  • You'd run mvn install in the root dir of the docx4j checkout (ie the one containing pom.xml). But you might be better off starting with a docx4j distribution, http://www.docx4java.org/docx4j/docx4j-3.2.2.zip – JasonPlutext Mar 08 '16 at 20:41
  • Uuuuh what do I do with it? Also I tried mvn install in there, it ran but it says there are errors for some reason, and it's outputting so much log I can't see what are the errors. – Zezombye Mar 09 '16 at 18:05
  • Forget mvn for now (or if you persevere, run it with -DskipTests=true). Instead, unzip the zip file and copy docx4j and the dependent jars to your classpath. – JasonPlutext Mar 09 '16 at 23:34
  • It now successfully adds the borders to the table :D but I ran inside another problem, I can't edit the style (font, font size and line spacing) for some reason, editing the styles.xml doesn't work, be it in or outside eclipse. Any idea? I also tried to set the docDefaults in my code but it doesn't work either. – Zezombye Mar 10 '16 at 11:56
  • I guess you better start a new question about that. – JasonPlutext Mar 10 '16 at 19:34

0 Answers0