jflap-lib
jflap-lib copied to clipboard
org/w3c/dom/ls/DocumentLS
When I try to run the jar bundles with any FSA I always get the following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/dom/ls/DocumentLS
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.apache.xerces.jaxp.DocumentBuilderImpl.
Any solution to this?
I'm running the bundle jar file wrapped in Python code see code below for testing an input and for testing equivalence for FSAs
#this method takes an input array and a jflap FSA machine
def testInput(input, machine):#input is an array e.g. input = ["abc","aabbcc"]
from subprocess import Popen, PIPE, STDOUT
from threading import Timer
p = Popen(['java', '-jar', 'jflaplib-cli-1.3-bundle.jar', 'run', machine, input], stdout=PIPE, stderr=STDOUT)
timer = Timer(10, p.kill)
try:
timer.start()#timeout in case of infinite loops
for line in p.stdout:
return line
return 'false'
finally:
timer.cancel()
#check if one machine is equivalent to another
def checkEquivalence(machine1, machine2):
from subprocess import Popen, PIPE, STDOUT
from threading import Timer
p = Popen(['java', '-jar', 'jflaplib-cli-1.3-bundle.jar', 'equivalent', machine1, machine2], stdout=PIPE, stderr=STDOUT)
timer = Timer(10, p.kill)
checkResult = ""
try:
timer.start()
for line in p.stdout:
checkResult = line
return checkResult
finally:
timer.cancel()
I have written a similar utility inspired by this repo, you can try it out here:
https://github.com/ushahid/jflap-cli
Quick Fix
If you're using Gradle (solution is similar for Maven, see related reading) you can address this issue by overriding the xerces:xercesImpl
used in your project. The version used in this project is rather old, and it appears there are some issues using it today. If you need to shell out to the JAR, you could try forking and modifying this project replacing the dependency.
dependencies {
// ...
implementation("com.github.citiususc:jflap-lib:1.3") {
exclude(group = "xerces", module = "xercesImpl")
}
implementation("xerces:xercesImpl:2.12.2")
// ...
}
Related Reading
Here is a related issue: https://stackoverflow.com/questions/62006284/noclassdeffounderror-org-w3c-dom-ls-documentls-issue-occurring-only-on-deploy