为什么在Maven中编译命令失败?

时间:2020-10-04 02:41:45

标签: java maven cmd

我是Maven的新手,正在尝试通过命令提示符运行。命令mvn build成功清除了命令。但是它无法生成编译和测试命令。 这是我的cmd屏幕

enter image description here

    <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>
    
      <groupId>bigProjectName</groupId>
      <artifactId>SubProjectName</artifactId>
      <packaging>jar</packaging>
      <version>0.0.1-SNAPSHOT</version>
      <name>SubProjectName</name>
      <url>http://maven.apache.org</url>
      
      <profiles>
      <profile>
      <id>Regression</id>
      
      </profile>
      </profiles>
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    
    <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>3.0.0-M5</version>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
      
      <dependencies>
      
      <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.0.0-alpha-6</version>
      </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
      <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.3.0</version>
        <scope>test</scope>
      </dependency>
    <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
      <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>7.3.0</version>
      </dependency>
    
      </dependencies>
    </project>

请建议我该怎么办?

2 个答案:

答案 0 :(得分:4)

添加两个属性以指定要定位的Java版本。当前,它的默认值为5(不再受支持)。例如,

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

答案 1 :(得分:0)

使用类似这样的东西

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>core01</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>foobar</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>fuu</groupId>
            <artifactId>bar</artifactId>
            <version>foo</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>8</source>
                        <target>8</target>              
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

关注这些行以设置编译器的Java版本

<properties>
    <java.version>8</java.version>
</properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>8</source>
                        <target>8</target>              
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

必须声明maven-compiler-plugin。您可以将数字8(Java版本)更改为至少71112等,具体取决于您的JDK版本。