Re: [antlr-discussion] How can I create a jar from the java code generated by the ANTLR4 ?

138 views
Skip to first unread message

Mike Lischke

unread,
Jul 29, 2017, 1:20:53 PM7/29/17
to antlr-di...@googlegroups.com
> I did create a file " date.g4 " to compile date articles like ' today +tomorrow +...' and return the date 'dd/mm/year' .
> then, compile it through terminal:
> " antlr4 date.g4
> javac date*.java"
> it generates finally a lot of files " .java , .tokens , .class "
> I want to trasform it to .jar but I didn t understand what I must transform from all those files

Add the generated .java files to your project in which you want to parse and you should be fine. But first you should test everything in the IDE of your choice, which doesn't involve creating a jar at all. You set up your project for parsing, add the generated java files to it and write your main code, as usual. Once this runs fine you can think of exporting it into a jar file.

Mike
--
www.soft-gems.net

Norman Dunbar

unread,
Jul 29, 2017, 4:03:47 PM7/29/17
to antlr-di...@googlegroups.com
To build a jar file, which I did with my ANTLR4 utility to check an Oracle Tnsnames.ora file, you just need to collect all the *.class files together into a jar file using the "jar" utility.

I have a bulk script for windows on Github at https://github.com/NormanDunbar/Tnsnames_checker/blob/master/build.bat which you might want to look at. The applicable line is:

jar -cvf test\tnsnames_checker.jar *.class > nul

This is after that "javac" compile of all the *.java files obviously.

My build runs anltr4 on the two grammar files, compiles the generated *.jave files into *.class files, collects them into a single *.jar file, then deletes the *.class files.

It may not be the best or most efficient way, but it worked for me, and I'm not a java programmer at all! This was my first one.

Have fun.

Cheers,
Norm.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Reply all
Reply to author
Forward
0 new messages