Hello all,
Apologies if my mistake is something relatively noobish; I’m not particularly familiar with Java so I’m learning as I go.
I’ve created a Java library for Lucee to enable local printing from a .CFM file by creating a custom <cf_print> tag. The code is working perfectly within the Java IDE (Eclipse) and is pretty much done. It -was- working in Lucee as an exported JAR (as an incomplete version). However, somewhere along the line, I started getting Lucee 6.0.1.83 Error (java.lang.NoClassDefFoundError) on some of the javax.print sub-classes, such as javax.print.attribute.standard.Media, or pretty much anything under javax.print.attribute.standard, whenever trying to call a method which contains them, through a .CFM file running within the Lucee environment.
I was able to call these classes from Lucee using earlier versions of the program, however those seem to have broken now too. Also, certain classes within javax.print are still working, like I think one of them is javax.print.attribute.PrintRequestAttributeSet.
I understand that the error is saying it was able to find these resources at compile time, but not at runtime, and given that they were working but stopped, this makes me believe that something changed within our Lucee config that’s causing my JAR to no-longer find this library. However, I’ve been unable to find any cause or solution.
It also strikes me as odd, since these libraries have been part of Java for quite some time, that my JAR can’t find them from within Lucee.
We wrote a simple CFM (not using a custom Java library) to show the available Java classes within Lucee, and the ones in question do show up. Not sure why my JAR can’t see them.
I don’t think we have any particular security setting blocking access or anything like that, nothing that we would’ve enabled at this point anyways.
It probably is something I’m doing wrong or some misconfiguration, but I’d appreciate any help navigating!
(Below is a very trimmed down, quick&dirty version of my full program that I wrote as a test.)
(JavaxPrintTest.java)
// import javax.print.*;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.PrintServiceLookup;
import javax.print.PrintService;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Fidelity;
import javax.print.attribute.standard.Media;
import javax.print.attribute.standard.MediaTray;
public class JavaxPrintTest {
public static void main(String[] args) {
System.out.println(showPrintServices());
}
public static String showPrintServices() {
String myString = "";
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
myString += "Number of print services: " + printServices.length + "\r\n";
for (PrintService printer : printServices) {
myString += "Printer: " + printer.getName() + "\r\n";
}
String printer = "HP LaserJet 600 M601 M602 M603 PCL6";
PrintService printService = findPrintService(printer); // Look up print service based on printer name
// MediaTray tray = findMediaTray(printService, "Tray 5");
myString += ShowMediaTray(printService, "Tray 5");
attributes.add(Fidelity.FIDELITY_FALSE);
return myString;
}
// Utility method to find a print service by its name
private static PrintService findPrintService(String printerName) {
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
for (PrintService service : printServices) {
if (service.getName().equalsIgnoreCase(printerName)) {
return service;
}
}
return null;
}
// Utility method to find a specific media tray by name within the available print service
private static String ShowMediaTray(PrintService service, String trayName) {
if (service == null) {
return null;
}
// Fetch all available media (paper trays, etc.) from the print service
Media[] medias = (Media[]) service.getSupportedAttributeValues(Media.class, null, null);
String MediaVal = "";
if (medias != null) {
// Iterate over the media to find the specified tray
for (Media media : medias) {
MediaVal += media + "\r\n";
}
}
return MediaVal;
}
}
OS: Windows Server 2022 Standard (21H2)
Java Version: 11.0.6 (AdoptOpenJDK) 64bit
Tomcat Version: Apache Tomcat/9.0.34
Lucee Version: Lucee 6.0.1.83
6 posts - 2 participants