One of the aspects of my job is to write Java code. It’s a nice task and I like it, but I’m not addicted to it. So once in a while I don’t want to write Java code, because I think at this planet there must be at least one person that already wrote what I need and that decided to share the code. With MaVeN I can easily include a Java library written by a third party, so in 15 minutes I can parse all kinds of CSV files.
Last week I described how to stream a file from the browser to WebManager. This file happened to be a CSV file and I need to do some processing for each entry in the file. Some CSV files are simple and each line has a set of fields separated by some special character. But in my CSV file this character can occur as content in the fields, so I needed to parse escaping and I had to cope with newlines inside fields. My bet was that someone needed this before, so I opened up my browser and found OpenCSV. The library is distributed using the Apache 2.0 license, so I am allowed to use and distribute it as part of my WCB.
After I checked for documentation, known bugs and some more about the project, I decided to use it for my WCB. A search on mvnrepository gave me the following POM dependency:
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>1.8</version>
</dependency>
All I do is copy these lines, open up Eclipse, paste them into my projects pom.xml, save the file and the MaVeN plugin automatically downloads the library from the central repository and adds it to the projects classpath. Using the API documentation of the library I finished my WCB the same day.
Mark is software engineer with a special interest in Security and Digital WebTV. Mark writes about daily engineering with GX WebManager
Other blog entries: