1

示されているように、Maven Plugin を使用して Eclipse IDE で Web アプリケーションを作成しました。 ここに画像の説明を入力

そのプロジェクトでサーブレットを作成しました

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>com</groupId>
  <artifactId>MTest</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>MTest 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>MTest</finalName>
  </build>
</project>

pom.xml を右クリックして Run as Maven Install を実行すると

サーブレットのクラス ファイルが表示されませんでした

C:\Users\sai\OfficeWSApril14\MTest\target\MTest\WEB-INF\classes

その結果、そのスローClassNotFoundException

私が間違っていたことを教えてください

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MTest Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ MTest ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ MTest ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ MTest ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\sai\OfficeWSApril14\MTest\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ MTest ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.7.1:test (default-test) @ MTest ---
[INFO] Surefire report directory: C:\Users\sai\OfficeWSApril14\MTest\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ MTest ---
[INFO] Packaging webapp
[INFO] Assembling webapp [MTest] in [C:\Users\sai\OfficeWSApril14\MTest\target\MTest]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\sai\OfficeWSApril14\MTest\src\main\webapp]
[INFO] Webapp assembled in [107 msecs]
[INFO] Building war: C:\Users\sai\OfficeWSApril14\MTest\target\MTest.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored 
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
[INFO] 
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ MTest ---
[INFO] Installing C:\Users\sai\OfficeWSApril14\MTest\target\MTest.war to C:\Users\sai\.m2\repository\com\MTest\0.0.1-SNAPSHOT\MTest-0.0.1-SNAPSHOT.war
[INFO] Installing C:\Users\sai\OfficeWSApril14\MTest\pom.xml to C:\Users\sai\.m2\repository\com\MTest\0.0.1-SNAPSHOT\MTest-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.536s
[INFO] Finished at: Mon Apr 29 10:10:06 IST 2013
[INFO] Final Memory: 5M/15M
[INFO] ---------------------

Eclipse IDE Project create new Servlet を右クリック
すると、ソースファイルが src/main/java の下に配置されるようにするにはどうすればよいですか??

スクリーンショットを添付しましたので、ご覧ください

ここに画像の説明を入力

4

1 に答える 1

1

は次のように私たちを示しているのでMaven: -

[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ MTest ---
[INFO] No sources to compile

これは、既知の Java クラスがないことを意味します。コードを見直して、ソース ファイルがsrc/main/java

編集

についてのあなたの質問を達成するための2つの可能な方法がありますhow can i move the servelet under src/main/java ?

1 既存の を次の手順で に変換しMaven Java ProjectますDynamic Web Project。 -

  1. Right clickあなたのプロジェクトで。

  2. Propertiesコンテキスト メニューから を選択します。

  3. Properties Windows 選択でProject Facets

  4. で以下を選択してright hand panelください: -

    1. 動的 Web モジュール: 3.0
    2. ジャワ: 1.6
    3. Java スクリプト: 1.0
  5. クリックOK button

2Maven Web Project次の手順を使用して新規作成します。 -

  1. メニューに移動しますFile ---> New ---> Other
  2. で、Select Wizard Windowsを選択しますMaven ---> Project
  3. [次へ] をクリックし、必要な情報を入力して、 に進みますNew Maven Project
  4. Filterテキストボックスに と入力しますwebapp-javaee6
  5. を選択しorg.codehaus.mojo.archetypes:webapp-javaee6:1.5ます。
  6. 次へをクリックし、必要な情報を入力してプロジェクトの作成を完了します。

pom.xmlさらなる開発に非常に役立つ追加の構成があるため、代わりに 2 番目の方法をお勧めします。How do I configure a Java EE maven project in Eclipse?の全文に関する以前の回答を参照することもできます。

これが役立つことを願っています。

于 2013-04-29T05:52:19.377 に答える