1

i have created a maven build of my project.The build was succesfull.But when i deploy it on server (apache tomcat 6) it gives various errors regarding jar files.But those jar files are available on the class path.But when i keep those jar files in the lib directory of server then that error gets resolved.So,anyone having any idea regarding this..I have done anything wrong in building using maven.

My pom.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 Test1 Test1 0.0.1-SNAPSHOT war Test1 http://maven.apache.org

<properties>
    <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>
<repositories>
    <repository>
        <id>central</id>
        <name>Maven Repository Switchboard</name>
        <layout>default</layout>
        <url>http://repo1.maven.org/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts-core</artifactId>
        <version>1.3.10</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.8</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.jexcelapi</groupId>
        <artifactId>jxl</artifactId>
        <version>2.6.10</version>
    </dependency>
    <dependency>
        <groupId>org.ow2.orchestra.eclipse.birt</groupId>
        <artifactId>org.ow2.orchestra.eclipse.birt.core</artifactId>
        <version>3.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.ow2.orchestra.eclipse.birt</groupId>
        <artifactId>org.ow2.orchestra.eclipse.birt.report.engine</artifactId>
        <version>3.7.0</version>
    </dependency>
    <dependency>
        <groupId>openforecast</groupId>
        <artifactId>openforecast</artifactId>
        <version>1.0.16</version>
        <scope>system</scope>
        <systemPath>D:/testing/WebContent/WEB-INF/lib/OpenForecast-0.5.0.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-math</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jsci</groupId>
        <artifactId>jsci</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts-taglib</artifactId>
        <version>1.3.10</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>struts</groupId>
        <artifactId>struts-bean</artifactId>
        <version>1.2.7</version>
        <type>tld</type>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <properties>
                    <maven.compiler.target>1.6</maven.compiler.target>
                    <maven.compiler.source>1.6</maven.compiler.source>
                </properties>
                <encoding>ISO-8859-1</encoding>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <packagingExcludes>D:/Test1/src/main/webapp/WEB-INF/web.xml</packagingExcludes>
            </configuration>
        </plugin>
    </plugins>
</build>

4

2 に答える 2

3

Tomcat に jar をデプロイするのではなく、war ファイルをデプロイします。war には、ライブラリを含む WEB-INF/lib フォルダーが含まれています。

Tomcat ルートの lib フォルダーは、デプロイされたすべてのアプリケーション間で共有されるライブラリにのみ使用されます。たとえば、データベース ドライバです。

Maven の依存関係が提供されたスコープ内にないことを確認してください。それらは、WEB-INF/libフォルダーに含まれている必要があります。

于 2012-07-02T07:45:53.083 に答える
0

サーブレットAPIへの依存関係などの最初のもの:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version>
</dependency>

このように「提供された」スコープが必要です。これは、コンパイルに必要になることを意味しますが、この場合、実行時にTomcatによって提供されます。

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version>
  <scope>provided</scope>
</dependency>

以下:

openforecast openforecast 1.0.16システムD:/testing/WebContent/WEB-INF/lib/OpenForecast-0.5.0.jar

本当に必要なリポジトリを使用していないことを示します。ビルドでシステムスコープの依存関係を使用しないでください。ビルド環境が固有になるためです。リポジトリマネージャ(Nexus、Artifactory、またはArchive)の使用を開始し、そこにopenforecastをインストールします。また、pom、特にMavenCentralでリポジトリを定義するのは悪い習慣です。

あなたが持っているようにあなたがあなたのpomで以下を定義したならば:

<properties>
    <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>

このようにmaven-compiler-pluginを構成する必要はありません。これにより、encodingパラメーターはデフォルトで上記のプロパティを使用します。

 <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <properties>
            <maven.compiler.target>1.6</maven.compiler.target>
            <maven.compiler.source>1.6</maven.compiler.source>
        </properties>
        <encoding>ISO-8859-1</encoding>
    </configuration>
</plugin>

次を使用できます。

 <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>

ただし、使用するプラグインのバージョンを定義する必要があります。

 <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>

最善の方法は、pluginManagementセクションを使用することです。

私の頭に浮かぶもう1つのことは、古いmaven-war-pluginを使用していて、構成で絶対パスを使用していることです。これは、どのような状況でも避ける必要があります。

<plugin>
   <artifactId>maven-war-plugin</artifactId>
   <version>2.1.1</version>
   <configuration>
     <packagingExcludes>D:/Test1/src/main/webapp/WEB-INF/web.xml</packagingExcludes>
   </configuration>
</plugin>

ウェブサイトが言うように、最新バージョンは2.2です。このようなものを除外する必要がある場合は、次の方法で行う必要があります。

<plugin>
   <artifactId>maven-war-plugin</artifactId>
   <version>2.2</version>
   <configuration>
     <packagingExcludes>${basedir}/src/main/webapp/WEB-INF/web.xml</packagingExcludes>
   </configuration>
</plugin>

しかし、この場合、なぜweb.xmlを除外したいのかわかりません。これは、warファイルの重要な部分だからです。それをもう少し詳しく説明できるかもしれません。

于 2012-07-02T13:07:37.877 に答える