{"id":1009,"date":"2020-12-01T20:54:37","date_gmt":"2020-12-01T11:54:37","guid":{"rendered":"https:\/\/www.typea.info\/blog\/?p=1009"},"modified":"2020-12-01T20:54:37","modified_gmt":"2020-12-01T11:54:37","slug":"vscode_java_maven_firestore","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2020\/12\/01\/vscode_java_maven_firestore\/","title":{"rendered":"VSCode+Java+Maven\u3067Firestore\u306b\u30c7\u30fc\u30bf\u767b\u9332"},"content":{"rendered":"<p>\u00a0<\/p>\n<p><a href=\"https:\/\/www.amazon.co.jp\/%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E3%83%AC%E3%82%B9%E9%96%8B%E7%99%BA%E3%83%97%E3%83%A9%E3%83%83%E3%83%88%E3%83%95%E3%82%A9%E3%83%BC%E3%83%A0-Firebase%E5%85%A5%E9%96%80-%E6%8E%8C%E7%94%B0%E6%B4%A5%E8%80%B6%E4%B9%83-ebook\/dp\/B07X5FR7XR\/ref=as_li_ss_il?__mk_ja_JP=%E3%82%AB%E3%82%BF%E3%82%AB%E3%83%8A&amp;dchild=1&amp;keywords=firebase&amp;qid=1606822818&amp;sr=8-2&amp;linkCode=li2&amp;tag=typea09-22&amp;linkId=cdc73b09622c0516ce94b4877694b027\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"\/\/ws-fe.amazon-adsystem.com\/widgets\/q?_encoding=UTF8&amp;ASIN=B07X5FR7XR&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=JP&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=typea09-22\" border=\"0\" \/><\/a><img loading=\"lazy\" decoding=\"async\" style=\"border: none !important; margin: 0px !important;\" src=\"https:\/\/ir-jp.amazon-adsystem.com\/e\/ir?t=typea09-22&amp;l=li2&amp;o=9&amp;a=B07X5FR7XR\" alt=\"\" width=\"1\" height=\"1\" border=\"0\" \/><\/p>\n<p>\u00a0<\/p>\n<p>Firestore\u3078\u306e\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\u3084\u66f8\u304d\u8fbc\u307f\u3092\u3001<\/p>\n<ul>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2020\/03\/28\/firebase-hosting-firestore\/\">Firebase Hosting<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2020\/03\/29\/cloud-functions-firestore-bind\/\">Cloud Functions<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2020\/04\/04\/firebase-hosting-firestore-release\/\">Angular<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2020\/04\/11\/flutter_cloud_firestore_android\/\">Flutter(Android)<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2020\/04\/16\/flutter-cloud-firestore-iphone\/\">Fltter(iPhone)<\/a><\/li>\n<\/ul>\n<p>\u3067\u78ba\u8a8d\u3057\u3066\u304d\u305f\u3093\u3060\u3051\u3069\u3001\u30c7\u30fc\u30bf\u3092\u30d0\u30c3\u30c1\u767b\u9332\u3057\u305f\u308a\u3057\u305f\u3044\u306e\u3067\u3001VSCode \u3068 Java\u3067\u74b0\u5883\u3092\u4f5c\u308b\u3002<\/p>\n<h2>1.VSCode\u306e\u6e96\u5099<\/h2>\n<h3>1.1\u3000Java Extension Pack \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>Extensions\u3067\u3001Java\u3092\u691c\u7d22\u3057\u3066\u62e1\u5f35\u30d1\u30c3\u30af\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/vscode_java_extension.png\"><img loading=\"lazy\" decoding=\"async\" title=\"vscode_java_extension.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/vscode_java_extension.png\" alt=\"Vscode java extension\" width=\"599\" height=\"206\" border=\"0\" \/>V<\/a><\/p>\n<h3>1.2 Java\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210<\/h3>\n<p>\u5de6\u4e0b\u306e JAVA PROJECTS \u304b\u3089\u3001Create new Java project \u3092\u9078\u629e\u3057\u3001\u3055\u3089\u306b Maven \u3092\u9078\u629e\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/java_maven_project.png\"><img loading=\"lazy\" decoding=\"async\" title=\"java_maven_project.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/java_maven_project.png\" alt=\"Java maven project\" width=\"599\" height=\"454\" border=\"0\" \/><\/a><\/p>\n<h3>1.3 Maven\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u9078\u629e<\/h3>\n<p>maven-archetype-quickstart \u3092\u9078\u629e<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/maven_quick_start.png\"><img loading=\"lazy\" decoding=\"async\" title=\"maven_quick_start.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/maven_quick_start.png\" alt=\"Maven quick start\" width=\"599\" height=\"345\" border=\"0\" \/><\/a><\/p>\n<p>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u304c\u5b9f\u884c\u3055\u308c\u308b\u3068\u5171\u306b\u3001TERMINAL\u3067\u3001groupId \u3068 artifactId \u3092\u30bf\u30a4\u30d7\u3057\u3066\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u96db\u5f62\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/maven_archtype.png\"><img loading=\"lazy\" decoding=\"async\" title=\"maven_archtype.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/maven_archtype.png\" alt=\"Maven archtype\" width=\"599\" height=\"297\" border=\"0\" \/><\/a><\/p>\n<h3>1.4 \u4f9d\u5b58\u6027\u306e\u8a18\u8ff0<\/h3>\n<p>pom.xml \u306b\u4f9d\u5b58\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8ffd\u8a18<\/p>\n<p><a href=\"https:\/\/firebase.google.com\/docs\/admin\/setup?hl=ja#java\">https:\/\/firebase.google.com\/docs\/admin\/setup?hl=ja#java<\/a><\/p>\n<pre class=\"prettyprint\">  &lt;dependencies&gt;\n    &lt;dependency&gt;\n      &lt;groupId&gt;junit&lt;\/groupId&gt;\n      &lt;artifactId&gt;junit&lt;\/artifactId&gt;\n      &lt;version&gt;4.11&lt;\/version&gt;\n      &lt;scope&gt;test&lt;\/scope&gt;\n    &lt;\/dependency&gt;\n    &lt;dependency&gt;\n      &lt;groupId&gt;com.google.firebase&lt;\/groupId&gt;\n      &lt;artifactId&gt;firebase-admin&lt;\/artifactId&gt;\n      &lt;version&gt;7.0.1&lt;\/version&gt;\n    &lt;\/dependency&gt;\n  &lt;\/dependencies&gt;\n<\/pre>\n<p>pom.xml \u3092\u5909\u66f4\u3059\u308b\u3068\u3001\u5909\u66f4\u3092\u691c\u77e5\u3057\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30c0\u30a4\u30a2\u30ed\u30b0\u304c\u8868\u793a\u3055\u308c\u308b\u3002Now\u3092\u9078\u3076\u3068\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u304c\u958b\u59cb<\/p>\n<p>~\/.m2 \u4ee5\u4e0b\u306b\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u308c\u53c2\u7167\u8a2d\u5b9a\u304c\u884c\u308f\u308c\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/pom_reflesh.png\"><img loading=\"lazy\" decoding=\"async\" title=\"pom_reflesh.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/pom_reflesh.png\" alt=\"Pom reflesh\" width=\"497\" height=\"195\" border=\"0\" \/><\/a><\/p>\n<h2>2.Google Cloud Platform \u306e\u8a2d\u5b9a<\/h2>\n<h3>2.1 \u8a8d\u8a3c\u30d5\u30a1\u30a4\u30eb\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3001GCP\u306e\u7ba1\u7406\u30da\u30fc\u30b8\u3001IAM\u3000\u304b\u3089\u3001\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u9375\u3092\u4f5c\u6210\u3067\u3001JSON\u5f62\u5f0f\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/h3>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/gcp_key_create.png\"><img loading=\"lazy\" decoding=\"async\" title=\"gcp_key_create.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/gcp_key_create.png\" alt=\"Gcp key create\" width=\"599\" height=\"269\" border=\"0\" \/><\/a><\/p>\n<h3>2.2 \u8a8d\u8a3c\u30d5\u30a1\u30a4\u30eb\u3092\u74b0\u5883\u8a2d\u5b9a<\/h3>\n<p>\u4fdd\u5b58\u3057\u3066PATH \u3092\u74b0\u5883\u5909\u6570\u306bexport \u00a0~\/.bash_profile<\/p>\n<p>export GOOGLE_APPLICATION_CREDENTIALS=&#8221;\/home\/user\/Downloads\/service-account-file.json&#8221;<\/p>\n<p>.bash_profile \u3092\u30ea\u30ed\u30fc\u30c9\u3057\u3001\u78ba\u8a8d<\/p>\n<pre class=\"prettyprint\">ash-3.2$ source ~\/.bash_profile\nbash-3.2$ env | grep \"GOOGLE\"\nGOOGLE_APPLICATION_CREDENTIALS=\/Users\/hirotoyagi\/keys\/typea-info-service-xxxxxxxxxxx.json\n<\/pre>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u3001\u8a8d\u8a3c\u60c5\u5831\u3092\u3092\u30ed\u30fc\u30c9\u3059\u308b<\/p>\n<p>FirebaseOptions.builder().setCredentials(GoogleCredentials.getApplicationDefault())<\/p>\n<h2>3.\u30b5\u30f3\u30d7\u30eb\u5b9f\u88c5<\/h2>\n<h3>3.1 \u4e0a\u8a18\u307e\u3067\u6e96\u5099\u3057Firestore\u306b\u767b\u9332\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u3092\u4f5c\u6210<\/h3>\n<pre class=\"prettyprint\">package info.typea.songdict.sample;\n\nimport java.util.HashMap;\nimport java.util.Map;\n\nimport com.google.api.core.ApiFuture;\nimport com.google.auth.oauth2.GoogleCredentials;\nimport com.google.cloud.firestore.DocumentReference;\nimport com.google.cloud.firestore.Firestore;\nimport com.google.cloud.firestore.WriteResult;\nimport com.google.firebase.FirebaseApp;\nimport com.google.firebase.FirebaseOptions;\nimport com.google.firebase.cloud.FirestoreClient;\n\npublic class FirestoreSample {\n\n    public void doEntry() {\n\n        FirebaseOptions options;\n        try {\n            options = FirebaseOptions.builder().setCredentials(GoogleCredentials.getApplicationDefault())\n                    .setDatabaseUrl(\"https:\/\/typea-info-service.firebaseio.com\")\n                    .build();\n            FirebaseApp.initializeApp(options);\n\n            Firestore db = FirestoreClient.getFirestore();\n\n            DocumentReference docRef = db.collection(\"songdict\").document(\"v1\")\n                                        .collection(\"work\").document(\"test\");\n            Map&lt;String, Object&gt; data = new HashMap&lt;&gt;();\n            data.put(\"first\", \"Ada\");\n            data.put(\"last\", \"Lovelace\");\n            data.put(\"born\", 1815);\n            \/\/asynchronously write data\n            ApiFuture result = docRef.set(data);\n\n            \/\/ result.get() blocks on response\n            System.out.println(\n                String.format(\"Firestore updated at : %s\", result.get().getUpdateTime()));\n\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n}\n<\/pre>\n<p>3.2 \u5b9f\u884c\u3057Firebase\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u3001Firestore\u3092\u78ba\u8a8d<\/p>\n<p>\u5b9f\u884c\u3067\u3001Firestore \u306b\u30c7\u30fc\u30bf\u304c\u767b\u9332\u3067\u304d\u305f\uff01\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"firestore_saved.png\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/12\/firestore_saved.png\" alt=\"Firestore saved\" width=\"599\" height=\"237\" border=\"0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 Firestore\u3078\u306e\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\u3084\u66f8\u304d\u8fbc\u307f\u3092\u3001 Firebase Hosting Cloud Functions Angular Flutter(Android) Fltter(iPhone) \u3067\u78ba\u8a8d\u3057\u3066\u304d\u305f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1008,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[104,6,96],"tags":[122,123,124,125],"class_list":["post-1009","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-firebase","category-java","category-visual-studio-code","tag-firebase","tag-firestore","tag-java","tag-vscode"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1009"}],"version-history":[{"count":1,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1009\/revisions"}],"predecessor-version":[{"id":1010,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1009\/revisions\/1010"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media\/1008"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}