2016-10-25 18 views
0

サーブレット用の単体テストを作成しようとしています。明らかにビルドプロセスに影響を与えるmaven(私は思う)にはいくつかの問題があります。プロジェクトのクラスパステストでjava ee apiが見つからない

私はいくつかの研究を行い、明らかにこれは既知の問題です。 pom.xmlのjavaee-web-api依存関係の場所を変更することです。

残念なことに、このソリューションは私のためには機能しません。これはコーディングよりも構成に多くの時間を費やしているので、非常に不満です。

この問題を解決するにはどうすればよいでしょうか、あるいはテストのための他の解決策がありますか?

私はmavenとNetBeansを使用しています。

はorg.glassfish.extras依存関係がそれを解決するための追加

<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.12</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.hamcrest</groupId> 
     <artifactId>hamcrest-core</artifactId> 
     <version>1.3</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-web-api</artifactId> 
     <version>6.0</version> 
     <scope>provided</scope> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.1.1</version> 
      <configuration> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
+0

提供手段、おそらくあなたの代わりにテストを使用したいですか? –

+0

あなたはエラーを投稿できますか?あなたのプロジェクトDynamic Web Moduleのバージョンは何ですか? – Fabio

+0

6.0の 'javax/javaee- *'アーチファクトはこの問題で有名です。コンパイルには問題ありませんが、実行時に使用するために必要なコンテンツは削除されています。 –

答えて

1

、ありがとうございました。

このquesionを参照してください。 "すでにクラスパス上の" Testing against Java EE 6 API

<modelVersion>4.0.0</modelVersion> 

<groupId>com.mycompany</groupId> 
<artifactId>mavenproject1</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>war</packaging> 

<name>mavenproject1</name> 

<dependencies> 
    <dependency> 
     <groupId>org.glassfish.extras</groupId> 
     <artifactId>glassfish-embedded-all</artifactId> 
     <version>3.0.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.12</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.hamcrest</groupId> 
     <artifactId>hamcrest-core</artifactId> 
     <version>1.3</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-web-api</artifactId> 
     <version>6.0</version> 
     <scope>provided</scope> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.1.1</version> 
      <configuration> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
<repositories> 
    <repository> 
     <id>glassfish-extras-repository</id> 
     <url>http://download.java.net/maven/glassfish/org/glassfish/extras</url> 
    </repository> 
</repositories> 

関連する問題