[英]Add JRE to Maven project classpath
我是Maven的新手,但遇到了以下问题:我创建了一个示例Maven项目,并且正试图发动战争。 我已经在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
类NamespaceprefixMapper
包含在JRE的库rt.jar
,因此我猜测我的JRE不在编译类路径中。 我已经尝试将JRE添加为我的pom.xml的依赖项,但是它不起作用。
将JRE库添加到类路径的正确方法是什么?
编辑1:
战争模块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>
这是一个带有耳和战争模块的多模块项目。 我正在尝试通过运行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>
我想我已经看到了更优雅的方法,但这就是我的习惯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.