jenetics / jpx

JPX - Java GPX library
Apache License 2.0
202 stars 30 forks source link

The import io.jenetics.jpx cannot be resolved. #165

Closed jimmyhealer closed 2 years ago

jimmyhealer commented 2 years ago

Hello, I'm trying to use jpx, however when I import jpx, vscode gives me The import io.jenetics.jpx cannot be resolved. What step did I do wrong?

my java version openjdk 17.0.3 2022-04-19 LTS

import io.jenetics.jpx.*; // The import io.jenetics.jpx cannot be resolved

public class GpxParser {

  final GPX gpx; // GPX cannot be resolved to a type

  public GpxParser() {
    gpx = GPX.builder()
    .addTrack(track -> track
        .addSegment(segment -> segment
        .addPoint(p -> p.lat(48.20100).lon(16.31651).ele(283))
        .addPoint(p -> p.lat(48.20112).lon(16.31639).ele(278))
        .addPoint(p -> p.lat(48.20126).lon(16.31601).ele(274))))
    .build();
  }

  public void write(String filename) throws IOException{
    System.out.println(filename);
    GPX.write(gpx, Path.of(filename));
  }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.0</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.example</groupId>
  <artifactId>example</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>example</name>
  <description>Demo project for Spring Boot</description>
  <properties>
    <java.version>17</java.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.jenetics/jenetics -->
    <dependency>
      <groupId>io.jenetics</groupId>
      <artifactId>jenetics</artifactId>
      <version>7.0.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.jenetics/jpx -->
    <dependency>
      <groupId>io.jenetics</groupId>
      <artifactId>jpx</artifactId>
      <version>3.0.1</version>
      <scope>runtime</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

</project>
jenetics commented 2 years ago

Hi, the reason might be the Java module system. If the JPX library is put into the module path, you have to add requires io.jenetics.jpx in your module-info.java file. Putting the libs into the classic classpath_ might also work. Since I'm not a Maven expert, I don't know the default behavior of your pom.

Regards Franz

jimmyhealer commented 2 years ago

Thank! Finally I am modifying the pom dependency option scope. Originally, it was copied directly from maven, but I didn't check it carefully.