Development/Java
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
LibreOffice contains various pieces of code written in Java. Some of these pieces are currently being replaced/rewritten, but it is likely that LibreOffice will contain Java code for quite some time.
What pieces of LibreOffice are written in Java?
Some basic GNU/Linux tools can be run over the source code to report on various aspects relating to Java usage. Each example command below has been run against an extracted copy of the v4.2.6.3 archived (tar/7z) source tree.
Which directories contain *.java files?
It is worth routing the output from the find
command to a text file for later (as required) post-processing.
$ find libreoffice -type f -name "*.java" > libreoffice_find_java.txt
$ sed -e 's/^libreoffice\///' -e 's/[^/]*.java$//' -e 's/\([^/]\/\).*/\1/' libreoffice_find_java.txt | awk '!x[$0]++' | sort
Output from the above sed/awk/sort commands gives only the first level directory:
android/
bean/
bridges/
chart2/
cli_ure/
codemaker/
comphelper/
connectivity/
cppuhelper/
dbaccess/
desktop/
embeddedobj/
extensions/
external/
filter/
forms/
framework/
javaunohelper/
jurt/
jvmaccess/
jvmfwk/
linguistic/
nlpsolver/
odk/
package/
qadevOOo/
reportbuilder/
reportdesign/
ridljar/
sc/
scripting/
sfx2/
smoketest/
sot/
stoc/
svl/
sw/
swext/
testtools/
toolkit/
ucb/
unotest/
unotools/
unoxml/
ure/
wizards/
workdir/
xmerge/
xmlsecurity/
Note though that very little of this Java code is actually part of the shipped product. Most of these lines of code are actually only testcode from the $MODULE/qa subdirectory. A more relevant analysis would exclude that subdirectories as they are never shipped with the product. Doing this on a ~recent checkout of master@64914e407ccac91fbbaa5022a6854be9a01027f8:
find . -type f -name "*.java" |grep -v workdir |grep -v instdir |grep -v '\/qa\/' |grep -v '\/test\/'> lo_find_java.txt
sed -e 's/^.\///' -e 's/[^/]*.java$//' -e 's/\([^/]\/\).*/\1/' lo_find_java.txt | awk '!x[$0]++' | sort
shows (with some resorting) this:
android/ # android port -- not part of the core product
bridges/ # modules that provide the bridge to Java itself -- little to no LibreOffice core functionality by itself
javaunohelper/
jurt/
jvmaccess/
jvmfwk/
odk/
ridljar/
ure/
qadevOOo/ # various forms of integration tests -- little to no LibreOffice core functionality by itself
smoketest/
testtools/
xmlsecurity/
bean/ # extensions and scripting -- little to no LibreOffice core functionality by itself
nlpsolver/
reportbuilder/
scripting/
swext/
xmerge/
wizards/ # seems to be dead code only really by now
filter/
external/ # third-party code not maintained by LibreOffice
connectivity/ # remaining core functionality -- mostly hsqldb 1.8 driver for LibreOffice Base default database (<5 KLOC)
For a comprehensive list of directories:
$ sed -e 's/^libreoffice\///' -e 's/[^/]*.java$//' libreoffice_find_java.txt | awk '!x[$0]++' | sort
Output (first few lines) from the above sed/awk/sort commands:
android/Bootstrap/src/org/libreoffice/kit/
android/source/src/java/org/libreoffice/
android/source/src/java/org/libreoffice/canvas/
android/source/src/java/org/libreoffice/overlay/
android/source/src/java/org/libreoffice/storage/
android/source/src/java/org/libreoffice/storage/external/
android/source/src/java/org/libreoffice/storage/local/
For the complete list, please see Development/Java/Directories containing .java files
How many lines of java source code in each main directory?
It is worth routing the output from sloccount
to a text file for later (as required) post-processing.
$ sloccount libreoffice > libreoffice_sloccount.txt
$ grep java= ../libreoffice_sloccount.txt | sed -e 's/^........//' -e 's/\(\([a-z]\{2,6\}=[0-9]\{1,6\},\)*\)\?java=/java=/' | awk -F, {'print $1'}
Output from above grep/sed commands, after sorted by the number of lines:
28 jvmfwk
45 jurt
50 jvmaccess
59 cli_ure
71 sw
91 external
98 stoc
120 smoketest
137 xmlsecurity
143 ure
175 sot
201 bridges
239 cppuhelper
275 linguistic
346 reportdesign
370 comphelper
430 svl
519 unotest
579 codemaker
622 desktop
684 filter
719 chart2
769 extensions
1230 ucb
1653 testtools
1745 sc
2099 embeddedobj
2373 nlpsolver
2923 javaunohelper
2950 dbaccess
3035 bean
3075 connectivity
3079 unoxml
3212 swext
3541 sfx2
3991 odk
4285 forms
5398 framework
7806 scripting
8505 xmerge
8524 toolkit
9158 package
12600 android
14643 reportbuilder
14756 ridljar
27203 wizards
87831 qadevOOo
263934 TOTAL
Java use (as a percentage) in each LibreOffice end-of-train release, is also available in the Ask thread Is there any plan to ditch Java in the future and use only C/C++ code?. Note though that very little of this Java code is actually part of the shipped product. Most of these lines of code are actually only testcode from the $MODULE/qa subdirectory. A more relevant analysis would exclude that subdirectories as they are never shipped with the product.
Which directories contain *.jar files?
$ find libreoffice -type f -name "*.jar" | sed -e 's/^libreoffice\///'
Output from above find/sort commands:
qadevOOo/testdocs/qadevlibs/JobExecutor.jar
qadevOOo/testdocs/qadevlibs/MyPersistObjectImpl.jar
Building LibreOffice without Java
Compile LibreOffice with the flag --without-java
Suggestion to Remove Java Components
Some think java is a slow memory hog, others think it is a legal swamp that invites lawsuits. Neither might be true, but some developers have nevertheless expressed their desire to remove Java usage in LO over time.
Resources
- See an overview of all code in LO on page Development/Code Overview.
- Also see https://docs.libreoffice.org