【发布时间】:2014-08-28 05:36:01
【问题描述】:
我是按照 sonatype 的书给出的这个例子学习 maven 的新手。这是一个最简单的 pom.xml 文件(工作正常)。但我的问题是,maven (mvn install) 如何找到安装在我机器上的 Java 编译器 (javac)?这个 POM 文件没有以任何方式指定 JDK。谢谢解释。
编辑:
作为比较,我按照书中的下一个示例进行操作,这一次,我收到了一个编译错误,因为它找不到 javax。我的 java 文件在其中,正如书中建议的那样:src/main/java/org/sonatype/mavenbook/web/SimpleServlet.java
现在当我运行 mvn compile 时,我在下面收到错误消息。为什么现在maven找不到编译器:
ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project simple-webapp: Compilation failure: Compilation failure:
[ERROR] /home/abigail/study/simple-webapp/src/main/java/org/sonatype/mavenbook/web/SimpleServlet.java:[4,1] package javax.servlet does not exist
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/maven- v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.simpleweb</groupId>
<artifactId>simple-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>simple-webapp</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
-
我确实设置了这个变量,但不确定它是否重要。