1

我在使用 Maven 和 Eclipse 编译器时遇到了一个非常奇怪的问题。

在 Eclipse+m2eclipse 中,我使用以下单个类编译一个小项目(原型快速入门)没有问题。

package test.test;
import com.Ostermiller.util.CSVParser;
public class TestCaseSensitive {
    CSVParser csvParser;
}

Ostermiller utils 被添加到 pom.xml。Eclipse Kepler 编译该项目。接下来, mvn compile 开箱即用。

现在的问题是,我切换到编译器 3.1 并要求使用 Eclipse 编译器(以便能够在控制台模式和 IDE 模式下处理相同的编译问题)。这是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>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>test</name>
<url>http://maven.apache.org</url>

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

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.ostermiller</groupId>
        <artifactId>utils</artifactId>
        <version>1.07.00</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <compilerId>eclipse</compilerId>
                <source>1.7</source>
                <target>1.7</target>
                <optimize>true</optimize>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
                <fork>false</fork>
                <compilerArgument>-err:nullAnnot,null</compilerArgument>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.plexus</groupId>
                    <artifactId>plexus-compiler-eclipse</artifactId>
                    <version>2.2</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

现在这是结果:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test: Compilation failure: Compilation failure:
[ERROR] /home/me/workspaces/4/3/ws/test/src/main/java/test/test/TestCaseSensitive.java:[3] The import com.Ostermiller cannot be resolved
[ERROR] /home/me/workspaces/4/3/ws/test/src/main/java/test/test/TestCaseSensitive.java:[7] CSVParser cannot be resolved to a type

com.Ostermiller 包存在(它在 Maven 默认编译器以及 Eclipse IDE 中编译),但在切换到 Eclipse 编译器后不存在。

请注意,报告的错误路径也是错误的:

[ERROR] /home/me/workspaces/4/3/ws/test/src/main/java/...

应该

[ERROR] /home/me/workspaces/4.3/ws/test/src/main/java/...

有人有想法吗?应该在哪里报告潜在的错误?

4

1 回答 1

1

你试过用tycho提供的jdt编译器吗?

请参阅http://wiki.eclipse.org/Tycho/FAQ#Can_I_use_the_Tycho_compiler_support_in_non-OSGi_projects.2C_too.3F

那会给你:

<plugin>
  <!-- Use compiler plugin with tycho as the adapter to the JDT compiler. -->
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
     <compilerId>jdt</compilerId>
     <source>1.7</source>
     <target>1.7</target>
     <optimize>true</optimize>
     <showWarnings>true</showWarnings>
     <showDeprecation>true</showDeprecation>
     <fork>false</fork>
     <compilerArgument>-err:nullAnnot,null</compilerArgument>
  </configuration>
  <dependencies>
     <!-- This dependency provides the implementation of compiler "jdt": -->
     <dependency>
       <groupId>org.eclipse.tycho</groupId>
       <artifactId>tycho-compiler-jdt</artifactId>
       <version>${tycho-version}</version>
     </dependency>
   </dependencies>
</plugin>

目前 tycho-version=0.18.0

于 2013-07-19T00:13:04.707 回答