I've come across one problem with maven and opencsv
I am trying to use the csvparser as followed:
import java.io.IOException;
import au.com.bytecode.opencsv.CSVParser;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Mapper;
public class FlightsByCarrierMapper extends
Mapper<LongWritable, Text, Text, IntWritable> {
@Override
protected void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
if (key.get() > 0) {
String[] lines = new
CSVParser().parseLine(value.toString());
context.write(new Text(lines[8]), new IntWritable(1));
}
}
}
I've added the opencsv dependency and can use the csvreader without problem. The csvparser though cannot be resolved and throws and error whenever I try to compile the code.
Maven then throws the following error.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project FlightsByCarrier: Compilation failure: Compilation failure:
[ERROR] /root/workspace/FlightsByCarrier/src/main/java/com/root/hadoop/FlightsByCarrier/FlightsByCarrierMapper.java:[6,30] error: cannot find symbol
[ERROR] package au.com.bytecode.opencsv
[ERROR] /root/workspace/FlightsByCarrier/src/main/java/com/root/hadoop/FlightsByCarrier/FlightsByCarrierMapper.java:[18,2] error: cannot find symbol
The dependency looks like this right now:
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>1.8</version>
</dependency>
It seems the class CSVParser
does not exist in opencsv 1.8. This class was introduced in opencsv 2.1.
As such, you need to update your dependency to version 2.1 at least.
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.1</version>
</dependency>
Note that starting with the 3.x branch, the artifact was relocated to the com.opencsv:opencsv
coordinate. It would be better to use the latest version of the library:
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>3.7</version>
</dependency>
You will need to update your imports also to import com.opencsv
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With