java.lang.NoClassDefFoundError: org/apache/commons/lang/text/StrLookup - java

The error is pointing to EventUnitTesting.readPropertyFile(EventUnitTesting.java:168) in which the body of readPropertyFile() is
private void readPropertyFile() throws IOException, ConfigurationException{
file = new File(fileLocation + unitTestingFileName);
propertiesConfiguration = new PropertiesConfiguration(file);
List<Object> propertyKeysList = propertiesConfiguration.getList("regular");
Iterator<Object> propertyKeysIterator = propertyKeysList.iterator();
regularEvents = new ArrayList<String>();
while(propertyKeysIterator.hasNext()){
regularEvents.add((String)propertyKeysIterator.next());
}
propertyKeysList = propertiesConfiguration.getList("consolidated");
propertyKeysIterator = propertyKeysList.iterator();
consolidatedEvents = new ArrayList<String>();
while(propertyKeysIterator.hasNext()){
consolidatedEvents.add((String)propertyKeysIterator.next());
}
propertyKeysList = propertiesConfiguration.getList("correlated");
propertyKeysIterator = propertyKeysList.iterator();
correlatedEvents = new ArrayList<String>();
while(propertyKeysIterator.hasNext()){
correlatedEvents.add((String)propertyKeysIterator.next());
}
}
whereby I am using the Apache Commons Configuration library version 1.10 to read a properties file that has non-unique keys. I don't receive this error using a JBoss 6.4.8 purpose-built WAR but this error is generating on a JBoss converted 5.2 WAR.
I am using the Apache Commons Lang 2.1 so I'm not sure how org/apache/commons/lang/text/StrLookup can be a problem. All relevant *.java and *.class files have been copied into the converted jar file and everything is fine except this issue.

Note that NoClassDefFoundError is different than ClassNotFoundException. The former can mean that the class was found, but during the a static initializer an exception was thrown.
Wrap this method code in a try catch and output the exception. Likely you will see why.

Looks like some dependent jar was present at compile time but missing at runtime. Can you compare classpaths for build time and runtime. It will give you the difference which jar is missing and causing this issue.

Related

How can I create executable jars with embedded tomcat 9?

Has anyone tried the plugin to build an executable war/jar using Tomcat 9?
I attempted to do so however ran into:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.catalina.startup.Catalina.setConfig(Ljava/lang/String;)V
at org.apache.tomcat.maven.runner.Tomcat7Runner.run(Tomcat7Runner.java:240)
at org.apache.tomcat.maven.runner.Tomcat7RunnerCli.main(Tomcat7RunnerCli.java:204)
I looked at the source and changed Catalina.setConfig() to Catalina.setConfigFile() based on docs here. After doing so the .extract dir is just empty:
use extractDirectory:.extract populateWebAppWarPerContext
warValue:ROOT.war|ROOT populateWebAppWarPerContext
contextValue/warFileName:ROOT/ROOT.war webappWarPerContext entry
key/value: ROOT/ROOT.war expand to file:.extract/webapps/ROOT.war
Exception in thread "main" java.lang.Exception: FATAL: impossible to
create directories:.extract/webapps at
org.apache.tomcat.maven.runner.Tomcat7Runner.extract(Tomcat7Runner.java:586)
at
org.apache.tomcat.maven.runner.Tomcat7Runner.run(Tomcat7Runner.java:204)
at
org.apache.tomcat.maven.runner.Tomcat7RunnerCli.main(Tomcat7RunnerCli.java:204)
.... although there is a ROOT.war, server.xml, web.xml in the *-exec-war.jar.
Is there a better way to be creating exec-jars with embedded tomcat 9?
For those looking for a solution it was fairly straight forward to checkout the code for the plugin and make a few changes to get this to work. Namely:
Update POM to change the depends to Tomcat 9
Fix compile errors which generally stem from deprecated methods. The lookup on these methods can be found here. For example:
- container.setConfig( serverXml.getAbsolutePath() );
+ container.setConfigFile( serverXml.getAbsolutePath() );
... and ...
- staticContext.addServletMapping( "/", "staticContent" );
+ staticContext.addServletMappingDecoded( "/", "staticContent" );
There are a few others but generally not difficult to resolve. After doing so I updated my app's pom to use the modified version and was able to generate a Tomcat 9 exec jar.
I would love to hear what others are doing here. I know some are programmatically initializing Tomcat via a new Tomcat() instance however curious what other solutions exist ready made. Thanks
For future searchs, one solution is to use the DirResourceSet or JarResourceSet.
String webAppMount = "/WEB-INF/classes";
WebResourceSet webResourceSet;
if (!isJar()) {
webResourceSet = new DirResourceSet(webResourceRoot, webAppMount, getResourceFromFs(), "/");
} else {
webResourceSet = new JarResourceSet(webResourceRoot, webAppMount, getResourceFromJarFile(), "/");
}
webResourceRoot.addJarResources(webResourceSet);
context.setResources(webResourceRoot);
public static boolean isJar() {
URL resource = Main.class.getResource("/");
return resource == null;
}
public static String getResourceFromJarFile() {
File jarFile = new File(System.getProperty("java.class.path"));
return jarFile.getAbsolutePath();
}
public static String getResourceFromFs() {
URL resource = Main.class.getResource("/");
return resource.getFile();
}
When add the webapp, use root path "/" for docBase:
tomcat.addWebapp("", "/")
Credits for:
https://nkonev.name/post/101

