maven 中使用jdt编译代码

在Maven项目中,配置使用JDT进行代码编译时,遇到了一个问题:当运行`mvn clean package`时,出现编译错误提示包名`com.ax.hello`与类型名冲突。尽管在Eclipse环境下代码能够正常运行,但在Maven构建过程中出现了错误。问题根源在于类Hello与包名hello相同导致的冲突,目前尚未找到解决该问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

pom 配置:

<build>
              <plugins>
                     <plugin>
                           <groupId>org.apache.maven.plugins</groupId>
                           <artifactId>maven-assembly-plugin</artifactId>
                     </plugin>
                     
                     <plugin>  
                      <groupId>org.apache.maven.plugins</groupId>  
                      <artifactId>maven-surefire-plugin</artifactId>  
                      <version>2.12.4</version>  
                      <configuration>  
                        <skipTests>true</skipTests>  
                      </configuration>  
                     </plugin>  
                     <!-- 指定jdk, 使用jdt插件 编译代码,解决默认javac编译严格的问题.  -->
                     <plugin>
                           <groupId>org.apache.maven.plugins</groupId>
                           <artifactId>maven-compiler-plugin</artifactId>
                           <configuration>
                                  <compilerId>eclipse</compilerId>
                                  <encoding>UTF-8</encoding>
                                  <failOnError>true</failOnError> <!-- 这里跳过编译报错,不会编译报错的部分,并不能解决下面的问题 -->                                  <compilerArguments>
                       <properties>${basedir}/.settings/org.eclipse.jdt.core.prefs</properties>
                       </compilerArguments>
                                  <source>1.7</source>
                                  <target>1.7</target>
                           </configuration>
                           
                           <dependencies>
                                  <dependency>
                           <groupId>org.codehaus.plexus</groupId>
                           <artifactId>plexus-compiler-eclipse</artifactId>
                           <version>2.4</version>
                       </dependency>
                       
                    <!--  https://mvnrepository.com/artifact/org.eclipse.jdt/org.eclipse.jdt.core -->
                                  <dependency>
                                      <groupId>org.eclipse.tycho</groupId>
                                       <artifactId>org.eclipse.jdt.core</artifactId>
                                   <version>3.10.0.v20140604-1726</version>
                                  </dependency>
                           </dependencies>
                     </plugin>
              </plugins>
       </build>

项目结构:

├─main
│  └─java
│      └─com
│          └─ax
│              │  Hello.java
│              │
│              ├─hello
│              │      TestOne.java
│              │
│              └─mvntest
│                      App.java

遇到问题: 在eclipse中运行mvc clean package 时遇到编译报错: The package com.ax.hello collides with a type.
分析:

  1. 是由于类Hello 和 包名 hello 存在出冲突。但是代码在eclipse中并没有报错。这里不知道如何解决。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值