从pom的xsi中可以打开描述pom的schema:

可以看到pom中,project的结构:

默认的mvn install生成的jar是不带主类入口的,需要在maven-compile-plugin中设置主类,

<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.cetc.di</groupId>
<artifactId>hellocetc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>hellocetc</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies> <build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<archive>
<manifest>
<mainClass>com.cetc.di.hellocetc.App</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest> </archive>
<classesDirectory>
</classesDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build> </project>

执行mvn install:

在target目录中,发现jar包已经生成:

用java decompiler,可以看到manifest中已经加入了MainClass:

使用mvn help:effective-pom可以看到pom.xml的完整结构(包括继承而来的属性):

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hellocetc 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:effective-pom (default-cli) @ hellocetc ---
[INFO]
Effective POMs, after inheritance, interpolation, and profiles are applied: <!-- ====================================================================== -->
<!-- -->
<!-- Generated by Maven Help Plugin on 2015-11-18T08:05:12 -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/ -->
<!-- -->
<!-- ====================================================================== --> <!-- ====================================================================== -->
<!-- -->
<!-- Effective POM for project 'com.cetc.di:hellocetc:jar:0.0.1-SNAPSHOT' -->
<!-- -->
<!-- ====================================================================== --> <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.cetc.di</groupId>
<artifactId>hellocetc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>hellocetc</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\main\java</sourceDirectory>
<scriptSourceDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\main\scripts</scriptSourceDirectory>
<testSourceDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\test\java</testSourceDirectory>
<outputDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\classes</outputDirectory>
<testOutputDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\test-classes</testOutputDirectory>
<resources>
<resource>
<directory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\main\resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\test\resources</directory>
</testResource>
</testResources>
<directory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target</directory>
<finalName>hellocetc-0.0.1-SNAPSHOT</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<archive>
<manifest>
<mainClass>com.cetc.di.hellocetc.App</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<classesDirectory />
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
<archive>
<manifest>
<mainClass>com.cetc.di.hellocetc.App</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<classesDirectory />
</configuration>
</execution>
</executions>
<configuration>
<source>1.8</source>
<target>1.8</target>
<archive>
<manifest>
<mainClass>com.cetc.di.hellocetc.App</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<classesDirectory />
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<outputDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site</outputDirectory>
</reporting>
</project> [INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.526 s
[INFO] Finished at: 2015-11-18T20:05:12+08:00
[INFO] Final Memory: 10M/245M
[INFO] ------------------------------------------------------------------------

使用maven生成可执行的jar包的更多相关文章

  1. Maven 生成可执行的jar包

    maven 默认打包生成的 jar 包是不能够直接运行的,因为带有 main 方法的类信息不会添加到 manifest 中,即打开 jar 文件中的 META-INF/MANIFEST.MF 文件,将 ...

  2. maven-jar-plugin 使用maven生成可执行的jar包install a test-jar in maven

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

  3. [Maven]Maven构建可执行的jar包(包含依赖jar包)

    ----------------------------------------------------------------- 原创博文,如需转载请注明出处! 博主:疲惫的豆豆 链接:http:/ ...

  4. 用命令行编译java并生成可执行的jar包

    用命令行编译java并生成可执行的jar包 1.编写源代码. 编写源文件:CardLayoutDemo.java并保存,例如:I:\myApp\CardLayoutDemo.java.程序结构如下: ...

  5. maven 生成可执行的jar文件

    微服务的热潮,慢慢讲jar引入了码农的视线之中,从传统web开发中过来的人面对这个东西也算是个新鲜事了,接下来聊一聊在maven下生成可运行jar的那些事. Maven可以使用mvn package指 ...

  6. eclipse使用MAVEN打包可执行的jar包

    1.新建maven工程 注意勾选 随便填一下 建好之后工程目录如下 新建测试类与工具类,主类很简单 工具类也很简单,就是初始化了日志 maven依赖包也只有一个log4j的jar <depend ...

  7. 转: maven打可执行的jar包以及classpath设置

    from:  http://drizzlewalk.blog.51cto.com/2203401/416508

  8. maven打一个可执行的jar包

    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-depen ...

  9. 使用Mavne生成可以执行的jar文件

    到目前为之,还没有运行HelloWorld的项目,不要忘了HelloWorld类可是有一个main方法的.使用mvn clean install命令默认生成的jar 包是不能直接运行的.因为带有mai ...

随机推荐

  1. python 爬虫 爬取序列博客文章列表

    python中写个爬虫真是太简单了 import urllib.request from pyquery import PyQuery as PQ # 根据URL获取内容并解码为UTF-8 def g ...

  2. 如何根据搜索页面内容得到的结果生成该元素的xpath路径

    如何根据搜索页面内容得到的结果生成该元素的xpath路径?

  3. Qt 立体水晶按键实现

    一直对 Qt 怎样实现富有立体感的按键很好奇,做过很多尝试,最后用的图片,但是图片终究不够灵活,而且占内存. 今天偶然发现,使用下面的代码,作出的 QPushButton 效果还算不错.代码共享之: ...

  4. uva 11346 - Probability(概率)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=2321">题目链接:uva 11346 - ...

  5. Spring MVC 通过 @PropertySource和@Value 来读取配置文件

    在这篇文章中,我们会利用Spring的@PropertySource和@Value两个注解从配置文件properties中读取值.先来段java代码: @Component @PropertySour ...

  6. SQL Server 2012 无人值守安装(加入新实例)

    方法1,通过指定条个參数安装 setup.exe /Q /IACCEPTSQLSERVERLICENSETERMS /ACTION=install /PID=<validpid> /FEA ...

  7. V-rep学习笔记:Reflexxes Motion Library 3

    路径规划 VS 轨迹规划 轨迹规划的目的是将输入的简单任务描述变为详细的运动轨迹描述.注意轨迹和路径的区别:Trajectory refers to a time history of positio ...

  8. 防止跨站请求伪造(CSRF)攻击 和 防重复提交 的方法的实现

    CSRF的概念可以参考:http://netsecurity.51cto.com/art/200812/102951.htm 本文介绍的是基于spring拦截器的Spring MVC实现 首先配置拦截 ...

  9. mysql保留2位小数字段如何设置 浮点数

    保留2位小数字段如何设置 方法1: select cast(avg(75.3333333) as decimal(10,2)) as '平均分' );#format第一个参数传递浮点数

  10. mybatis-generator生成逆向工程两种方式

    本文博客地址:http://blog.csdn.net/soonfly/article/details/64499423 逆向工程下载 链接:https://pan.baidu.com/s/1YOAq ...