I'm trying to use Google protocol buffer for Java(I'm a newbie about Java, just trying).
First of all, I'm using OSX and I've installed protocol buffer with brew install protobuf
command.
protoc command works okay.
I've generated MyProtocol.java
by protoc.
I've installed protocol buffer for Java as its instruction(README.txt).
mvn install
command created .m2
directory and I can find protobuf-java-2.4.1.jar
file somewhere in the directory.
I wrote simple test Java code just importing MyProtocol.java
and it complains could not find package com.google.protobuf
.
So, I've just make jar file mvn package
and add its directory as CLASSPATH and it compiled well.
javac -classpath <protobuf-dir>/jara/target/classes Test.java ./com/example/tutorial/AddressBookProtos.java
If I use maven's repository directory (~/.m2/repository
), it complains again.
Doesn't maven make CLASSPATH for me if I install the package? If not, how can I use installed package by maven to compile my code?
Maven doesn't change your setup, so it's up to you to set your CLASSPATH according to your need.
However there are at least two ways in which Maven can halp you:
The Maven Dependency Plugin has a goal called
build-classpath
which does what you need. You can get usage hints on the Usage page