【问题标题】:Why can't maven compiler resolve class from depedency?为什么 Maven 编译器不能从依赖中解析类?
【发布时间】:2010-08-23 03:34:49
【问题描述】:

Eclipse可以构建这个项目,依赖jar在本地仓库,编译器列出jar。 我正在使用 Eclipse Helios 和 Maven Integration For Eclipse (0.10.2);

但它失败了,因为编译器无法从 spring-beans-2.5.6.jar 解析 PropertiesEditor。

这是构建的完整报告

http://wellingtonpeoplescentre.org.nz/geek/maven-wigout.txt

这是我的 POM。

<?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>witerat</groupId>
 <artifactId>iWPC</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <name>WPC on the web</name>
 <url>http://wellingtonpeoplescentre.org.nz</url>
 <organization>
  <name>Wellington People's Centre</name>
  <url>http://wellingtonpeoplescentre.org.nz</url>
 </organization>


 <build>
  <defaultGoal>package</defaultGoal>
  <finalName>iBffsdb</finalName>
  <sourceDirectory>src/main/java</sourceDirectory>
  <testSourceDirectory>src/test/java</testSourceDirectory>
  <directory>target</directory>  
  <resources>
   <resource>
    <directory>src/main/resources</directory>
   </resource>
  </resources>
  <testResources>
   <testResource>
    <directory>src/test/resources</directory>
   </testResource>
  </testResources>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>

    <version>2.1-beta-1</version>
    <configuration>
    <overlays>
    <!-- 
      <overlay>      
       <groupId>org.dojotoolkit</groupId>       
       <artifactId>dojo-war</artifactId>
       <targetPath>javascript</targetPath>
      </overlay> -->
      <overlay>
       <groupId>jcivicrm-dao</groupId>
       <artifactId>jcivicrm-dao</artifactId>
       <type>jar</type>
       <targetPath>WEB-INF/classes</targetPath>
      </overlay>
    </overlays>
    <warSourceDirectory>WebContent</warSourceDirectory>
    </configuration>
   </plugin>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.1</version>
    <configuration>
        <encoding>Cp1252</encoding>


     <verbose>true</verbose>    
     <source>1.6</source>
     <target>1.6</target>
    </configuration>
   </plugin>

  </plugins>
 </build>
 <repositories>
  <repository>
   <id>snapshots-local</id>
   <name>snaps</name>
   <url>http://localhost:12120/nexus-webapp-1.7.1/content/repositories/snapshots/</url>
   <releases>
    <enabled>false</enabled>
   </releases>
   <snapshots>
     <enabled>true</enabled>
    <updatePolicy>always</updatePolicy>
    <checksumPolicy>warn</checksumPolicy>
   </snapshots>
  </repository>
 </repositories>
 <dependencies>
  <dependency>
   <groupId>jcivicrm-dao</groupId>
   <artifactId>jcivicrm-dao</artifactId>
   <version>0.0.1-SNAPSHOT</version>
  </dependency><dependency>
   <groupId>JCivicrm-platform</groupId>
   <artifactId>JCivicrm-platform</artifactId>
   <version>0.0.1-SNAPSHOT</version>
  </dependency><dependency>
   <groupId>JCiviCRM</groupId>
   <artifactId>JCiviCRM</artifactId>
   <version>0.0.1-SNAPSHOT</version>
  </dependency><dependency>
   <groupId>nz.org.wpc.user.security</groupId>
   <artifactId>nz.org.wpc.user.security</artifactId>
   <version>0.0.1-SNAPSHOT</version>
    </dependency><dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
   <version>1.1.111</version>
  </dependency><dependency>
   <groupId>commons-collections</groupId>
   <artifactId>commons-collections</artifactId>
   <version>3.2.1</version>
  </dependency><dependency>
   <groupId>commons-dbcp</groupId>
   <artifactId>commons-dbcp</artifactId>
   <version>1.2.2</version>
  </dependency><dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>servlet-api</artifactId>
   <version>2.4</version> 
   <scope>provided</scope>
  </dependency><dependency>
   <groupId>javax</groupId>
   <artifactId>mail</artifactId>
   <version>1.5</version>
   <scope>system</scope>
   <systemPath>c:\sun\sdk\lib\mail.jar</systemPath>
  </dependency><dependency>
   <groupId>javax.transaction</groupId>
   <artifactId>jta</artifactId>
   <version>1.0.1B</version>
  </dependency><dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.2</version>
   <scope>system</scope>
   <systemPath>C:\dev\eclipse\plugins\org.junit_3.8.2.v20080602-1318\junit.jar</systemPath>
  </dependency><dependency>
     <groupId>net.sf.ehcache</groupId>
     <artifactId>ehcache</artifactId>
     <version>1.6.0</version>
    </dependency><dependency>
   <groupId>net.sf.json-lib</groupId>
   <artifactId>json-lib-ext-spring</artifactId>
   <version>1.0.2</version>
  </dependency><dependency>
     <groupId>org.aspectj</groupId>
     <artifactId>aspectjrt</artifactId>
     <version>1.5.4</version>
     <scope>runtime</scope>
  </dependency><dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-orm</artifactId>
   <version>2.5.6</version>
  </dependency><dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>2.5.6</version>
  </dependency><dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context-support</artifactId>
   <version>2.5.6</version>
  </dependency><dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-jdbc</artifactId>
   <version>2.5.6</version>
  </dependency><dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-core</artifactId>
   <version>2.0.4</version>
   <exclusions>
    <exclusion>
     <groupId>org.springframework</groupId>
     <artifactId>spring-aop</artifactId>
    </exclusion><exclusion>
     <groupId>org.springframework</groupId>
     <artifactId>spring-support</artifactId>
    </exclusion><exclusion>
     <groupId>org.springframework</groupId>
     <artifactId>spring-remoting</artifactId>
    </exclusion>
   </exclusions>
  </dependency><dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-aop</artifactId>
   <version>2.5.6</version>
  </dependency><dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-acl</artifactId>
   <version>2.0.4</version>
  </dependency><dependency>
     <groupId>org.springframework.security</groupId>
     <artifactId>spring-security-core-tiger</artifactId>
     <version>2.0.4</version>
    </dependency><dependency>
     <groupId>org.springframework.security</groupId>
     <artifactId>spring-security-taglibs</artifactId>
     <version>2.0.5.RELEASE</version>
    </dependency><dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-beans</artifactId>
   <version>2.5.6</version>
   <type>jar</type>
   <scope>compile</scope>
  </dependency><dependency>
   <groupId>velocity</groupId>
   <artifactId>velocity</artifactId>
   <version>1.4</version>
  </dependency><dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate</artifactId>
   <version>3.2.6.ga</version>
   <type>jar</type>
   <scope>compile</scope>
  </dependency>
 </dependencies>

 <distributionManagement>
  <repository>
   <id>releases-local</id>
   <name>releases</name>
   <url>http://localhost:12120/nexus-webapp-1.7.1/content/repositories/releases/</url>
  </repository>
  <snapshotRepository>
   <id>snapshot-local</id>
   <name>snaps</name>
   <url>http://localhost:12120/nexus-webapp-1.7.1/content/repositories/snapshots/</url>
  </snapshotRepository>
 </distributionManagement>
