2017-08-11 9 views
-1

私は私のpom.xmlに、これとバックエンドのプロジェクトを持っている:NoClassDefFoundErrorが

<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>GestionScolaire</groupId> 
    <artifactId>GestionScolaire</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 
    <build> 
    <sourceDirectory>src/java</sourceDirectory> 
... 

はその後、私のフロントエンドプロジェクトは、私の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/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>GestionScolaire</groupId> 
<artifactId>GestionScolaireWeb</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>war</packaging> 
<description>project_Spring</description> 
<name>GestionScolaireWeb</name> 
<url>http://maven.apache.org</url> 
<properties> 
    <java.version>1.6</java.version> 
    <spring.version>3.1.0.RELEASE</spring.version> 
    <cglib.version>2.2.2</cglib.version> 
</properties> 

<dependencies> 
<dependency> 
    <groupId>GestionScolaire</groupId> 
    <artifactId>GestionScolaire</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <type>war</type> 
</dependency> 
私のサーバーの起動時に

Matiere

package model; 

import java.util.List; 

import javax.persistence.Entity; 
import javax.persistence.FetchType; 
import javax.persistence.GeneratedValue; 
import javax.persistence.Id; 
import javax.persistence.JoinColumn; 
import javax.persistence.ManyToOne; 
import javax.persistence.OneToMany; 
import javax.persistence.Version; 

@Entity 
public class Matiere { 

... 

私はこのエラーがあります:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Matiere

君たちは、私はこのエラーを持っている理由のいずれかのアイデアを持っていますか?

ありがとうございます!問題の

+0

私の同僚は2 "Webプロジェクト" を作成していました。クラスはWEB-INFフォルダにありました....とにかくありがとう – Spiiff77

答えて

0

少なくとも一部が、この中にある:私はあなたがしようとしていると思うように

<dependency> 
    <groupId>GestionScolaire</groupId> 
    <artifactId>GestionScolaire</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <type>war</type> 
</dependency> 

あなたはタイプの戦争の成果物を含めている場合は、あなたがそのWEB-INF/classesフォルダからクラスを使用することはできませんそう、あなたが見ているエラーは予想される動作です。

戦争は瓶のようには動作しません。

可能な解決策については、MavenのWARプロジェクトでは、classesをjarとして「公開」することもできます。 このlink hereは、より良い、それを説明します

は、どのように私は自分のWebアプリケーションのクラスを含むJARを作成するのですか?

If you would simply like to package the classes and resources as a JAR in WEB-INF/lib rather than as loose files under WEB-INF/classes, 

次のコンフィギュレーションを使用します。

  <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>3.1.0</version> 
      <configuration> 
       <archiveClasses>true</archiveClasses> 
      </configuration> 
      </plugin> 

If you need to re-use this JAR in another project, the recommended approach is to move the classes to a separate module that builds a 

JARをした後、 としてだけでなく、それを必要とする任意の他のプロジェクトから、WebアプリケーションからそのJARの依存関係を宣言します。分類器と、以下の構成を使用して、

If you can't move the classes to another project, you can deploy the classes and resources included in your webapp as an "attached" 

アーティファクト、:

<project> 
     ... 
     <artifactId>mywebapp</artifactId> 
     <version>1.0-SNAPSHOT</version> 
     ... 
     <build> 
     <plugins> 
      <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>3.1.0</version> 
      <configuration> 
       <attachClasses>true</attachClasses> 
      </configuration> 
      </plugin> 
     </plugins> 
     </build> 
     ... 
    </project> 

This will result in two artifacts being deployed: mywebapp-1.0-SNAPSHOT.war and mywebapp-1.0-SNAPSHOT-classes.jar. 
関連する問題