• eclipse打包非web项目的整合了spring和mybaits的pom项目,打包可以运行的jar


    eclipse打包非web项目的整合了spring和mybaits的pom项目,打包可以运行的jar

    在pom中添加

     <build>  
            <plugins>  
                <plugin>  
                    <groupId>org.apache.maven.plugins</groupId>  
                    <artifactId>maven-shade-plugin</artifactId>  
                    <version>1.4</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>main.Main</mainClass>  
                                    </transformer>  
                                    <transformer  
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
                                        <resource>META-INF/spring.handlers</resource>  
                                    </transformer>  
                                    <transformer  
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
                                        <resource>META-INF/spring.schemas</resource>  
                                    </transformer>  
                                </transformers>  
                            </configuration>  
                        </execution>  
                    </executions>  
                </plugin>  
            </plugins>  
        </build>  
      
    

    其中 main.Main 是入口类的类全名

    我的完整的pom

    <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.hd.foodclient</groupId>
      <artifactId>FoodClient_pom</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      
      <properties>
    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    		<spring.version>4.2.5.RELEASE</spring.version>
    		<log4j.version>1.2.17</log4j.version>
    	</properties>
    	
     <build>  
            <plugins>  
                <plugin>  
                    <groupId>org.apache.maven.plugins</groupId>  
                    <artifactId>maven-shade-plugin</artifactId>  
                    <version>1.4</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>main.Main</mainClass>  
                                    </transformer>  
                                    <transformer  
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
                                        <resource>META-INF/spring.handlers</resource>  
                                    </transformer>  
                                    <transformer  
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
                                        <resource>META-INF/spring.schemas</resource>  
                                    </transformer>  
                                </transformers>  
                            </configuration>  
                        </execution>  
                    </executions>  
                </plugin>  
            </plugins>  
        </build>  
      
    	
    	
    	<dependencies>
    	
    	<!-- 下载需要的 -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.0-alpha4</version>
    </dependency>
    	<!-- End下载需要的 -->
    	
    	
    	<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
    	
    		<dependency>
    			<groupId>junit</groupId>
    			<artifactId>junit</artifactId>
    			<version>4.12</version>
    		</dependency>
    		<!-- spring核心包 -->
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-core</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-oxm</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-tx</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-jdbc</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-aop</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-context-support</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-test</artifactId>
    			<version>${spring.version}</version>
    		</dependency>
    		<!-- 添加MyBatis依赖 -->
    		<dependency>
    			<groupId>org.mybatis</groupId>
    			<artifactId>mybatis</artifactId>
    			<version>3.3.0</version>
    		</dependency>
    		<dependency>
    			<groupId>mysql</groupId>
    			<artifactId>mysql-connector-java</artifactId>
    			<version>5.1.38</version>
    		</dependency>
    		<!-- 阿里巴巴的数据库连接池 -->
    		<dependency>
    			<groupId>com.alibaba</groupId>
    			<artifactId>druid</artifactId>
    			<version>1.0.16</version>
    		</dependency>
    
    		<!-- spring结成mybatis -->
    		<dependency>
    			<groupId>org.mybatis</groupId>
    			<artifactId>mybatis-spring</artifactId>
    			<version>1.2.3</version>
    		</dependency>
    		<dependency>
    			<groupId>log4j</groupId>
    			<artifactId>log4j</artifactId>
    			<version>${log4j.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-nop</artifactId>
    			<version>1.6.4</version>
    		</dependency>
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-api</artifactId>
    			<version>1.6.1</version>
    		</dependency>
    		<dependency>
    			<groupId>commons-discovery</groupId>
    			<artifactId>commons-discovery</artifactId>
    			<version>0.2</version>
    		</dependency>
    		<dependency>
    			<groupId>com.sun.xml.bind</groupId>
    			<artifactId>jaxb-impl</artifactId>
    			<version>2.1.7</version>
    		</dependency>
    		<dependency>
    			<groupId>mysql</groupId>
    			<artifactId>mysql-connector-java</artifactId>
    			<version>5.1.38</version>
    		</dependency>
    		<dependency>
    			<groupId>org.quartz-scheduler</groupId>
    			<artifactId>quartz-parent</artifactId>
    			<version>1.8.5</version>
    			<type>pom</type>
    		</dependency>
    
    		<dependency>
    			<groupId>jdom</groupId>
    			<artifactId>jdom</artifactId>
    			<version>b10</version>
    		</dependency>
    		<dependency>
    			<groupId>tk.mybatis</groupId>
    			<artifactId>mapper</artifactId>
    			<version>3.3.8</version>
    		</dependency>
    		<dependency>
    			<groupId>org.xerial</groupId>
    			<artifactId>sqlite-jdbc</artifactId>
    			<version>3.8.11.2</version>
    		</dependency>
    
    	</dependencies>
      
    
      
      
      
    </project>
    

    然后右击项目输入maven命令clean packge即可打包

    注意所有的配置文件一定要放在resources,否则打包后会找不到

  • 相关阅读:
    Django cache (缓存)
    Django CSRF
    Django 中的 Cookie 和 Session
    Django views 中的装饰器
    Ajax 基础
    JavaScript 对象
    Django ORM 操作
    Django 视图
    Django 路由系统
    Django 模版语言
  • 原文地址:https://www.cnblogs.com/AngeLeyes/p/7818221.html
Copyright © 2020-2023  润新知