Sorry , i didn't know where to post this but wanted to help people working with PIG for the first time .(As i struggled for a long time to run my first program)
Anyways , please follow the steps to run pig programs via java .
1.write ur program in java as
PigServer pigServer = new PigServer("local"); // here local indicates u run ur prog in local mode, mapreduce indicates u run the prog in cluster mode .
2. register ur queries as
pigServer.registerQuery(<ur queries go here>);
3. run ur queries using
pigServer.store(<whatever u wana store >,<path>);
Now for runnig ur program
javac -cp <locate ur pig jar here> <ur programname>.java
If this doesnt work.. Set the CLASSPATH using export CLASSPATH to point to PIG jar and then run
javac <ur programname>.java
Lastly just run
java <ur programname>.java
and see the output in the path u have specified(local) or in base folder or path specified (mapreduce mode)
Hope people find this useful.