0

I am trying to use Scala macro annotations with this library.

I have a schema file at src/main/resources/avsc/FriendRequestAcceptedGson.avsc

I am trying to refer to it in my code as follows:

@AvroTypeProvider("/avsc/FriendRequestAcceptedGson.avsc")
@AvroRecord
case class FriendRequestAcceptedGson()   

This is the error I get:

[error] /home/lee/Code/bigdata-friends/java/etl/src/main/scala/com/mxit/bd/friends/etl/Runner.scala:64: exception during macro expansion: [error] java.io.FileNotFoundException: /avsc/FriendRequestAcceptedGson.avsc (No such file or directory) [error] at java.io.FileInputStream.open(Native Method) [error] at java.io.FileInputStream.<init>(FileInputStream.java:146) [error] at org.codehaus.jackson.JsonFactory.createJsonParser(JsonFactory.java:504) [error] at org.apache.avro.Schema$Parser.parse(Schema.java:922) [error] at com.julianpeeters.avro.annotations.util.SchemaParser$.getSchema(SchemaParser.scala:20) [error] at com.julianpeeters.avro.annotations.AvroTypeProviderMacro$.impl(TypeProviderMacro.scala:23) [error] @AvroTypeProvider("/avsc/FriendRequestAcceptedGson.avsc")

Lee
  • 8,354
  • 14
  • 55
  • 90
  • It seems that the avsc file is being picked up from an absolute path. What happens by using `avsc/FriendRequestAcceptedGson.avsc`? – Nader Ghanbari Oct 28 '14 at 13:48
  • The same problem: ```java.io.FileNotFoundException: avsc/FriendRequestAcceptedGson.avsc (No such file or directory)``` – Lee Oct 28 '14 at 13:52

1 Answers1

1

Resources are compiled into your JAR file. You must find them with a ClassLoader, not in the file system. The java.io.FIle class only knows how to look in the file system. Now, if you're trying to open the source file (which may not be present when the JAR is deployed), it will depend on where your current working directory is relative to the file. Probably it is at the root so the path you need to use is the full relative one: src/main/resources/avsc/FriendRequestAcceptedGson.avsc

Reid Spencer
  • 2,776
  • 28
  • 37