2017-02-07 4 views
1

私はJenkinsで実行しているmavenプロジェクトを持っています。プロジェクトには、プロジェクトのルートディレクトリ下のresourcesフォルダー内のconfig.propertiesファイルが含まれています。ときどき&をコンパイルすると、エラーが発生します。Exception: java.io.FileNotFoundException: property file 'config.properties' not found in the classpathJava Mavenプロジェクトのコマンドプロンプトで 'project> clean'を実行する方法

「プロジェクト>クリーン」を実行すると、このエラーを取り除きます。しかし、私はジェンキンスでバッチファイルを使ってこれを実行しているので、 'プロジェクト>クリーン'はできません。汚れた回避策として、私はeclipseでプロジェクトを開き、 'Project> Clean'を実行し、その後Jenkinsでプロジェクトを再構築します。

Jenkinsのバッチファイルから「プロジェクト>クリーン」を実行するにはどうすればよいですか?

更新: これは私のプロジェクト構造の様子です。 config.propertiesファイルには、テストが実行される環境の詳細が格納されます。

enter image description here

のpom.xml:コマンドラインで

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.3</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.18.1</version> 
      <configuration> 
       <forkCount>100</forkCount> 
       <suiteXmlFiles> 
        <suiteXmlFile>testng.xml</suiteXmlFile> 
       </suiteXmlFiles> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 


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

<repositories> 
    <!--other repositories if any --> 
    <repository> 
     <id>project.local</id> 
     <name>project</name> 
     <url>file:${project.basedir}/lib</url> 
    </repository> 
</repositories> 

<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>2.4</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jsoup</groupId> 
     <artifactId>jsoup</artifactId> 
     <version>1.8.3</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.poi</groupId> 
     <artifactId>poi</artifactId> 
     <version>3.9</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.poi</groupId> 
     <artifactId>poi-scratchpad</artifactId> 
     <version>3.9</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.poi</groupId> 
     <artifactId>poi-ooxml</artifactId> 
     <version>3.9</version> 
    </dependency> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.8.5</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpclient</artifactId> 
     <version>4.4.1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-databind</artifactId> 
     <version>2.6.3</version> 
    </dependency> 
    <dependency> 
     <groupId>com.relevantcodes</groupId> 
     <artifactId>extentreports</artifactId> 
     <version>2.41.2</version> 
    </dependency> 
    <dependency> 
     <groupId>com.local</groupId> 
     <artifactId>ewsc</artifactId> 
     <version>1.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.local</groupId> 
     <artifactId>msgparser</artifactId> 
     <version>1.14</version> 
    </dependency> 

</dependencies> 
+0

まず、プロジェクトをクリーンアップする必要はありません。また、ビルド中にEclipseに何らかの形で依存する必要があります。現在の設定についてもっと詳しく投稿できますか?あなたのPOM? 'config.properties'とは何ですか?どのように使用されていますか? – Tunaki

+0

@Tunaki - 質問に答えて詳細を追加しました。その情報が十分であることを願っています。 – Sanu

+1

あなたのプロジェクトのソースコードからJenkins-Filesを移動することを検討するべきです。それはあなたが記述している奇妙な動作を引き起こしているかもしれません...また、config.propertiesは、/リソース/テストでは必要ない場合は/ src/test/resourcesの下に置く必要があります。 – tom

答えて

2

設定、ファイルはフォルダの下にあり/resourcesフォルダが/resources ISNとして、デフォルトでMavenの(またはM2eをEclipseプラグイン)によってピックアップされていないことを

デフォルトのMavenディレクトリ構造の一部です。 デフォルトでは、テストのためだけにリソースが必要な場合は、リソースはsrc/test/resourcesに配置する必要があります。参照ボックスの外にMavenによって検討されているディレクトリのリストについては、

https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

あなたが持っていない場合は、しかし、Mavenのビルドヘルパーをプラグインあなたが考えられフォルダhttp://www.mojohaus.org/build-helper-maven-plugin/usage.htmlを拡張するために使用することができますがありますその道を行く良い理由は、私はデフォルトのディレクトリ構造にこだわることをお勧めします。

-1

mvn clean *target*は、トリックを行う必要があります。

"何らかの理由でコマンドラインにクリーンアップを追加するオプションがない場合、クリーンプラグインをプロジェクトのpom.xmlに入れて、プロジェクトがビルドされるたびに実行されるようにすることができます。

<project> 
    [...] 
    <build> 
    <plugins> 
     <plugin> 
     <artifactId>maven-clean-plugin</artifactId> 
     <version>3.0.0</version> 
     <executions> 
     <execution> 
      <id>auto-clean</id> 
      <phase>initialize</phase> 
      <goals> 
       <goal>clean</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
    [...] 
</project> 

出典:https://maven.apache.org/plugins/maven-clean-plugin/usage.html

+3

'mvn clean'とEclipseの" Project> Clean "オプションは完全に異なっています。 – Tunaki

+0

どうやら、mvn> cleanとproject> cleanを実行した後で、「Exception:java.io.FileNotFoundException:プロパティファイル 'config.properties'がクラスパスに見つかりません」というエラーが表示されます。 – Sanu

関連する問題