How to verify Maven settings
How to verify Maven settings
Objectives: Set up your Maven settings, verify that they are correct, 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: Beginner
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 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.
NoteNotice that "Credentials" in this context refers 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
└── scalaYou 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 and place it in the root directory of your project. 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_2.13</artifactId>
<version>2.85.8</version>
<relativePath/>
</parent>
<groupId>com.here.platform.tutorial</groupId>
<artifactId>verify-m2</artifactId>
<version>0.2.942</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.7.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>The pom.xml file contains the com.here.hrn:hrn_${scala.compat.version} library that allows you to work with HRNs.
Note that the library version is taken from the parent BOM com.here.platform:sdk-standalone-bom_2.13 dependency.
We recommend using BOM files to ensure that SDK library versions are aligned.
For more details on constructing POMs for HERE projects, see the Dependency Management section of the HERE Workspace for 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. Make sure to name the file after the main class: HRNHelloWorldScala.scala or HRNHelloWorldJava.java, respectively.
/*
* Copyright (c) 2018-2026 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.apply("hrn:here:data::olp-here:olp-sdii-sample-berlin-2")
println(s"HRN: '${hrn}'")
println(s" partition: '${hrn.partition}'")
println(s" service: '${hrn.service}'")
println(s" account: '${hrn.account}'")
println(s" resource: '${hrn.resource}'")
}/*
* Copyright (c) 2018-2026 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.printf("HRN: '%s'%n", hrn);
out.printf(" partition: '%s'%n", hrn.partition());
out.printf(" service: '%s'%n", hrn.service());
out.printf(" account: '%s'%n", hrn.account());
out.printf(" resource: '%s'%n", hrn.resource());
}
}You can now run your code either using your IDE or from the command line using
mvn:
mvn compile exec:java -Dexec.mainClass=HRNHelloWorldScalamvn compile exec:java -Dexec.mainClass=HRNHelloWorldJavaThe following is the expected output from both the Java and Scala programs:
HRN: 'hrn:here:data::olp-here:olp-sdii-sample-berlin-2'
partition: 'here'
service: 'data'
account: 'olp-here'
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.
The account value is olp-here. It's the designation of a particular shard of a region specific to a given customer/account, also known as realm.
Further information
Once you have verified your repository credentials to download HERE Data SDK for Java & Scala artifacts, you can verify your platform credentials to access catalog data.
Updated 19 days ago