Cannot load class through its string name, because no definition for the class with the specified name [org.apache.poi.poifs.crypt.EncryptionMode] could be found caused by (java.lang.ClassNotFoundException:org.apache.poi.poifs.crypt.EncryptionMode

Hi,

Please help on below error

I have a code like below:
<cfset mode = createObject(“java”, “org.apache.poi.poifs.crypt.EncryptionMode”) />
<cfset info = createObject( “java”, “org.apache.poi.poifs.crypt.EncryptionInfo” ) />

	<cfset pa = createObject("java", "org.apache.poi.openxml4j.opc.PackageAccess") />
	<cfset opc = createObject("java", "org.apache.poi.openxml4j.opc.OPCPackage") />

Recently we had convert a ACF to Lucee and we got an error related to POI as below:

cannot load class through its string name, because no definition for the class with the specified name [org.apache.poi.poifs.crypt.EncryptionMode] could be found caused by (java.lang.ClassNotFoundException:org.apache.poi.poifs.crypt.EncryptionMode not found by lucee.core [49];java.lang.ClassNotFoundException:org.apache.poi.poifs.crypt.EncryptionMode;)

Full Error Dump
lucee.runtime.exp.NativeException: cannot load class through its string name, because no definition for the class with the specified name [org.apache.poi.poifs.crypt.EncryptionMode] could be found caused by (java.lang.ClassNotFoundException:org.apache.poi.poifs.crypt.EncryptionMode not found by lucee.core [49];java.lang.ClassNotFoundException:org.apache.poi.poifs.crypt.EncryptionMode;) at lucee.commons.lang.ClassUtil.loadClass(ClassUtil.java:296) at lucee.runtime.functions.other.JavaProxy.loadClassByPath(JavaProxy.java:130) at lucee.runtime.functions.other.JavaProxy.loadClass(JavaProxy.java:65) at lucee.runtime.functions.other.JavaProxy.call(JavaProxy.java:60) at lucee.runtime.functions.other.CreateObject.doJava(CreateObject.java:140) at lucee.runtime.functions.other.CreateObject.call(CreateObject.java:62) at lucee.runtime.functions.other.CreateObject.call(CreateObject.java:49) at boul.tools.ic_getstocktransferfile_cfm$cf$rd.call(/boul/tools/IC_GetStockTransferFile.cfm:158) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1043) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:935) at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:916) at application_cfc$cf.udfCall(/Application.cfc:708) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:350) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:223) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:697) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:585) at lucee.runtime.ComponentImpl.call(ComponentImpl.java:1932) at lucee.runtime.listener.ModernAppListener.call(ModernAppListener.java:444) at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:218) at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44) at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2475) at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2465) at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2436) at lucee.runtime.engine.Request.exe(Request.java:45) at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1194) at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1140) at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97) at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) at org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:433) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Unknown Source) Caused by: lucee.commons.lang.ClassException: cannot load class through its string name, because no definition for the class with the specified name [org.apache.poi.poifs.crypt.EncryptionMode] could be found caused by (java.lang.ClassNotFoundException:org.apache.poi.poifs.crypt.EncryptionMode not found by lucee.core [49];java.lang.ClassNotFoundException:org.apache.poi.poifs.crypt.EncryptionMode;) … 51 more

which POI lib are you using? are you loading a version directly yourself?

Lucee doesn’t ship with POI unlike ACF. You’ll need to load it yourself.

If you are just wanting to generate a password-protected XLSX file, then the Spreadsheet-CFML library can do that for you without you having to deal with POI:

@Julian_Halliwell , Here I have the code,

Can I use simplicity , or do I need other POI Utilities for below code

	<cfset mode = createObject("java", "org.apache.poi.poifs.crypt.EncryptionMode") />
	<cfset info = createObject( "java", "org.apache.poi.poifs.crypt.EncryptionInfo" ) />
	<cfset info.init(mode.agile) />
	
	<cfset enc = info.getEncryptor() />
	<cfset enc.confirmPassword("somepassword) />
	
	<!-------- Read in an existing OOXML file -------->
	<cfset pa = createObject("java", "org.apache.poi.openxml4j.opc.PackageAccess") />
	<cfset opc = createObject("java", "org.apache.poi.openxml4j.opc.OPCPackage") />
	<cfset opc = opc.open("#TransferFilePath#", pa.READ_WRITE) />
	
	<cfset os = enc.getDataStream(fs) />
	<cfset opc.save(os) />
	
	<cfset opc.close() />
	
	<!-------- Write out the encrypted version -------->
	<cfset fos = createobject("java", "java.io.FileOutputStream") />
	<cfset fos.init("#TransferFilePath#") />
	
	<cfset fs.writeFilesystem(fos) />
	<cfset fos.close() />

@Zackster

I Did not used any POI Lib,

can you please provide from where I can get POI lib and where should I place those Lib

Thanks

The library can read and write password-protected files, so yes it should do what you want. For example

<cfscript>
path = "c:\path\to\myspreadsheet.xlsx";
password = "topsecret";
// instantiate the library
spreadsheet = New Spreadsheet(); 
//... read in a password protected file
workbook = spreadsheet.read( src=path, password=password );
//... make some changes to the workbook object, then
//... save it back to disk
spreadsheet.write( workbook=workbook, filepath=path, overwrite=true, password=password );
</cfscript>

There are installation/usage instructions if you are unsure about that.

3 Likes

Thanks @Julian_Halliwell . That worked for me.