Javaの11アプリをクイックスタートするMavenのリポジトリがあります

Prakharミシュラ:

:私はここに見ることができるように、クイックスタートMavenの原型のJava 7のためにありますhttps://maven.apache.org/archetypes/maven-archetype-quickstart/これに伴う問題は、私は、このコマンドを起動したとき:

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart

プロジェクトディレクトリを入力して、このコマンドを発射。

mvn package

私はこのエラーを取得します:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project gfg-stuff: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test failed. NullPointerException

してくださいノート私のJDKをインストールするといくつかの問題があること、などupdate-alternatives私はJDK 11を実行していることを私に伝えます。

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1101      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1101      manual mode
  2            /usr/lib/jvm/java-8-oracle/jre/bin/java       1081      manual mode

私が実行した場合でも、java -versionそれは私にこれを与えます:

$ java -version
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3, mixed mode)

私は、なぜ私は私が唯一の最初の場所でJDK 11をインストールしているという事実にもかかわらず、OpenJDKの11を取得しておりませんことを確認していません。たぶん、その上の別のスレッドを開始します。

バジルボーク:

TL; DR

quickstart原型、悲しいことに、多くの場合、外の日付です。

あなたの更新maven-surefire-pluginなどの最新バージョンにPOMの要素を3.0.0-M3

あなたの依存関係は、現在のバージョンに更新します

奇妙なことに、maven-archetype-quickstartアーティファクトは最新に保たれることはありませんこれは、最新のJavaのバージョン、あなたのIDE、または他のライブラリとうまく動作しない場合があり、旧バージョンとの依存関係を示しています。

あなたはアーティファクトが最新に保たれることになるいくつかの自動化スクリプトを経由して思うだろう、これは非常にイライラさせられます。結局のところ、Mavenの全体のポイントは、構成雑用のこの種のは簡単で自動化することです!

幸いなことに、あなたは簡単にバージョン番号を自分で更新することができます。

どのように各依存関係のために入力する最新のバージョン番号は何を知っていますか?

  • あなたは、Mavenのリポジトリのウェブサイトを使用して、手動で最新のバージョン番号を調べることができます。あなたのPOMにバージョン番号をコピー&ペーストします。
  • あなたは、バージョン番号のXML要素の値を編集して、あなたのIDE(などのIntelliJ、NetBeansは、)最新の番号を提案させることができます。あなたは、またはあなたのIDEの動作方法に応じて、いくつかの「ヘルプ・ミー」のキーストロークを入力しない場合があります。これを行う前に、それは現在の最新バージョン番号を知っているので、MavenのリポジトリデータのあなたのIDEのキャッシュを更新してください。例えば、IntelliJの中の好みに行き、そして設定の検索フィールドに、タイプrepo、および既知のリポジトリのリスト内の各クリックUpdateボタンを。

ステップ

まず、Mavenので動作するようにあなたのIDEを使用している場合、あなたが最新になっているので、Mavenのリポジトリデータのキャッシュを更新してくださいquickstartアーティファクトを。例えば、IntelliJので、Preferences> Build, Execution, Deployment> Build tools> Maven> Repositories> Updateボタンをクリックします。

ここでは、画像の説明を入力します。

最初のPOMは、大きな一つに展開する必要があります。あなたは、Mavenを必要とすることcleaninstall

最初に使用した後、あなたのPOMを経ます。

<?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>work.basil.work.example</groupId>
  <artifactId>quickstart</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>quickstart</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

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

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

POMの各要素には、最新のバージョン番号を変更。

あなたのIDEはあなたにそれを知っているのバージョン番号の一覧を示すことによって助けることができます。

ここでは、画像の説明を入力します。

または最新のバージョン番号を確認するためのMavenリポジトリのウェブサイトを使用しています。同様に、この

ここでは、画像の説明を入力します。

あなたは、ほとんどの項目のは古くているかもしれません。特に、質問で説明した確実な問題に関しては、V3に確実な要素を変更します。

    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.0.0-M3</version>
    </plugin>

This will fix your surefire specifically, in my experience. Some problems were recently fixed in later versions. I don’t recall the nature of the problems, perhaps related to the Java Platform Module System.

My version of the POM after updating to the latest as of 2019-05-29.

<?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>work.basil.work.example</groupId>
  <artifactId>quickstart</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>quickstart</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

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

  <dependencies>
    <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>5.5.0-M1</version>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>3.0.0-M3</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.1.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>3.0.0-M1</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>3.0.0-M1</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

JUnit

Notice I also updated JUnit from v4 to the vastly improved v5 "Jupiter". If you do this, you will also need to update the AppTest.java file to simply change the import lines.

Old:

package work.basil.work.example;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

/**
 * Unit test for simple App.
 */
public class AppTest 
{
    /**
     * Rigorous Test :-)
     */
    @Test
    public void shouldAnswerWithTrue()
    {
        assertTrue( true );
    }
}

New:

package work.basil.work.example;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * Unit test for simple App.
 */
public class AppTest 
{
    /**
     * Rigorous Test :-)
     */
    @Test
    public void shouldAnswerWithTrue()
    {
        assertTrue( true );
    }
}

Lastly, do a Maven clean and install to get those latest versions of your dependencies actually installed inside your app.

By the way, for more about JUnit Jupiter, and how to run old JUnit 3 & 4 testes, see my Answer to another Question.

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=181988&siteId=1