【问题标题】:maven eclipse plugin generate wrong class path entrymaven eclipse插件生成错误的类路径条目
【发布时间】:2019-08-09 13:10:26
【问题描述】:

我正在使用 maven 3.6.0 并在 POM 文件中使用 maven eclipse 插件来生成 eclipse .classpath(用于我的依赖项)文件。构建成功完成,当我尝试配置 eclipse 项目时。我遇到了构建路径错误,例如 1. jar 不存在于类路径中,但 jar 存在于 lib 文件夹中 2.期望jar版本不同,但lib中的版本不同

而不是使用 maven 创建 .classpath。我在本地创建了一个并将其作为资源复制到我的 eclipse 项目中。

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.10</version>
                <configuration> 
                    <excludes>
                        <exclude>org.testng:testng</exclude>
                        <exclude>com.beust:jcommander</exclude>
                        <exclude>org.yaml:snakeyaml</exclude>                        
                        <exclude>org.apache-extras.beanshell:bsh</exclude>                       
                    </excludes>
                </configuration>
                <executions> 
                    <execution> 
                        <phase>prepare-package</phase> 
                        <goals> 
                            <goal>eclipse</goal> 
                        </goals> 
                    </execution> 
                </executions> 
            </plugin>
<execution>
                        <id>copy-eclipse-deps</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${setupDir}/Engine</outputDirectory>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <resources>        
                                <resource>
                                    <directory>${project.basedir}</directory>
                                    <includes>
                                        <include>.classpath</include>
                                        <include>.project</include>
                                    </includes>
                                </resource>
                            </resources>              
                        </configuration>            
                    </execution>

目前我刚刚注释掉 .classpath 行并通过更正所有类路径错误将文件复制为资源。

我想通过 maven 本身来实现它,否则每次我引入第三方 jar 时,我最终都会在类路径中添加新条目。

【问题讨论】:

标签: maven maven-eclipse-plugin


【解决方案1】:

当您使用 Maven 时,您不应将任何内容手动写入 .classpath。此外,您根本不应该使用maven-eclipse-plugin

当您使用最近的 Eclipse 时,Eclipse 中的 m2e 插件会自动处理 .classpath。您添加/编辑依赖项的唯一位置是pom.xml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 2019-03-03
    • 1970-01-01
    • 2011-06-19
    • 2023-04-04
    • 2013-05-16
    • 1970-01-01
    相关资源
    最近更新 更多