1. 程式人生 > >maven專案匯入eclipse預設jre修改

maven專案匯入eclipse預設jre修改

1.糾結了好長時間,不如看看maven的配置檔案吧。開啟%maven_home%\conf\setting.xml,只會在新建專案時自動使用1.6的匯入專案不會

在<profiles>標籤內新增如下配置:

<profile>
 <id>jdk-1.6</id>
 <activation>
  <activeByDefault>true</activeByDefault>
  <jdk>1.6</jdk>
 </activation>
 <properties>
  <maven.compiler.source>1.6</maven.compiler.source>
  <maven.compiler.target>1.6</maven.compiler.target>
  <maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>
 </properties>
</profile>

以後再使用maven生成專案預設編譯級別就是1.6的了

2.如果你有特別的需要,比如不同的專案使用的jre不同那麼可以在專案的pom.xml裡新增如下配置,匯入專案可以這樣配置然後進行maven project update:

<build>

    <plugins>

        <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-compiler-plugin</artifactId>

            <configuration>

                <source>1.6</source>

                <target>1.6</target>

            </configuration>

        </plugin>

    </plugins>

</build>
3.How to fix maven-dependency-plugin (goals “copy-dependencies”, “unpack”) is not supported by m2e in Eclipse

		<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.maven.plugins
										</groupId>
										<artifactId>
											maven-dependency-plugin
										</artifactId>
										<versionRange>
											[2.0,)
										</versionRange>
										<goals>
											<goal>unpack</goal>
										</goals>
									</pluginExecutionFilter>
									<action>
										<ignore></ignore>
									</action>
								</pluginExecution>
							</pluginExecutions>
						</lifecycleMappingMetadata>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>