java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Workbook.sheetIterator()Ljava/util/Iterator;

please i need some help on the error. I have a javafx project with the following jar files
fontawesome-fx-8.1.jar
sqlite-jdbc-3.8.10.1.jar
controlsfx-8.40.11.jar
sqljdbc42.jar
jfoenix-1.0.0.jar
POI-3.17.jar
poi-examples-3.17.jar
poi-excelant-3.17.jar
poi-ooxml-3.17.jar
poi-ooxml-schemas-3.17.jar
poi-scratchpad-3.17.jar
And what i need is to import some excel data to it. I have imported the above jar files
But unfortunately when i try to run the project i get the error:
Caused by: java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Workbook.sheetIterator()Ljava/util/Iterator;
at app.controllers.ContentAreaController.nextActionReport(ContentAreaController.java:734)
... 62 more
I have tried googling and what suggested is i change the versions of poi lib files but no luck .Can anyone suggest me the solution as i have spent enough time on the issue
Promoting some comments to an answer - you have older Apache POI jars on your classpath. As per this POI FAQ - mixing POI jars between versions is not supported
What you need to do is just remove the older POI jars. I say just, since you didn't know you had them... Luckily, if you follow the code in this Apache POI FAQ it'll help you find where the older jars are coming from. Something like this when run on your problematic system should print out the names and locations of the older jars:
ClassLoader classloader =
org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
URL res = classloader.getResource(
"org/apache/poi/poifs/filesystem/POIFSFileSystem.class");
String path = res.getPath();
System.out.println("POI Core came from " + path);
classloader = org.apache.poi.POIXMLDocument.class.getClassLoader();
res = classloader.getResource("org/apache/poi/POIXMLDocument.class");
path = res.getPath();
System.out.println("POI OOXML came from " + path);
classloader = org.apache.poi.hslf.usermodel.HSLFSlideShow.class.getClassLoader();
res = classloader.getResource("org/apache/poi/hslf/usermodel/HSLFSlideShow.class");
path = res.getPath();
System.out.println("POI Scratchpad came from " + path);
Just identify the older jars you don't want, remove, and you should be set!
Gagravarr's answer https://stackoverflow.com/a/50472754/1497139 pointed to http://poi.apache.org/help/faq.html#faq-N10006
I modified the code to be used the JUnit Test to fix the same base issue with the following error messages:
java.lang.NoSuchMethodError: org.apache.poi.xssf.usermodel.XSSFCell.getCellTypeEnum()Lorg/apache/poi/ss/usermodel/CellType;
Which if first thought was an issue of deprecation. After fixing the deprecation i got:
java.lang.NoSuchMethodError: org.apache.poi.xssf.usermodel.XSSFCell.getCellType()Lorg/apache/poi/ss/usermodel/CellType;
which was caused by mixing Apache POI 3.12 and Apache POI 4.0.1 jars in the same project.
To avoid this for the future I created the following Unit test. You might want to adapt the version to your needs or skip the assertion at all while still debugging the issue.
JUnit Test to check POI versions of used classes.
/**
* get the path the given class was loaded from
*
* #param clazz
* #return the path
*/
public String getClassLoaderPath(Class<?> clazz) {
ClassLoader classloader = clazz.getClassLoader();
String resource = clazz.getName().replaceAll("\\.", "/") + ".class";
URL res = classloader.getResource(resource);
String path = res.getPath();
return path;
}
#Test
public void testPOI() {
Class<?>[] classes = {
org.apache.poi.poifs.filesystem.POIFSFileSystem.class,
org.apache.poi.ooxml.POIXMLDocument.class,
org.apache.poi.hslf.usermodel.HSLFSlideShow.class,
org.apache.poi.xssf.usermodel.XSSFCell.class,
org.apache.poi.ss.usermodel.CellType.class};
for (Class<?> clazz : classes) {
String path = getClassLoaderPath(clazz);
if (debug)
System.out.println(
String.format("%s came from %s", clazz.getSimpleName(), path));
assertTrue(path.contains("4.0.1"));
}
}

