将 JRE 添加到 Maven 项目类路径

Add JRE to Maven project classpath

我是 Maven 的新手,我 运行 遇到了以下问题:我已经创建了一个示例 Maven 项目,并且正在尝试创建一些 war。我已经向我的 pom.xml 添加了几个依赖项,但我就是不知道如何将 JRE 添加到类路径。当我编译 war 模块时,出现以下错误:

[ERROR] /C:/path/to/class/PreferredMapper.java:[3,44] package com.sun.xml.internal.bind.marshaller does not exist
[ERROR] /C:/path/to/class/PreferredMapper.java:[11,38] cannot find symbol
  symbol: class NamespacePrefixMapper

Class NamespaceprefixMapper 包含在 JRE 的库 rt.jar 中,所以我猜测我的 JRE 不在编译类路径中。我已经尝试将 JRE 添加为我的依赖项 pom.xml,但它不起作用。

将 JRE 库添加到类路径的正确方法是什么?

编辑 1:

War 模块 pom.xml:

<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.example</groupId>
    <artifactId>multi-module-project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>war-module</artifactId>
<packaging>war</packaging>
<name>WarModule</name>
<description>WAR module</description>

<dependencies>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
    </dependency>
    <dependency>
        <groupId>aopalliance</groupId>
        <artifactId>aopalliance</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
    <dependency>
        <groupId>com.ibm.ws.admin</groupId>
        <artifactId>client</artifactId>
    </dependency>
    <dependency>
        <groupId>com.ibm.ws.ejb</groupId>
        <artifactId>thinclient</artifactId>
    </dependency>
</dependencies>

这是一个带有 ear 和 war 模块的多模块项目。我正在尝试通过 运行 mvn install 命令将工件安装到我的本地存储库。

我会添加一个属性部分,其中包括以下内容(根据需要更改版本)

<properties>
    <java.version>1.8</java.version>
</properties>

然后添加编译插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>

我想我见过更优雅的方法,但我已经习惯了。