我将 SpringSource 工具套件 (STS) 与 Maven + m2eclipse 一起使用。在我的最新项目中,将现有 Maven 项目从 SVN 正确导入 STS 时遇到问题。当我使用import -> Maven -> 'existing Maven project'
时,项目将导入,但会出现以下问题:
- 和
src/main/java
不src/test/java
作为源文件夹拾取。STS 将配置src
为源文件夹,并将 main/test 添加到包名称中。 - Maven 依赖库未添加到 java 构建路径。
我可以手动更正源文件夹,但是当我尝试将“Maven 托管依赖项”库添加到构建路径时,我收到消息“使用 Maven 项目设置来配置 Maven 依赖项解析”并且未添加该库。我似乎能够设置的唯一 Maven 项目设置是活动配置文件和“解决工作区项目中的依赖项”(选中),这两者似乎都没有任何区别。
如果我从命令行运行mvn install
,项目将成功构建。如果我运行mvn eclipse:eclipse
然后导入 STS,那么一切都按预期工作,但是当然每次更新 pom 时都必须重新运行它,这是不可取的。
我通过运行mvn eclipse:eclipse
然后手动更新 .classpath 以消除M2_REPO
添加eclipse:eclipse
的依赖项并添加 m2eclipse 依赖项条目来解决它:
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
然后我导入了现有的 Maven 项目,它按预期工作。但是,这是一个 hack,我不确定eclipse:ecplise
在使用 m2eclipse 时运行会产生什么其他后果。
我曾参与过其他 Maven 项目,并且在正确导入它们时没有遇到任何问题。
可能的相关资料:
- 这是一个网络应用项目。
- subversion repo 仅包含
pom.xml
和src
文件夹。 - 我使用外部 Maven 安装,它是 3.0.3 版
- 我们使用现场 Artifactory repo 进行工件下载
我尝试过的事情:
- 从 SVN 下载到本地磁盘,然后使用导入现有的 Maven 项目导入到 STS
- 将项目从SVN导入STS,配置->启用Maven性质
- 运行
mvn eclipse:eclipse
然后导入(有效,但需要手动编辑 m2e 的类路径) - 搜索stackoverflow,发现这个问题非常相似,但答案似乎没有解决我的问题。
pom.xml:
<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>com.company.group</groupId>
<artifactId>artifact</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>My Project</name>
<description>My Project</description>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.0.RELEASE</org.springframework-version>
<!-- Lots of other versions omitted -->
</properties>
<repositories>
<repository>
<id>repoId</id>
<name>repoName</name>
<url>http://fake.company.com/artifactory/repo</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repoId</id>
<name>repoName</name>
<url>http://fake.company.com/artifactory/repo</url>
</pluginRepository>
</pluginRepositories>
<!-- Configurations required for deploy plugin. Artifacts are deployed to
artifactory -->
<distributionManagement>
<repository>
<id>repoId</id>
<name>repoName-releases</name>
<url>http://fake.company.com/artifactory/apps-releases-local</url>
</repository>
<snapshotRepository>
<id>repoId</id>
<name>repoName-snapshots</name>
<url>http://fake.company.com/artifactory/apps-snapshots-local</url>
</snapshotRepository>
</distributionManagement>
<scm>
<connection>scm:svn:https://fake.company.com/svn/fake-repo/trunk</connection>
<developerConnection>scm:svn:https://fake.company.com/svn/fake-repo/trunk</developerConnection>
<url>https://fake.company.com/svn/fake-repo/trunk</url>
</scm>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Lots of other dependencies omitted -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/TestUtil.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<verbose>true</verbose>
<source>${java-version}</source>
<target>${java-version}</target>
<compilerVersion>${java-version}</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>war-name</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<formats>
<format>html</format>
</formats>
<instrumentation>
<ignores>
<ignore>path/**/*Test.class</ignore>
</ignores>
<excludes>
<exclude>path/Constants.class</exclude>
<exclude>path/*.class</exclude>
</excludes>
</instrumentation>
<check>
<haltOnFailure>false</haltOnFailure>
<totalBranchRate>25</totalBranchRate>
<totalLineRate>41</totalLineRate>
<packageLineRate>25</packageLineRate>
<packageBranchRate>15</packageBranchRate>
</check>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${org.apache.cxf-version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/automation.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated/cxf</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.cxf</groupId>
<artifactId>
cxf-codegen-plugin
</artifactId>
<versionRange>
[${org.apache.cxf-version},)
</versionRange>
<goals>
<goal>wsdl2java</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<versionRange>[2.3.2,)</versionRange>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<!-- Deployment profiles omitted -->
</profiles>
</project>
有没有人对如何:
- 让 m2eclipse 导入正常工作?或者
- 配置 STS 以允许我在项目创建/转换后将 Maven 托管依赖项添加到构建路径?