工具及经验总结

  |   0 评论   |   159 浏览

Java

SpringBoot启动

nohup java -jar xxx-0.0.1-SNAPSHOT.jar  > micro-communication.log  2>&1 &

Maven

assembly方式和JSW(Java Service Wrapper)包装

  • Maven打包使用assembly方式可以自定义打包后的文件格式,方便传输。
  • 加入JSW包装让程序作为windows服务或者unix守护进程运行
  • 增强程序的可靠性,程序崩溃后的自动重启,比如内存溢出,虚拟机崩溃等造成JVM退出的监控和恢复运行
  • 标准的,可独立使用的配置JVM参数的脚本
  • 支持java应用程序重启JVM,比如应用程序修改了配置文件,或者重启系统避免内存溢出等问题
    <build>
        <plugins>
            <!-- Specify JDK compiler version -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <!-- Specify the configuration files that do not need to be packaged into the jar package -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <!-- The exclusion rule is recommended to be consistent with the import rules in the assembly.xml file -->
                    <excludes>
                        <!-- Custom configuration -->
                        <exclude>*.yml</exclude>
                        <exclude>*.xml</exclude>
                        <exclude>*.properties</exclude>
                        <exclude>static/**</exclude>
                        <!-- Must be configured -->
                        <exclude>*.conf</exclude>
                        <exclude>tools/**</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Packing command: mvn clean package appassembler:generate-daemons -Dmaven.test.skip=true -->
            <!-- Using JSW services to create scaffolding for target material packages -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>2.0.0</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <binFolder>bin</binFolder>
                    <tempDirectory>tmp</tempDirectory>
                    <logsDirectory>logs</logsDirectory>
                    <repositoryName>lib</repositoryName>
                    <repositoryLayout>flat</repositoryLayout>
                    <target>${project.build.directory}/dist</target>
                    <configurationDirectory>conf</configurationDirectory>
                    <copyConfigurationDirectory>true</copyConfigurationDirectory>
                    <configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
                    <daemons>
                        <daemon>
                            <id>app</id>
                            <!-- Main Class -->
                            <mainClass>com.mmzs.zero.it.system.SystemApplication</mainClass>
                            <platforms>
                                <!-- Java Service Wrapper -->
                                <platform>jsw</platform>
                            </platforms>
                            <generatorConfigurations>
                                <generatorConfiguration>
                                    <generator>jsw</generator>
                                    <includes>
                                        <include>aix-ppc-32</include>
                                        <include>aix-ppc-64</include>
                                        <include>linux-ppc-64</include>
                                        <include>linux-x86-32</include>
                                        <include>linux-x86-64</include>
                                        <include>windows-x86-32</include>
                                        <include>windows-x86-64</include>
                                        <include>hpux-parisc-64</include>
                                        <include>solaris-x86-32</include>
                                        <include>solaris-sparc-32</include>
                                        <include>solaris-sparc-64</include>
                                        <include>macosx-ppc-32</include>
                                        <include>macosx-universal-32</include>
                                        <include>macosx-universal-64</include>
                                    </includes>
                                    <configuration>
                                        <property>
                                            <name>configuration.directory.in.classpath.first</name>
                                            <value>conf</value>
                                        </property>
                                        <property>
                                            <name>wrapper.ping.timeout</name>
                                            <value>120</value>
                                        </property>
                                        <property>
                                            <name>set.default.REPO_DIR</name>
                                            <value>lib</value>
                                        </property>
                                        <property>
                                            <name>wrapper.logfile</name>
                                            <value>logs/wrapper.log</value>
                                        </property>
                                    </configuration>
                                </generatorConfiguration>
                            </generatorConfigurations>
                            <jvmSettings>
                                <!-- JMX -->
                                <systemProperties>
                                    <systemProperty>java.security.policy=conf/policy.all</systemProperty>
                                    <systemProperty>com.sun.management.jmxremote</systemProperty>
                                    <systemProperty>com.sun.management.jmxremote.port=8500</systemProperty>
                                    <systemProperty>com.sun.management.jmxremote.authenticate=false</systemProperty>
                                    <systemProperty>com.sun.management.jmxremote.ssl=false</systemProperty>
                                </systemProperties>
                                <!-- https://blog.csdn.net/wo541075754/article/details/75008617 -->
                                <!-- https://zhaoyanblog.com/archives/440.html -->
                                <!-- https://www.javadoop.com/post/g1 -->
                                <extraArguments>
                                    <extraArgument>-server</extraArgument>
                                    <!-- Remote Debug -->
                                    <extraArgument>-Xdebug</extraArgument>
                                    <extraArgument>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5006
                                    </extraArgument>
                                    <!-- Heap Dump -->
                                    <extraArgument>-XX:+HeapDumpOnOutOfMemoryError</extraArgument>
                                    <extraArgument>-XX:HeapDumpPath=logs/heap-dump.hprof</extraArgument>
                                    <!-- GC Config -->
                                    <extraArgument>-XX:+UseG1GC</extraArgument>
                                    <extraArgument>-XX:MaxGCPauseMillis=200</extraArgument>
                                    <extraArgument>-XX:InitiatingHeapOccupancyPercent=45</extraArgument>
                                    <extraArgument>-XX:G1ReservePercent=10</extraArgument>
                                    <extraArgument>-XX:NewRatio=2</extraArgument>
                                    <extraArgument>-XX:SurvivorRatio=8</extraArgument>
                                    <extraArgument>-XX:MaxTenuringThreshold=15</extraArgument>
                                    <!-- GC Log -->
                                    <extraArgument>-Xloggc:logs/gc.log</extraArgument>
                                    <extraArgument>-XX:GCLogFileSize=10M</extraArgument>
                                    <extraArgument>-XX:NumberOfGCLogFiles=10</extraArgument>
                                    <extraArgument>-XX:+UseGCLogFileRotation</extraArgument>
                                    <extraArgument>-XX:+PrintGCDateStamps</extraArgument>
                                    <extraArgument>-XX:+PrintGCTimeStamps</extraArgument>
                                    <extraArgument>-XX:+PrintGCDetails</extraArgument>
                                    <extraArgument>-XX:+PrintHeapAtGC</extraArgument>
                                    <extraArgument>-XX:+PrintGCApplicationStoppedTime</extraArgument>
                                    <extraArgument>-XX:+DisableExplicitGC</extraArgument>
                                    <extraArgument>-verbose:gc</extraArgument>
                                </extraArguments>
                            </jvmSettings>
                        </daemon>
                    </daemons>
                </configuration>
                <executions>
                    <execution>
                        <id>generate-jsw-scripts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>generate-daemons</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Use assembly to package the scaffolding directory into compressed packets -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/resources/tools/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

MyBatis

MyBatisplus

MyBatisplus自动化构建工具

1、使用前先导入对应的包:

<!-- mybatisplus生成工具需要的依赖 -->
...
<dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>1.7</version>
    <scope>test</scope>
</dependency>
...
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-generator</artifactId>
    <version>3.0.6</version>
    <scope>test</scope>
</dependency>

2、使用方式如下:

package cn.micro.dc;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.lang.reflect.Field;

public class CustomGenerator {

    public static void main(String[] args) throws Exception {
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        gc.setOutputDir("/Users/echo/IdeaProjects4/micro-dc/src/main/java");
        gc.setFileOverride(true);
        gc.setActiveRecord(true);
        gc.setEnableCache(true);// XML 二级缓存
        gc.setBaseResultMap(true);// XML ResultMap
        gc.setBaseColumnList(true);// XML columList
        gc.setAuthor("lry");

        // 自定义文件命名,注意 %s 会自动填充表实体属性!
        gc.setMapperName("I%sMapper");
        gc.setXmlName("%sMapper");
        gc.setServiceName("I%sService");
        gc.setServiceImplName("%sServiceImpl");
        gc.setControllerName("%sController");
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(DbType.MYSQL);

        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUrl("jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxx?useUnicode=true&characterEncoding=UTF-8&generateSimpleParameterMetadata=true");
        dsc.setUsername("root");
        dsc.setPassword("root");
        mpg.setDataSource(dsc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
        strategy.setInclude(new String[]{"wx_user_info"}); // 需要生成的表
//        strategy.setExclude(new String[]{"order"}); // 排除生成的表
        Field field = strategy.getClass().getDeclaredField("logicDeleteFieldName");
        field.setAccessible(true);
        field.set(strategy, "logic_del");
        mpg.setStrategy(strategy);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("cn.micro");
        pc.setModuleName("dc");
        mpg.setPackageInfo(pc);

        // 执行生成
        mpg.execute();
    }

}

密钥

生成pfx签名文件

第一步:生成采用des3算法保护的私钥:

openssl genrsa -des3 -out private-rsa.key 1024

命令执行过程中,提示信息Enter pass phrase的含义是输入用来保护私钥文件的密码(最好不要超过6位)
第二步:生成公钥证书:

openssl req -new -x509 -key private-rsa.key -days 750 -out public-rsa.cer

该过程除了最开始时需要输入私钥文件的保护密码之外,其他需要的输入均可直接回车忽略,不影响正常使用。
第三步:生成PKCS12格式Keystore:

openssl pkcs12 -export -name test-alias -in public-rsa.cer -inkey private-rsa.key -out user-rsa.pfx

面试问题

设计

用户和用户组的概念


标题:工具及经验总结
作者:StudyofNeural
地址:https://www.mmzsblog.cn/articles/2019/08/07/1565161662449.html

个人微信公众号:

评论

发表评论