Verify Maven Settings

Objectives: Set up your Maven settings, verify that you have set up the Maven settings correctly, and introduce the concept of a HERE Resource Name (HRN), which is a unique identifier for the Workspace resources such as catalogs and schemas.

Complexity: Easy

Time to complete: 10 min

Source code: Download

This section demonstrates how to write a sample program using the HERE, and how to set up your first project in Maven.

Compile and run the program to download a single library dependency from the Workspace repository, and to use its API to construct and inspect an HRN.

If you have not already done so, click Generate Credentials on the Repository page of the HERE Workspace portal to obtain your Maven settings for the HERE Data SDK for Java & Scala.

Note

Note that "Credentials" in this context refer to the repository credentials encoded in the Maven settings. These credentials allow you to download HERE Data SDK for Java & Scala library artifacts from the repository, as opposed to the platform credentials used to access assets such as catalogs and schemas in the Workspace.

Create the following folder structure for the project.

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

You can do this with a single bash command:

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

Create a minimal pom.xml project for Maven. The contents of the POM for this project are shown below.

<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</artifactId>
        <version>2.21.6</version>
        <relativePath/>
    </parent>

    <groupId>com.here.platform.tutorial</groupId>
    <artifactId>verify-m2</artifactId>
    <version>0.2.380</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.1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

For more details on constructing POMs for HERE projects, see the Dependency Management section of the HERE Data SDK fot Java & Scala Developers.

This is the source code for the respective Scala and Java implementations, which you can drop into the appropriate hrn-hello-world/src/main/{java,scala} folders.

Scala
Java
/*
 * Copyright (c) 2018-2020 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-sdii-sample-berlin-2
  val hrn = HRN.fromString("hrn:here:data:::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-2020 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-sdii-sample-berlin-2
    HRN hrn = HRN.fromString("hrn:here:data:::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() + "\"");
  }
}

You can now run your code either using your IDE or from the command line using mvn:

Run Scala
Run Java
mvn compile exec:java -Dexec.mainClass=HRNHelloWorldScala
mvn compile exec:java -Dexec.mainClass=HRNHelloWorldJava

The expected output from both the Java and Scala programs is as follows:


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

This output indicates that the HRN represents a resource managed by the "data" service, which manages catalogs in the HERE Workspace. The identifier of the catalog itself is in the resource field.

The partition value is "here". You can use the partition field to differentiate between environments that you want to host the same representative data, but for different audiences. One use case of this would be to publish a catalog to China Environment under "here-cn" partition to make it available for developers using China Portal.

The owner of the resource can also use values for region and account to further specify and narrow the scope of the identified resource.

Further Information

Now that you have verified your repository credentials to download HERE Data SDK for Java & Scala artifacts, you can verify your platform credentials to acesss catalog data.

results matching ""

    No results matching ""