国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

maven第一坑

2019-11-08 03:22:26
字體:
來源:轉載
供稿:網友

maven 命令行指令

mvn clean complie / test / package/ install

cd target

java -jar xxx.jar

剛啃完linux,開始啃maven。按照《maven實戰》的教程,使用命令行進行打包。遇到了一些問題。

首先,最坑爹的一點是,書上并沒有按照maven官方建議的目錄結構進行建立。可能由于還沒有講到目錄結構的原因。

但是按照書中建立目錄結構,導致一直運行不成功。

從mvn clean test命令開始,就有問題,如果直接打包運行,遇到的錯誤為:找不到主類。

maven的目錄結構:

src

  |     main

  |           |          java            ----------com.test.helloworld.HelloWorld.java

  |           |          resources

  |           |          filters

  |       test

  |           |        java             ----------HelloWorldTest.java

  |           |        resource

  |           |        filters

  |       site

  |       assembly

 target

 pom.xml

pom.xml:

         

<?xml version = "1.0" encoding = "UTF-8"?><PRoject xmlns = "http://maven.apache.org/POM/4.0.0"    xmlns:xsi = "http://www.w3.org/2001/XNLSchema-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>com.test</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-compiler-plugin</artifactId>            <configuration>                <source>1.8</source>                <target>1.8</target>            </configuration>        </plugin>        <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>main.java.com.test.helloworld.HelloWorld</mainClass> <!-- 指明主類-->                            </transformer>                        </transformers>                    </configuration>                </execution>            </executions>        </plugin>    </plugins>  </build></project>

HelloWorldTest

package test.java;import main.java.com.test.helloworld.HelloWorld;import junit.framework.Assert;import junit.framework.TestCase;//導入的包名和書中不一致,應該是由于版本的歷史原因?public class HelloWorldTest extends TestCase{    //@Test        注解被注釋掉了,不知道為什么會出錯。    public void testSayHello(){        HelloWorld helloWorld = new HelloWorld();        String result = helloWorld.sayHello();        assertEquals("Hello Maven", result);    }}

HelloWorld:

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

不在IDE里,打印錯誤是常見錯誤。QAQ


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黄大仙区| 克什克腾旗| 五常市| 彩票| 鸡泽县| 楚雄市| 拉孜县| 山丹县| 图片| 南陵县| 拉萨市| 长兴县| 喀喇沁旗| 黄山市| 湾仔区| 双鸭山市| 弥勒县| 黎平县| 陕西省| 海晏县| 林州市| 阳城县| 景洪市| 杂多县| 乌审旗| 喀什市| 黔东| 蒲江县| 寿光市| 梅河口市| 旬邑县| 增城市| 沈丘县| 长白| 宁强县| 长顺县| 兴安县| 轮台县| 滨州市| 黄龙县| 辽中县|