1

我有一个使用 Maven 使用 maven-assembly-plugin 构建 JAR 的应用程序。

该项目包括一个依赖项列表,其中一个是另一个 Maven 项目。我正在使用 Eclipse 进行开发,当我运行该项目时,一切正常。当我使用 Maven 目标构建时assembly:assembly,它会生成 JAR,但是当我运行 JAR 时,会出现以下错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The method configure(Map<String,String>) of type SMTPMailService must 
      override a superclass method
    at rey.sto.utils.mail.SMTPMailService.configure(SMTPMailService.java:89)
    at com.ppl_sftp.transfer.FileTransfer.startTransfer(FileTransfer.java:232)
    at com.ppl_sftp.transfer.MainApp.main(MainApp.java:33)

这是主项目的 pom.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<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.ppl-sftp</groupId>
<artifactId>transfer</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>

<name>A Camel Route</name>
<url>http://www.myorganization.org</url>

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

<dependencies>
    <!-- logging -->

    <!-- testing -->
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.10.0</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.6</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.6</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
        <version>3.7.2</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-test</artifactId>
        <version>2.10.0</version>
        <type>jar</type>
        <scope>test</scope>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-ftp</artifactId>
        <version>2.9.2</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>

    <dependency>
        <groupId>my-utils</groupId>
        <artifactId>my-utils</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
         <groupId>javax.activation</groupId>
         <artifactId>activation</artifactId>
         <version>1.1</version>
        </dependency>
    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.4.5</version>
    </dependency>
</dependencies>

<build>
    <defaultGoal>install</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <!-- allows the route to be ran via 'mvn camel:run' -->
        <plugin>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-maven-plugin</artifactId>
            <version>2.10.0</version>
        </plugin>
        <!-- Allows the example to be run via 'mvn compile exec:java' -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <mainClass>com.ppl_sftp.transfer.MainApp</mainClass>
                <includePluginDependencies>false</includePluginDependencies>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.ppl_sftp.transfer.MainApp</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
    </plugins>
</build>

这是 my-utils 项目依赖项的 pom:

<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>rey-sto-utils</groupId>
<artifactId>rey-sto-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>2.0-beta2</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.21</version>
    </dependency>
    <dependency>
        <groupId>ojdbc6</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>6</version>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.4.5</version>
    </dependency>
</dependencies>

该问题与 Java 邮件依赖项有关。如您所见,我已经使用过 com.sun.mail,但我看到了一些其他不同的库对应于javax.mail.

也许我在我的 poms 中遗漏了一些东西,比如配置参数或插件。

我还尝试在我的本地存储库中放入一个在其他项目中运行良好的 mail.jar,但我得到了同样的错误。

4

1 回答 1

4

“未解决的编译问题”来自 Eclipse 已编译的 utils 项目中的类文件,但 Eclipse 无法正确编译它。

您从 Eclipse 和 Maven 看到不同结果的原因是它们使用了不同版本的类文件。Eclipse 正在做工作区解析,所以它使用 utils/target/classes 中的 SMTPMailService 版本。mvn installMaven 正在从您的本地 Maven 存储库中解析 utils jar,当您在 Eclipse 中出现编译错误时,该存储库是通过运行放置在那里的。

Try running mvn clean install in the utils project (clean to remove any class files generated by Eclipse, install to replace the jar in your local repository). Then rebuild your assembly.

于 2012-10-17T13:39:37.520 回答