Maven の設定を確認します

目的: Maven の設定を設定し、設定が正しいことを確認し、カタログ HERE リソースネーム やスキーマなどのワークスペースリソースの一意の識別子である HERE リソースネーム (Workspace Resources) の概念を紹介します。

複雑さ: 初心者向け

所要時間: 10 分

ソースコード: ダウンロード

この節では、 HERE を使用してサンプルプログラムを記述する方法と、 Maven で最初のプロジェクトを設定する方法について説明します。

プログラムをコンパイルして実行し、ワークスペースリポジトリから単一のライブラリ依存関係をダウンロードし、その API を使用して HERE リソースネーム を構築および検査します。

まだ 行っていない場合は、 HERE Workspace ポータルのリポジトリページで資格情報を生成をクリックして、 HERE Data SDK for Java & Scala の Maven 設定を取得します。

このコンテキストの「資格情報」は、 Maven 設定でエンコードされたリポジトリ資格情報を参照しています。 これらの資格情報を使用すると、プラットフォーム資格情報 for Java および Scala ライブラリアーティファクトをリポジトリからダウンロードできます。これは、ワークスペース内のカタログやスキーマなどのアセットへのアクセスに使用される HERE Data SDK とは異なります。

プロジェクトの次のフォルダー構造を作成します。

hrn-hello-world
└── src
    └── main
        ├── java
        └── scala

この操作は、次の bash 1 つのコマンドで実行できます。

mkdir -p hrn-hello-world/src/main/{java,scala}

pom.xml Maven の最小限のプロジェクトを作成し、プロジェクトのルートディレクトリに配置します。 このプロジェクトの POM の内容を次に示します。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.here.platform</groupId>
        <artifactId>sdk-standalone-bom_2.12</artifactId>
        <version>2.54.3</version>
        <relativePath/>
    </parent>

    <groupId>com.here.platform.tutorial</groupId>
    <artifactId>verify-m2</artifactId>
    <version>0.2.735</version>

    <name>Verify M2 Settings Tutorial</name>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>https://apache.org/licenses/LICENSE-2.0</url>
            <distribution>repo</distribution>
            <comments>SPDX-License-Identifier: Apache-2.0</comments>
        </license>
    </licenses>

    <properties>
        <encoding>UTF-8</encoding>
        <exec.classpathScope>compile</exec.classpathScope>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.here.hrn</groupId>
            <artifactId>hrn_${scala.compat.version}</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>4.5.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

HERE プロジェクト用の HERE Workspace の作成の詳細については、『 Java for Scala & 開発者ガイド』の「依存関係管理」を参照してください。

これは、該当 hrn-hello-world/src/main/{java,scala} する Scala および Java の実装のソースコードで、適切なフォルダにドロップできます。 メインクラスの後にファイルの名前を入力してください : HRNHelloWorldScala.scala または HRNHelloWorldJava.java、それぞれ。

Scala
Java
/*
 * Copyright (c) 2018-2023 HERE Europe B.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.here.hrn.HRN

object HRNHelloWorldScala extends App {

  // HRN for the simulated sensor data at https://platform.here.com/data/hrn:here:data::olp-here:olp-sdii-sample-berlin-2
  val hrn = HRN.fromString("hrn:here:data::olp-here:olp-sdii-sample-berlin-2")
  println("HRN: \"" + hrn + "\"")
  println("\tpartition: \"" + hrn.partition + "\"")
  println("\tservice: \"" + hrn.service + "\"")
  println("\tregion: \"" + hrn.region + "\"")
  println("\taccount: \"" + hrn.account + "\"")
  println("\tresource: \"" + hrn.resource + "\"")
}

/*
 * Copyright (c) 2018-2023 HERE Europe B.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import static java.lang.System.out;

import com.here.hrn.HRN;

public class HRNHelloWorldJava {

  public static void main(String[] args) {
    // HRN for the simulated sensor data at
    // https://platform.here.com/data/hrn:here:data::olp-here:olp-sdii-sample-berlin-2
    HRN hrn = HRN.fromString("hrn:here:data::olp-here:olp-sdii-sample-berlin-2");
    out.println("HRN: \"" + hrn + "\"");
    out.println("\tpartition: \"" + hrn.partition() + "\"");
    out.println("\tservice: \"" + hrn.service() + "\"");
    out.println("\tregion: \"" + hrn.region() + "\"");
    out.println("\taccount: \"" + hrn.account() + "\"");
    out.println("\tresource: \"" + hrn.resource() + "\"");
  }
}

IDE を使用するか、または次のコマンドを使用してコマンド ラインからコードを実行できるようになりまし mvnた。

Scala を実行します
Java を実行します
mvn compile exec:java -Dexec.mainClass=HRNHelloWorldScala
mvn compile exec:java -Dexec.mainClass=HRNHelloWorldJava

Java プログラムと Scala プログラムの両方から、次の出力が予想されます。


HRN: "hrn:here:data::olp-here:olp-sdii-sample-berlin-2"
	partition: "here"
	service: "data"
	region: ""
	account: ""
	resource: "olp-sdii-sample-berlin-2"

この出力は、 HERE リソースネーム が 「データ」サービスによって管理されているリソースを表していることを示しています。このサービスは、 HERE Workspace 内のカタログを管理します。 カタログ自体の識別子が リソース フィールドに表示されます。

パーティション の値は「 HERE 」です。 [ パーティション ] フィールドを使用して、同じ代表的なデータをホストするが、対象ユーザーごとに異なる環境を区別できます。 このうちの 1 つのユースケース は、中国パーティションを使用している開発者がカタログを利用できるようにするために、 "here-cn" ポータルの下で中国環境にカタログを公開することです。

リソースの所有者は 、リージョン および アカウントの値を使用 して、特定されたリソースの範囲をさらに指定および絞り込むこともできます。

詳細情報

リポジトリ資格情報 を確認して HERE Data SDK for Java & Scala アーティファクトをダウンロードすると 、 プラットフォーム 資格情報 を確認してカタログデータにアクセスできます。

」に一致する結果は 件です

    」に一致する結果はありません