I am successfully using a Java command line program that I wrote that uses the Apache POI file to read a Microsoft Word (.docx) file and mail it. I wish to package it as an executable jar.
I am creating this by taking each jar that my application needs and expanding with jar -xvf.
Stackoverflow question 183292 describes the techniques that one can use when one needs to put a library "jar in a jar."
Unfortunately, I am getting the error below when I run it.
DEBUG: setDebug: JavaMail version 1.4ea
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
at org.apache.poi.ooxml.POIXMLTypeLoader.<clinit>(POIXMLTypeLoader.java:43)
at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:178)
at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:184)
at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:145)
at m4.main(m4.java:273)
The last thing I did before creating the jar fille was to expand (with jar -xvf
) xmlbeans-5.1.3.jar
. I then rejarred everything (my application and the results of jaring all the other files.)
Question 20799326 on StackOverflow.com explains that this symptom is caused by multiple xml beans jar files on the class path.
However, since the executable jar should only see expanded versions, I do not believe that could be a problem.
Question 183292 further said that expanding one jar to create another could lead to issues with package name conflicts.
(But this "should not happen if people use proper packages, ..." However, I certainly believe that Apache does use the standard package convention...
I expanded 5.1 version last.
That should replace any old version that might have been lying around in the directory. (Just in case, I tried removing the old org/apache/xmlbeans
directory and then redoing the jar. Did not help.)
After I expanded the jar's, I did a ls -R
I take the liberty of attaching the list, on the offchance, someone might see something there. I did abbreviate those parts that seem least relevant with ellipsis.
m4:
com
Debug
javax
LICENSE.txt
m4$1.class
m4$AddressMap.class
m4.class
m4$CmdLineConst.class
Manifest.txt
META-INF
NOTICE.txt
org
resolver.jar
schemaorg_apache_xmlbeans
m4/com:
microsoft
sun
m4/com/microsoft:
schemas
m4/com/microsoft/schemas:
compatibility
office
vml
...
m4/com/microsoft/schemas/office:
excel
office
visio
x2006
m4/com/microsoft/schemas/office/excel:
...
m4/com/microsoft/schemas/office/x2006:
digsig
encryption
keyEncryptor
m4/com/microsoft/schemas/office/x2006/digsig:
CTSignatureInfoV1.class
CTSignatureInfoV1$Factory.class
....
m4/com/microsoft/schemas/office/x2006/digsig/impl:
...
m4/com/microsoft/schemas/office/x2006/encryption:
CTDataIntegrity.class
....
m4/com/sun:
mail
m4/com/sun/mail:
handlers
iap
imap
pop3
smtp
util
m4/com/sun/mail/handlers:
image_gif.class
image_jpeg.class
message_rfc822.class
multipart_mixed.class
text_html.class
text_plain.class
text_xml.class
m4/com/sun/mail/iap:
Argument.class
AString.class
Atom.class
....
m4/com/sun/mail/imap:
ACL.class
AppendUID.class
DefaultFolder$1.class
...
m4/com/sun/mail/imap/protocol:
BASE64MailboxDecoder.class
BASE64MailboxEncoder.class
BODY.class
...
....
m4/com/sun/mail/smtp:
DigestMD5.class
SMTPAddressFailedException.class
....
m4/com/sun/mail/util:
ASCIIUtility.class
BASE64DecoderStream.class
...
m4/Debug: (This is my class)
Debug.class
Debug.java
m4/javax:
mail
m4/javax/mail:
Address.class
AuthenticationFailedException.class
Authenticator.class
BodyPart.class
....
m4/javax/mail/event:
ConnectionAdapter.class
ConnectionEvent.class
....
m4/javax/mail/internet:
AddressException.class
AsciiOutputStream.class
CachedDataHandler.class
....
m4/javax/mail/search:
AddressStringTerm.class
AddressTerm.class
AndTerm.class
....
m4/javax/mail/util:
...
m4/META-INF:
INDEX.LIST
javamail.charset.map
javamail.default.address.map
javamail.default.providers
LICENSE
LICENSE.txt
mailcap
MANIFEST.MF
maven
NOTICE
NOTICE.txt
services
SUN_MICR.RSA
SUN_MICR.SF
xmlbeans.bnd
m4/META-INF/maven:
org.apache.commons
org.ow2.jonas.osgi
m4/META-INF/maven/org.apache.commons:
commons-collections4
commons-compress
....
m4/org:
apache
etsi
openxmlformats
w3
w3c
m4/org/apache:
commons
env
poi
xml
xmlbeans
m4/org/apache/commons:
collections4
compress
m4/org/apache/commons/collections4:
ArrayStack.class
ArrayUtils.class
bag
Bag.class
BagUtils.class
bidimap
...
m4/org/apache/commons/collections4/bag:
AbstractBagDecorator.class
AbstractMapBag$BagIterator.class
AbstractMapBag.class
.....
m4/org/apache/commons/compress:
archivers
changes
....
m4/org/apache/commons/compress/archivers:
ar
ArchiveEntry.class
ArchiveException.class
ArchiveInputStream.class
....
tar
zip
...
m4/org/apache/env:
WhichFactory.properties
WhichJar.properties
m4/org/apache/poi:
common
ddf
EmptyFileException.class
....
m4/org/apache/poi/common:
usermodel
m4/org/apache/poi/common/usermodel:
fonts
Hyperlink.class
HyperlinkType.class
m4/org/apache/poi/common/usermodel/fonts:
FontCharset.class
FontFamily.class
....
m4/org/apache/poi/ddf:
AbstractEscherOptRecord$1.class
AbstractEscherOptRecord.class
DefaultEscherRecordFactory.class
....
m4/org/apache/poi/extractor:
ole2
OLE2ExtractorFactory.class
POIOLE2TextExtractor.class
POITextExtractor.class
m4/org/apache/poi/extractor/ole2:
OLE2ScratchpadExtractorFactory.class
....
m4/org/apache/poi/ooxml:
extractor
POIXMLDocument.class
...
m4/org/apache/poi/ooxml/extractor:
CommandLineTextExtractor.class
....
m4/org/apache/poi/ooxml/util:
DocumentHelper$1.class
DocumentHelper.class
....
m4/org/apache/poi/openxml4j:
exceptions
opc
util
.....
m4/org/apache/poi/sl/usermodel:
AbstractColorStyle.class
AutoNumberingScheme$1.class
AutoNumberingScheme.class
...
TextShape$TextPlaceholder.class
VerticalAlignment.class
m4/org/apache/poi/ss:
excelant
extractor
format
formula
SpreadsheetVersion.class
usermodel
util
m4/org/apache/poi/ss/excelant:
antlib.xml
ExcelAntEvaluateCell.class
ExcelAntHandlerTask.class
ExcelAntPrecision.class
....
m4/org/apache/poi/ss/excelant/util:
ExcelAntEvaluationResult.class
ExcelAntWorkbookUtil.class
ExcelAntWorkbookUtilFactory.class
m4/org/apache/poi/ss/extractor:
EmbeddedData.class
EmbeddedExtractor$BiffExtractor.class
...
m4/org/apache/poi/ss/format:
CellDateFormatter$1.class
CellDateFormatter.class
CellDateFormatter$DatePartHandler.class
CellElapsedFormatter$1.class
...
m4/org/apache/poi/ss/formula:
atp
BaseFormulaEvaluator$1.class
BaseFormulaEvaluator.class
...
WorkbookDependentFormula.class
WorkbookEvaluator$1.class
WorkbookEvaluator.class
WorkbookEvaluatorProvider.class
...
....
m4/org/apache/poi/xddf:
usermodel
m4/org/apache/poi/xddf/usermodel:
BlackWhiteMode.class
chart
CompoundLine.class
...
XDDFRadarChartData.class
XDDFRadarChartData$Series.class
XDDFScatterChartData.class
XDDFScatterChartData$Series.class
XDDFSeriesAxis.class
XDDFValueAxis.class
....
....
m4/org/apache/poi/xwpf:
extractor
model
usermodel
m4/org/apache/poi/xwpf/extractor:
XWPFWordExtractor.class
m4/org/apache/poi/xwpf/model:
WMLHelper.class
XWPFCommentsDecorator.class
XWPFHeaderFooterPolicy.class
XWPFParagraphDecorator.class
m4/org/apache/poi/xwpf/usermodel:
BodyElementType.class
BodyType.class
Borders.class
BreakClear.class
...
XWPFTable$1.class
XWPFTable$Border.class
...
m4/org/apache/xml:
resolver
m4/org/apache/xml/resolver:
apps
Catalog.class
CatalogEntry.class
...
Resolver.class
tools
Version.class
m4/org/apache/xml/resolver/apps:
resolver.class
xparse.class
XParseError.class
xread.class
m4/org/apache/xml/resolver/etc:
catalog.dtd
catalog.rng
catalog.xsd
...
m4/org/apache/xmlbeans:
BindingConfig.class
CDataBookmark.class
DelegateXmlObject.class
...
XmlUnsignedShort$Factory.class
XmlValidationError.class
m4/org/apache/xmlbeans/impl:
common
config
inst2xsd
jam
piccolo
regex
richParser
schema
soap
store
tool
util
validator
values
xb
xpathgen
xsd2inst
m4/org/apache/xmlbeans/impl/common:
ConcurrentReaderHashMap$1.class
ConcurrentReaderHashMap$BarrierLock.class
ConcurrentReaderHashMap.class
ConcurrentReaderHashMap$Entry.class
...
XPath.class
XPath$CompilationContext.class
XPath$ExecutionContext.class
XPath$ExecutionContext$PathContext.class
XPath$Selector.class
XPath$Step.class
XPath$XPathCompileException.class
...
m4/org/etsi:
uri
m4/org/etsi/uri:
x01903
m4/org/etsi/uri/x01903:
v13
m4/org/etsi/uri/x01903/v13:
AnyType.class
AnyType$Factory.class
CertIDListType.class
CertIDListType$Factory.class
CertIDType.class
CertIDType$Factory.class
...
XAdESTimeStampType.class
XAdESTimeStampType$Factory.class
m4/org/etsi/uri/x01903/v13/impl:
AnyTypeImpl.class
CertIDListTypeImpl.class
CertIDTypeImpl.class
CertificateValuesTypeImpl.class
...
UnsignedPropertiesTypeImpl.class
UnsignedSignaturePropertiesTypeImpl.class
XAdESTimeStampTypeImpl.class
m4/org/openxmlformats:
schemas
m4/org/openxmlformats/schemas:
drawingml
officeDocument
presentationml
spreadsheetml
wordprocessingml
xpackage
....
...
m4/org/openxmlformats/schemas/officeDocument:
x2006
m4/org/openxmlformats/schemas/officeDocument/x2006:
customProperties
docPropsVTypes
extendedProperties
relationships
...
m4/org/openxmlformats/schemas/spreadsheetml/x2006/main:
CalcChainDocument.class
CalcChainDocument$Factory.class
ChartsheetDocument.class
ChartsheetDocument$Factory.class
CommentsDocument.class
...
StylesDocument.class
StylesDocument$Factory.class
STZoom$Enum.class
....
m4/schemaorg_apache_xmlbeans/javaname/org/apache/xmlbeans:
impl
m4/schemaorg_apache_xmlbeans/javaname/org/apache/xmlbeans/impl:
xb
m4/schemaorg_apache_xmlbeans/javaname/org/apache/xmlbeans/impl/xb:
ltgfmt
substwsdl
xmlconfig
xmlschema
xsdownload
xsdschema
m4/schemaorg_apache_xmlbeans/javaname/org/apache/xmlbeans/impl/xb/ltgfmt:
Code.xsb
FileDesc
FileDesc.xsb
TestCase
... (rest is all schemaorg stuff)
Same error here but loading an excel file, just upgrade my XMLBeans from 2.3.0 to 3.1.0 and all work really nice.
download here:
https://www.apache.org/dyn/closer.lua/poi/xmlbeans/release/bin/xmlbeans-bin-3.1.0.zip
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.