Here's my goal: Use SableCC to generate several parsers/lexers at runtime and load instances of them for parsing and lexing.
So I figured my steps would be:
Generate the .java
files using SableCC. I think I've done this, fine.
Compile the .java
file to .class
files. I did this using JavaCompiler
. I think this worked fine, as well.
Put the generated files in a .jar
file, preserving the file structure. I did this using this as a template. Examining the .jar
file using JarBrowser showed that the file structure of the packages was preserved. Using it, the Jar Catalog looks the same as a regular .jar
file. However, using JarBrowser, my jar doesn't show up under "CLASSPATH catalog." This leads me to believe that my .jar
file isn't being created correctly.
Load the .jar
file into an instance of URLClassLoader
. I'm trying to load it using Class.forName()
but it doesn't seem to be working.
Whenever I do step 4., I get a java.lang.ClassNotFoundException
. Does anyone have any ideas as to why this is?
It turns out that I had a slash as a prefix to the file/directory names. I was truncating the parent directory from the file name, but didn't take into account the trailing slash from the parent directory, so /dir1/file1
was being done instead of dir1/file1
. I guess JAR
files are picky.