</project>

【问题讨论】:

  • 你确定导入语句是正确的(你可能引用了其他一些PropertiesEditor)
  • 是的,请记住 eclipse 工作区构建工作但 Run-As maven 包不能。 jave 不是问题。

标签: eclipse maven m2eclipse


【解决方案1】:

是的,m2eclipse 是一个旧的或包含几个错误。

您好,您遇到了同样的问题,我已经苦苦挣扎了 20 多个小时。 m2eclipse 插件在其属性中的某处具有 J2SE 1.5 编译器,即使您在 pom.xml 中指定了正确的编译器,它也经常中断。

create your own command: 
1) right click on project
2) Run as 
3) Run as maven build (5-th one)
4) on configuration panel specify your goals (site / test / clean)
5) **on JRE panel specify your JRE 1.6**
6) save your command as e.g. "maven site JDK 6"
7) run everything using your customs commands ("maven site JDK 6"), not built in commands. 

这是我的其他提示 1) 使用您自己的 maven,而不是在 m2eclipse 中构建,您可以在 m2eclipse 首选项中切换到它

2) 从愚蠢的 C:\Users\current_user-m2\repository 更改存储库位置 到 D:\repository 或任何其他没有 ~ 或任何其他特殊升的正常路径

3) 在恐慌之前使用您自己的 Maven 检查控制台中的所有内容。例如我的命令,如

mvn site
mvn install 
mvn tomcat:redeploy 

从控制台工作出色,但在 Eclipse 内部失败。这意味着 m2eclipse 参数是错误的,您应该设置自己的参数。

4)不要依赖上下文命令(右键单击-运行为-maven测试/站点/构建) 在运行中创建自己的命令 - maven build - 在菜单中选择正确的 JRE 版本(在我的例子中是 1.7)并添加任何其他参数不要忘记给这个命令命名,例如:“maven tomcat:redeploy JDK 7” - 这会给你一个很好的机会来运行你想要的任何东西,并且不会面临 90% 的 m2eclipse 问题和错误。

附:我在 maven 2 和 m2eclipse 上苦苦挣扎了 20 多个小时。希望我的提示对某些人有用。

【讨论】:

    猜你喜欢
    • 2022-01-15
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    相关资源
    最近更新 更多