Skip to content

Instantly share code, notes, and snippets.

@tam7t
Last active November 25, 2015 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tam7t/b952d76ca9531f04678c to your computer and use it in GitHub Desktop.
Save tam7t/b952d76ca9531f04678c to your computer and use it in GitHub Desktop.
public class DoesNotWork {
public static void main(String[] args) {
// this will compile once, fail on execution, and subsequent compiles fail
Messages.Status me = Messages.Status.newBuilder().buildPartial();
System.out.println("It Works!");
}
}
enum STATUS {
OK = 1;
}
message Status {
required STATUS code = 1;
}
message Person {
required string name = 1;
}
#!/bin/bash
echo "protobuf + java = 💩"
echo "-----java info-----"
java -version
echo "-----protobuf info-----"
protoc --version
printf "\n\n"
read -rsp $'Press any key to download protobuf jar...\n' -n1 key
wget http://central.maven.org/maven2/com/google/protobuf/protobuf-java/2.6.1/protobuf-java-2.6.1.jar
read -rsp $'Press any key to compile messages.proto...\n' -n1 key
protoc --proto_path . --java_out . messages.proto
read -rsp $'Press any key to compile the working example...\n' -n1 key
javac Works.java -cp protobuf-java-2.6.1.jar:.
read -rsp $'Press any key to run the working example...\n' -n1 key
java -cp protobuf-java-2.6.1.jar:. Works
read -rsp $'Press any key to clear compiled classes...\n' -n1 key
rm *.class
read -rsp $'Press any key to compile the non-working example...\n' -n1 key
javac DoesNotWork.java -cp protobuf-java-2.6.1.jar:.
read -rsp $'Press any key to run the non-working example...\n' -n1 key
java -cp protobuf-java-2.6.1.jar:. DoesNotWork
read -rsp $'Press any key to compile the non-working example...\n' -n1 key
javac DoesNotWork.java -cp protobuf-java-2.6.1.jar:.
echo "Clean up files with $ rm Messages.java *.class protobuf-java-2.6.1.jar"
public class Works {
public static void main(String[] args) {
// this will work all day every day
Messages.Person me = Messages.Person.newBuilder().buildPartial();
System.out.println("It Works!");
}
}
@tam7t
Copy link
Author

tam7t commented Nov 25, 2015

This demonstrates a failure on OSX Oracle JVM 1.8:

Exception in thread "main" java.lang.NoClassDefFoundError: Messages$STATUS (wrong name: Messages$Status)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment