Repository navigation
What's the best way for a total n00b to start with this library? #34
Copy link
Copy link
Closed
Labels
🚨 criticalP0 critical issue. Requires immediate fixP0 critical issue. Requires immediate fixapi: coreauthtriage meI really want to be triaged.I really want to be triaged.
Description
I'm having trouble getting a HelloDatastore project working. Hoping that you can help me get this going...
Here's what I did:
$ git clone https://github.com/GoogleCloudPlatform/gcloud-java.git
$ cd gcloud-java
$ sudo apt-get install maven
$ mvn install
$ export CLASSPATH=~/gcdjavasample/gcloud-java/target/gcloud-java-0.0.3.jarHere's the file I'm trying to run (HelloDatastore.java):
import com.google.gcloud.datastore.DatastoreService;
import com.google.gcloud.datastore.DatastoreServiceFactory;
import com.google.gcloud.datastore.DatastoreServiceOptions;
import com.google.gcloud.datastore.Entity;
import com.google.gcloud.datastore.Key;
import com.google.gcloud.datastore.KeyFactory;
public class HelloDatastore {
private static final String DATASET = "gcloud-datastore-demo";
public static void main(String[] args) {
DatastoreServiceOptions options = DatastoreServiceOptions.builder().dataset(DATASET).build();
DatastoreService datastore = DatastoreServiceFactory.getDefault(options);
KeyFactory keyFactory = datastore.newKeyFactory().kind("Person");
Key key = keyFactory.newKey("Jimmy");
System.out.println("Trying to get the entity by its key!");
Entity entity = datastore.get(key);
if (entity == null) {
System.out.println("Entity not found! Creating it!");
entity = Entity.builder(key)
.set("name", "John Doe")
.set("age", 30)
.set("updated", false)
.build();
datastore.put(entity);
} else {
System.out.println("Entity found! Updating it!");
boolean updated = entity.getBoolean("updated");
if (!updated) {
String[] name = entity.getString("name").split(" ");
entity = Entity.builder(entity)
.set("name", name[0])
.set("last_name", name[1])
.set("updated", true)
.remove("old_property")
.set("new_property", 1.1)
.build();
datastore.update(entity);
}
}
System.out.println("Done!");
}
}I can get it to compile just fine, then I run into problems running the class. Apparently I need Guava? And google-auth-library-java ? And google-api-java-client ?
What exactly is the best way to get this so that I can run... java HelloDatastore and I'll see some stuff happening.... ?
(Sorry for the dumb question....)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
🚨 criticalP0 critical issue. Requires immediate fixP0 critical issue. Requires immediate fixapi: coreauthtriage meI really want to be triaged.I really want to be triaged.
Activity
aozarov commentedon Mar 19, 2015
When using maven one's artifact does not include/bundle all its dependencies.
There are various ways to deal with it but the most recommended way for someone that consumes
a maven artifact[s] is to make its code using maven (http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html) and adding gcloud-java as a dependency as such:
For latest versions one could use: http://search.maven.org/#search%7Cga%7C1%7Cgcloud-java
If you want to run your code (not as a test via "mvn test") you have various options. here are some references:
http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/
http://mojo.codehaus.org/exec-maven-plugin/examples/example-exec-for-java-programs.html
There are other options such as using ant and ivy (http://ant.apache.org/ivy/history/2.2.0/tutorial/start.html) or using tools or various maven plugins to bundle all jars (latter is not recommended).
aozarov commentedon Mar 20, 2015
@jgeewax let me know what you want to do about this one?
jgeewax commentedon Mar 23, 2015
Is there any value is having a "starter-project" template (not the expense report example -- but one that is just a blank template) ?
aozarov commentedon Mar 23, 2015
I think little value. All 3 main IDEs have an option for creating a "starter" maven project and an easy way to add dependencies. Yes, we could create a simple "hello gcloud java" simple project with maven, ant and gradle config files (already configured to pull gcloud-java) (we could also provide project configuration for all 3 main IDEs but I am not sure that is a great idea, especially when configuration may differ between IDEs versions) but I think one could also clone the "expense report" project (when available) and trim the unnecessary files. In any case, I don't object the idea (but not sure where exactly to put it - see: https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html -- as I don't think we need to create another gitHub project for it).
18 remaining items
build: configuration files update (#34)
deps: update dependency google-cloud-storage to v2.5.0 (#34)
deps: update dependency typing-extensions to v4.3.0 (#34)
deps: update dependency typing-extensions to v4.3.0 (#34)
deps: update dependency jeepney to v0.8.0 (#34)
chore(main): release 0.1.1 (#35)
chore(main): release 0.1.3 (#30)
chore(main): release 0.1.0 (#7)
chore(main): release 0.1.0 (#7)
chore(main): release 0.1.0 (#7)
Merge pull request #34 from anthmgoogle/3lo02pr
Merge pull request #34 from anthmgoogle/3lo02pr
chore(deps): update dependency com.google.http-client:google-http-cli…
chore(deps): update dependency com.google.http-client:google-http-cli…
chore(deps): update google.core.version to v1.91.3 (googleapis#34)