• [Maven实战-许晓斌]-[第三章] Mave使用入门


    <?xml version="1.0" encoding="UTF-8"?>
    <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.juvenxu.mvnbook</groupId>
        <artifactId>hello-world</artifactId>
        <version>1.0-SNAPSHOT</version>
        <name>Maven Hello World Project</name>
    </project>

     

    package com.juvenxu.mvnbook.helloworld;
    
    public class HelloWorld {
        public String sayHello(){
            return "Hello Maven";
        }
    
        public static void main(String[] args) {
            System.out.println(new HelloWorld().sayHello());
        }
    
    }

    mvn clean compile

     

     

    <?xml version="1.0" encoding="UTF-8"?>
    <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.juvenxu.mvnbook</groupId>
        <artifactId>hello-world</artifactId>
        <version>1.0-SNAPSHOT</version>
        <name>Maven Hello World Project</name>
        
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.7</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </project>

    package com.juvenxu.mvnbook.helloworld;
    
    import static org.junit.Assert.assertEquals;
    import org.junit.Test;
    
    public class HelloWorldTest {
        @Test
        public void testSayHello(){
            HelloWorld helloWorld = new HelloWorld();
            String result = helloWorld.sayHello();
            assertEquals("Hello Maven", result);
        }
    
    
    }

    mvn clean test

     

    最新版本maven好像已经不存在下文所述的问题了

    mvn clean package

     

    mvn clean install

      

     

    maven-shade-plugin
    <?xml version="1.0" encoding="UTF-8"?>
    <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.juvenxu.mvnbook</groupId>
        <artifactId>hello-world</artifactId>
        <version>1.0-SNAPSHOT</version>
        <name>Maven Hello World Project</name>
        
        
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.7</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        
        <build>    
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>1.2.1</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <transformers>
                                    <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <mainClass>com.juvenxu.mvnbook.helloworld.HelloWorld</mainClass>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins> 
        </build>
    </project>

     

    一键式生成maven工程
    
    脚手架生成maven工程
    
    Archetype

    mvn archetype:generate

  • 相关阅读:
    Linux的内存管理之道
    Ramdisk根文件系统启动Linux(单独的ramdisk镜像)
    详解 ARM Linux启动过程
    晒晒我的vimrc配置【不定期更新】
    [Python入门及进阶笔记]Pythondecorator装饰器小结
    谷歌10个用户体验设计原则
    用busybox创建基于Linux2.6.24内核的nfs根文件系统
    [Python入门及进阶笔记]Python魔术方法小结(方法运算符重载)
    mysql慢查询
    关于android的各种disk images(看过的讲android image比较细致的好文)
  • 原文地址:https://www.cnblogs.com/whoknows1/p/9806624.html
Copyright © 2020-2023  润新知