发表于: 2018-03-17 21:17:10
1 644
今天完成的事情:
服务器上用jar包插入一百万条数据
复习一下mvn命令,使用mvn命令运行了下jar包
mvn test 运行测试
mvn site 产生site
mvn package 打包
mvn install 在本地Repository中安装jar:
mvn clean 清除产生的项目:
mvn eclipse:eclipse 生成eclipse项目:
mvn idea:idea 生成idea项目:
mvn -Dtest package 组合使用goal命令,如只打包不测试:
mvn test-compile 编译测试的内容:
mvn jar:jar 只打jar包:
package mybatis;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.InputStream;
public class MapperTest {
private static SqlSessionFactory sqlSessionFactory;
public static void main(String[] args) throws IOException {
long start=System.currentTimeMillis();
String resource = "sqlMapConfig.xml"; //mybatis配置文件
//得到配置文件的流
InputStream inputStream = Resources.getResourceAsStream(resource);
//创建会话工厂SqlSessionFactory,要传入mybaits的配置文件的流
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession sqlSession = sqlSessionFactory.openSession();
User user=new User("韩","梁家键","前端工程师");
int aa = Integer.valueOf(args[0]);
for (int s=0;s<=aa;s++){
// User user=new User("韩");
sqlSession.insert("mybatis.UserMapper.insertUser",user);
sqlSession.commit();
// long a = user.getId();
}
sqlSession.close();
long end=System.currentTimeMillis();
long a = user.getId();
System.out.println(a);
System.out.println("程序运行时间: "+(end-start)/1000+"S");
}
}
<?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>mapperDao</groupId>
<artifactId>mapperDao</artifactId>
<version>1.1</version>
<dependencies>
<!--单元测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- mybatis支持-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.3.0</version>
</dependency>
<!--mysql支持-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
<!--log4j-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<targetPath>${project.build.directory}/classes</targetPath>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<targetPath>${project.build.directory}/classes</targetPath>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-shade-plugin</artifactId>-->
<!--<version>2.3</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>shade</goal>-->
<!--</goals>-->
<!--<configuration>-->
<!--<transformers>-->
<!--<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">-->
<!--<mainClass>mybatis.MapperTest</mainClass>-->
<!--</transformer>-->
<!--</transformers>-->
<!--<artifactSet>-->
<!--</artifactSet>-->
<!--</configuration>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-jar-plugin</artifactId>-->
<!--<configuration>-->
<!--<classesDirectory>target/classes/</classesDirectory>-->
<!--<archive>-->
<!--<manifest>-->
<!--<!– 主函数的入口 –>-->
<!--<mainClass>mybatis.MapperTest</mainClass>-->
<!--<!– 打包时 MANIFEST.MF文件不记录的时间戳版本 –>-->
<!--<useUniqueVersions>false</useUniqueVersions>-->
<!--<addClasspath>true</addClasspath>-->
<!--<classpathPrefix>lib/</classpathPrefix>-->
<!--</manifest>-->
<!--<manifestEntries>-->
<!--<Class-Path>.</Class-Path>-->
<!--</manifestEntries>-->
<!--</archive>-->
<!--</configuration>-->
<!--</plugin>-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!-- 此处指定main方法入口的class -->
<mainClass>mybatis.MapperTest</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
明天计划的事情:
任务一深度思考
遇到的问题:
输入中文字符报错
本地能运行,但是jar包无法运行
原因一,大小写的问题
原因二:依赖的缺失
这时候需要正确的包
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!-- 此处指定main方法入口的class -->
<mainClass>mybatis.MapperTest</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
还有一种路径配置方法
<resources>
<resource>
<targetPath>${project.build.directory}/classes</targetPath>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<targetPath>${project.build.directory}/classes</targetPath>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
收获:(通过今天的学习,学到了什么知识)
评论