Running XSLT to RDF framework fails because of Saxon

I´m using Krextor to convert XML to RDF. It runs fine from the command line.
I try to run it from Java (Eclipse) using this code.
private static void XMLToRDF() throws KrextorException, ValidityException, ParsingException, IOException, XSLException{
Element root = new Element("person");
Attribute friend = new Attribute("friends", "http://van-houten.name/milhouse");
root.addAttribute(friend);
Element name = new Element("name");
name.appendChild("Bart Simpson");
root.appendChild(name);
nu.xom.Document inputDocument = new nu.xom.Document(root);
System.out.println(inputDocument.toXML());
Element root1 = inputDocument.getRootElement();
System.out.println(root1);
Krextor k = new Krextor();
nu.xom.Document outputDocument = k.extract("socialnetwork","turtle",inputDocument);
System.out.println(outputDocument.toString());
}
I have the following problem problem
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/saxon/CollectionURIResolver
Caused by: java.lang.ClassNotFoundException: net.sf.saxon.CollectionURIResolver
I have included Saxon9he in the classpath, and I have also added manually as a library in the project but the error is the same.
I am the main developer of Krextor. And, #Michael Kay, actually a colleague of Grangel, so I will resolve the concrete problem with him locally.
So indeed the last Saxon version with which I did serious testing was 9.1; after that I haven't used Krextor integrated into Java but mainly used Krextor from the command line.
#Grangel, could you please file an issue for Krextor, and then we can work on fixing it together.
Indeed, #Michael Kay, for a while I had been including more recent Saxon versions with Krextor and updated the command line wrapper to use them (such as to add different JARs to the classpath), but I have not necessarily updated the Java wrapper code.

Exception running TrueZip

I run a simple TrueZip code:
TFile src = new TFile(path + file_to_add);
TFile dst = new TFile(path + outZipFile);
src.cp_rp(dst);
When i run the program the compiler throws (on the first line):
java.lang.NoClassDefFoundError: de/schlichtherle/truezip/fs/FsSyncOption
I have truezip-file-7.4.3.jar and truezip-file-7.4.3-sources.jar files.
Am i missing jars or the problem may be something else?
add truezip-driver-file.jar & truezip-kernel.jar according to Maven POM.

Eclipse RunTime NoClassDefFoundError

I am having trouble trying to use an imported class from a jar file which is located in the referenced libraries of my project.
So I have a project which has the pydev.jar file in the Referenced Libraries. Pydev.jar contains org.python.pydev.navigator.elements.PythonNode, and I have imported this in one of the Java files. Eclipse does not give an errors when I import and use this in the Java file but when I run the project as an Eclipse application there is a java.lang.NoClassDefFoundError: org/python/pydev/navigator/elements/PythonNode exception being thrown.
Code is trying to cast an ISelection to a PythonNode as below:
IStructuredSelection sel = (IStructuredSelection)
window.getSelectionService().getSelection();
ArrayList<String> testNames = new ArrayList<String>();
Iterator<?> itr = sel.iterator();
String testName = "";
String testSuite = "";
while(itr.hasNext()) {
PythonNode selectionElement = (PythonNode) itr.next();
testName = selectionElement.toString();
testSuite = selectionElement.pythonFile.toString();
testNames.add(testSuite + "." + testName);
}
If anyone can explain why the Exception is being thrown for the use of the PythonNode class at runtime I would be very appreciative. As far as I can see it is imported correctly as it is visible in the Referenced Libraries.
I think you're building either Eclipse RCP or Eclipse plugin. Am I right?
If yes, you should put pydev.jar under plugin dependencies. Go to plugin.xml, Runtime and put pydev.jar in the classpath

Categories