• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

New JavaRanch Journal article: Handling Uncommon File Formats - Introducing Lexers

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The latest issue of the JavaRanch Journal contains an article by yours truly on Handling Uncommon File Formats - Introducing Lexers. Go read it while it's fresh, and discuss it in this thread.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

Thanks for the nice article. It sounded interesting and I started reading through. On my way, I had downloaded the 'Properties.zip' file and ran the very first example you had demonstrated to run the 'PropertiesReader1.class' with 'example1.properties'. I face an issue here as it gives the infamous 'NoClassDefFoundError'.

I did run the command



in the directory where I had extracted the Properties.zip file and the error I get is




I could see the .class, .flex, .properties files present inside the extracted folder content. I also checked inside the .flex file to see if the PropertiesReader1.class file belongs to any package. But it does NOT. Why I am getting this error here?

Do I miss something here?

Thank you.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is odd. I just downloaded the zip file, changed to the directory, and ran the command you quoted - it worked just fine. You could try recompiling by
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Windows? If so, you need to use a semi-colon instead of a colon in the classpath.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ulf. Yes I am using windows and when i tried executing the same command without having the -classpath switch itself, it did work fine .

Let me proceed further and get back for any clarifications.

 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf,

Thank you very much. I am done with the full article and ran the complete set of examples in the zip file. It is really nice and I am happy about the last example (PropertiesReader5.flex) as it gives a provision/solution for the hierarchical properties in standard Java properties. .

It somehow gives me a hint to solve my long time problem of having a parameterized properties -- as what we do with ANT. Like we can refer a property inside the .properties file using the {} pairs to get its value so as to have a single point of change. I guess this JFlex can help me in solving this. Aint I?

To what extent should I know the 'internals' of JFlex? OR can i just go ahead with the same pace as that of your examples?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad you liked it.

I don't think you need to know the internals of JFlex. At least, I don't know them, and I've used it for more complex file formats than this one.

Maybe I'm misunderstanding what you mean by "parameterized properties", but Java already has that. Check out the "Messages" examples at http://www.exampledepot.com/egs/java.text/pkg.html. That sounds like what you're trying to do.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ulf for the immediate response as usual and expected.

I am aware of the example which is shown in the page -- which has the parameters to be passed to a property using {0}, {1} etc., and at the runtime, you can pass an Object[] to it by using MessageFormat.format() method.

I guess i had termed it in an inappropriate way. All what I want is



This we use it with ANT in our build.properties file by making use of "${}" to get the value of an existing property.

When we do NOT use ANT and if we write our own parser to deal with the traditional .properties file, is there any bulit in facility to deal with this OR do we have write on our own? Here is where I thought, this JFlex could be of some use to me. Aint I?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While you could write a lexer to do that, it seems overkill. A simple regular expression will extract the property name(s), and also allow you to replace them with their respective property values. That's much easier to write.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the idea of using RegEx seems to be an easy deal. Let me try. Thanks Ulf.
 
BWA HA HA HA HA HA HA! Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic