使用maven创建普通maven项目并导入到eclipse

使用maven来创建普通maven项目

 

1.命令行输入以下mvn命令:

mvn archetype:generate -DgroupId=com.cpuid -DartifactId=CpuId -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

 

2.eclipse中File->Import...->Maven->Existing Maven Project,选择刚才创建的CpuId目录,点击Finish

 

3.修改pom.xml,添加main class

<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>com.cpuid</groupId>
  <artifactId>CpuId</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>CpuId</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
      <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.cpuid.CpuidMain</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

其中<build></build>间的内容是我们新添加的

 

4.编译打包(jar包)

右键项目->Run As->Maven install

 

done

 

posted @ 2015-11-25 16:32  onemuji  阅读(213)  评论(0)    收藏  举报