使用maven命令创建java项目

1.进入maven 所在目录的bin文件下: 如:D:\apache-maven-3.2.1\bin,输入以下命令

mvn archetype:generate -DgroupId=cn.everlook.myweb -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

2.进入maven新建的目录下:D:\apache-maven-3.2.1\bin\myapp>:输入以下命令

mvn eclipse:eclipse

3.导入ecclipse中:

修改App内容:

public class App
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!ljf" );
    }
}

修改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.0http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>cn.everlook.myweb</groupId>
  <artifactId>myapp</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>myapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
   <build>
   <plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>2.3.2</version>
   <configuration>
    <source>1.6</source>
    <target>1.6</target>
   </configuration>
  </plugin>
  
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <!-- The configuration of the plugin -->
    <configuration>
     <!-- Configuration of the archiver -->
     <archive>

      <!-- 生成的jar中,不要包含pom.xml和pom.properties这两个文件 -->
      <addMavenDescriptor>false</addMavenDescriptor>

      <!-- Manifest specific configuration -->
      <manifest>
       <!-- 是否要把第三方jar放到manifest的classpath中 -->
       <addClasspath>true</addClasspath>
       <!-- 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/ -->
       <classpathPrefix>lib/</classpathPrefix>
       <!-- 应用的main class -->
       <mainClass>cn.everlook.myweb.App</mainClass>

      </manifest>
     </archive>
    
    </configuration>
   </plugin>
  
  
  
  
  
   </plugins>
 </build>
</project>

5.打包: mvn clean package;

6 执行jar:


D:\apache-maven-3.2.1\myapp\target>java -jar myapp-1.0-SNAPSHOT.jar
Hello World!ljf

 

你可能感兴趣的:(maven)