Maven控制台项目打包成jar包教程

直接在pom文件plugins中配置<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-jar-plugin</artifactId>    <configuration>        <archive>            <manifest>                <mainClass>top.cway.OkHttpArctime</mainClass>                <!-- 您主类包名 -->            </manifest>        </archive>    </configuration></plugin>对于一般控制台程序亦可直接配置MANIFEST.MF,在java包中创建/META-INF/MANIFEST.MF,文件内容如下:Manifest-Version: 1.0Main-Class: top.cway.OkHttpArctimeidea的话可以在项目配置中添加即可选择启动类Main Class然后再build即可

Maven控制台项目打包成jar包教程

Java中取指定范围随机数的方法

例如随机取从20到100的整数,由于随机取值范围 [0,1),因此直接加起始数,因为nextInt中值可能为0,但是又小于最大数减起始数,因此需要加1            Random random1 = new Random();            int num = random1.nextInt(100 - 20 + 1) + 20;//            总结下:random1.nextInt(大数-小数+1)+小数或者使用如下,Math.random()与new Random().nextDouble()基本相同int num1 = new Double(Math.random() * (100 - 20 + 1) + 20).intValue();int num2 = (int) (new Random().nextDouble() * (100 - 20 + 1) + 20);int number1 = (int) (Math.random() * (100 - 20 + 1)) + 20;//不想减1的话直接四舍五入呗 前面原本1*79.999…… 四舍五入也就80了int number2 = (int) round(Math.random() * (100 - 20)) + 20;new Random(10)其中的10为初始种子,如果种子一致每次产生的随机序列是相同的,因此多个随机的话可以设置不同的种子,种子seed值一般可设置为当前时间。