Resolving java.lang.NoClassDefFoundError: java_cup/runtime/lr_parser

· Read in about 1 min · (98 words) ·

While building {OpenGrok from source I came across a common error. {OpenGrok also needs JFlex to be present on the classpath as mentioned in the README.TXT file.

$ sudo yum install jflex
$  hg clone ssh://anon@hg.opensolaris.org/hg/opengrok/trunk/ opengrok-dev
$ cd opengrok-dev
$ CLASSPATH=$CLASSPATH:/usr/share/java/JFlex.jar

Compilation failed giving the following error.

BUILD FAILED
java.lang.NoClassDefFoundError: java_cup/runtime/lr_parser
	at JFlex.anttask.JFlexTask.execute(JFlexTask.java:71)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
	at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.Target.execute(Target.java:357)

I couldn’t locate the cause of this error and after struggling a lot, the solution was pretty simple. I just added java_cup.jar to the class path:

CLASSPATH=$CLASSPATH:/usr/share/java/JFlex.jar:/usr/share/java/java_cup.jar  ant

Bingo!