你们注意一下,因为在写入MANIFEST的时候,Class-Path路径给的是 ../lib
,即上级目录的lib。 因此在对拍时若是手动移动了 jar包的位置,须要保证 lib/ 文件夹在存放jar包的上一级目录下,不然在运行时会报错 ClassNotFound
java
(也能够在源码中直接修改jar包的输出位置)git
一种可能的文件树以下:github
├──src │ ├─ Archer.jar │ ├─ Berserker.jar │ ├─ Caster.jar | ├─ .... | └─ Alterego.jar ├──lib │ ├─ elevator-input-hw3-1.4-jar-with-dependencies.jar │ └─ timable-output-1.1-raw-jar-with-dependencies.jar └──your_pat.py
一键build:zip -> jar
因为每次互测都要通过重复的操做:shell
download -> unzip -> compile -> runbash
本着一懒到底的原则,以及想要进一步熟悉一下shell指令,写了一个builder的脚本。测试
本身留着没意思,就拿出来分享给你们了,慢慢享用。ui
同时要感谢一下 fmh,过程当中帮我解决了许多问题,还有 lqq 以身试法帮我测试~spa
2.
中,更改相应的lib文件的绝对路径├──src │ ├─ Archer.zip │ ├─ Berserker.zip │ ├─ Caster.zip | ├─ .... | └─ Alterego.zip ├──lib │ ├─ elevator-input-hw3-1.4-jar-with-dependencies.jar │ └─ timable-output-1.1-raw-jar-with-dependencies.jar └──builder.sh
builder.sh
而后就能够愉快地开始对拍啦code
注意若是有player上交的src文件有多个main入口,有可能会出错。(但一样的,若是上交文件包含有多个入口,官方评测可能也过不了,这也是为何rules中规定只能有一个入口)orm
easy
player/out/
lib
中的 -classpath 为绝对路径MANIFEST.mf
的写入
elevator3.Main
grep
检索.java
文件,获得Main类包路径,再对获得的路径进行标准格式化操做便可。.
表示当前路径;..
表示上一目录的路径#!/bin/bash # Pre-Condition: # NOTHING # Attention: # *.zip will be deleted # Procedure: # 1. put all *.zip into the src/ folder # 2. put the external .jar into lib/ folder # 3. run './builder.sh' # 4. the jar-files has been generated in the 'out' folder of the corresponding directory, enjoy! # file-tree is as follows: # dir # ├──src # ├──lib # └──builder.sh cd src/ # 1. unzip and copy lib/ to src/ echo unzip start... ls *.zip > temp.txt sed 's/.zip//g' temp.txt > names.txt # sed 's/src/dst/' names=`cat names.txt` # attention # echo $names for name in ${names[@]} do mkdir $name unzip $name.zip -d $name cp -a ../lib $name done rm *.txt rm *.zip echo unzip successfully... # 2. compile to class echo complie start... prefix="javac -encoding utf-8 -d out/ @srcpath.txt " lib="-classpath /C/Users/94831/Desktop/CourseCenter/OO/testShell/lib/elevator-input-hw3-1.4-jar-with-dependencies.jar:/C/Users/94831/Desktop/CourseCenter/OO/testShell/lib/timable-output-1.1-raw-jar-with-dependencies.jar " command=${prefix}${lib} dirs=`ls` echo $dirs for dir in ${dirs[@]} do # echo $dir cd $dir mkdir out find -name "*.java" > srcpath.txt $command # rm srcpath.txt cd .. done echo compile successfully... # 3. pack to jar echo packing to jar... for dir in ${dirs[@]} do echo $dir cd $dir # write config information to MANIFEST.mf echo -n 'Main-Class: ' > MANIFEST.mf grep -l "public static void main" . -r | sed s/\\.\\///g | sed s/src\\///g | sed s/\\.java//g | sed s/\\//./g >> MANIFEST.mf sed '2, $d' MANIFEST.mf | tee MANIFEST.mf echo 'Class-Path: ../lib/elevator-input-hw3-1.4-jar-with-dependencies.jar ../lib/timable-output-1.1-raw-jar-with-dependencies.jar' >> MANIFEST.mf echo >> MANIFEST.mf mv MANIFEST.mf out cd out find -name "*.class" > classpath.txt jar cvfm $dir.jar MANIFEST.mf @classpath.txt cd .. # from out cd .. # from player_dir done echo pack successfully...