maven如何找到Java编译器? [英] How does maven find Java compiler?

查看:87
本文介绍了maven如何找到Java编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手学习maven,遵循sonatype的书给出的这个例子。这是一个最简单的 pom.xml 文件(工作正常)。但我的问题是,maven(mvn install)如何在我的机器上安装Java编译器(javac)?此POM文件不以任何方式指定JDK。谢谢你的解释。

I am new to learn maven by following this example given by sonatype's book.This is a simplest pom.xml file (works fine). But my question is, how does maven (mvn install) find Java compiler (javac) installed on my machine? This POM file doesn't specify JDK in any way. Thanks for explanation.

编辑:
作为比较,我正在关注书中的下一个例子,这一次,我收到了编译错误,因为它无法找到javax.My java文件,如书中所示: src / main / java / org / sonatype / mavenbook / web / SimpleServlet.java

现在我运行mvn编译,我收到下面的错误信息。为什么现在maven找不到编译器:

Now as I run mvn compile, and i got error message below. Why now maven can't find the compiler:

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>


推荐答案

如果你走这条路,请说 maven版本3.2.3

If you go to this path, say with maven version 3.2.3

apache-maven-3.2.3-bin\apache-maven-3.2.3\bin

opne mvn.bat ,你可以在下面看到

opne the mvn.bat, you can see below


@REM Maven2启动批处理脚本

@REM Maven2 Start Up Batch script

@REM必需的ENV vars:

@REM Required ENV vars:

@REM JAVA_HOME - JDK主目录的位置

@REM JAVA_HOME - location of a JDK home dir

显然,它从您的环境变量中选择 JAVA_HOME 。下面是文件中的代码段。

Clearly it picks JAVA_HOME, from your environment variables. Below code snippet from the file.

@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto chkMHome
:chkMHome
if not "%M2_HOME%"=="" goto valMHome

for issue,javax.servlet

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>

或任何可用的

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

这篇关于maven如何找到Java编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