一,安装环境
1.安装spm
spm工具是基于node(nodejs的服务平台)的,因此我们需要先安装 node 和 npm 下载地址:http://nodejs.org/#download.下载完成后安装即可。
node安装完成后,找到cmd命令文件以管理员的方式打开,输入以下命令进行安装:
npm install spm -g
在此过程中,可能需要你很长的时间等待。(偶尔可能连接失败了,你需要关闭cmd后重新开启并执行同样的命令,过程将继续)
安装完成后,恭喜你,可以使用了。
2.spm的使用:
使用spm其实就是执行cmd命令,安装完成后,你就可以使用命令了 (当然有很多命令的),输入:
spm help
你会看到所有的命令。我们主要用的命令就是
spm build
当然得注意两点:
(1).需要将执行目录切换到项目。比如你的项目js目录在D:/www/spm/js下;则需要先用cmd命令切换到D:/www/spm/js.见下图
(2).项目的js目录结构里面必须包含src目录,即未合并和压缩的js文件(seajs模块文件)。目录结构约定传送门。
最后,这些只是将了我接触的时候遇到的问题,具体spm命令及使用细节请见官方文档
https://github.com/spmjs/spm/
二,批量压缩类
写了个类查找所有JS文件,调用DOS命令执行文件的压缩
package com.tank.test; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggerFactory; /** * @author tank * @date:Sep 24, 2012 4:14:58 PM * @description: * @version :1.0 */ public class TestSeaJS { private static final Logger logger = Logger.getLogger(TestSeaJS.class); private static final String SRC_PATH = "F:/MyEclipseforSpring8.6/showcang/WebRoot/js"; private static final String OUT_PATH = "D:/apache-tomcat-6.0.35/webapps/showcang/js"; //private static final String APP_URL = "http://127.0.0.1:8080/js"; private static final String APP_URL = "http://www.showcang.com/js"; // private static final String CMD = "spm build #0# --combine --app_url #1# // --app_path #2# --out_path #3#"; private static StringBuffer sb = new StringBuffer(); public static void main(String[] args) { //String cmdStr = "spm build ${0} --combine --app_url ${1} --app_path ${2} --out_path ${3}"; File file = new File(SRC_PATH); StringBuffer sbcontext = new StringBuffer(); // sbcontext.append("d: \r"); // sbcontext.append("cd D:/Soft/seajs-spm-ab7a728/demo/js \r"); findFile(file, sbcontext); new FileHelper().getWriteTXT("c:/seajs.bat", sbcontext.toString()); logger.info("压缩完成!"); } public static void findFile(File file, StringBuffer sbcontext) { File[] dir = file.listFiles(); for (File f : dir) { if (f.isFile()) { String filepath = f.getAbsolutePath(); if (filepath != null && filepath.toLowerCase().endsWith("js")) { String dirpath = f.getParentFile().getPath(); String outPath = dirpath.substring(SRC_PATH.length()); sb.delete(0, sb.length()); sb.append("spm build ").append(filepath).append(" --combine --app_url ").append(APP_URL).append(" --app_path ").append(dirpath).append( " --out_path ").append(OUT_PATH).append(outPath); sbcontext.append(sb.toString()); Runtime rt = Runtime.getRuntime(); BufferedReader br = null; try { Process process = rt.exec("cmd /C " + sb.toString()); br = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = br.readLine(); while (line != null) { logger.info(line); line = br.readLine(); } } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage()); } finally { if (br != null) { try { br.close(); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); } } } sbcontext.append("\r"); } } else if (file.isDirectory()) { findFile(f, sbcontext); } } } }
文件帮助类:
package com.tank.test; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; /** * @author tank * @date:Sep 26, 2011 9:03:29 PM * @description: 纯文本文件操作类 .txt * @version : */ public class FileHelper { public String getReadTXT(String path) { BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(new FileInputStream(path), "utf-8")); String data = null; StringBuffer sbf = new StringBuffer(); while ((data = br.readLine()) != null) { sbf.append(data); } return sbf.toString(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return null; } public boolean getWriteTXT(String path, String writeContext) { OutputStreamWriter fw = null; try { fw = new OutputStreamWriter(new FileOutputStream(path), "utf-8"); fw.write(writeContext, 0, writeContext.length()); fw.flush(); return true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } finally { try { fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
三,写批处理调用
java -jar compass.jar
执行bat即可!
相关推荐
NULL 博文链接:https://web322-szb.iteye.com/blog/1734863
matlab中的SPM软件包的使用原理及应用,这是第一部分,还有第二部分。
spm-build(不建议使用,请对cmd使用 ,对于独立使用 ) 用于spm3的构建工具。 如果您仍在使用spm2,请转到分支 。 安装 $ npm install spm-build -g 用法 $ spm-build [option] [file] 选项 -I, --input-directory...
SPM使用简介SPM使用简介SPM使用简介SPM使用简介SPM使用简介SPM使用简介
seajs-cssA Sea.js plugin for loading cssInstallInstall with spm:$ spm install seajs/seajs-cssUsage[removed][removed][removed][removed][removed]// seajs can load css file after loading css plugin.seajs...
$ spm install seajs/seajs-css Usage [removed][removed] [removed][removed] [removed] // seajs can load css file after loading css plugin. seajs.use("path/to/some.css") [removed] 中文说明 在Sea.js < ...
npm 打包文件,包含 express gruntjs spm 组件
spm12软件包 spm12软件包 spm12软件包
海浪 seajs中的SPM项目捆绑程序。安装$ npm install spm-sea -g用法$ spm-sea [option] [file]存在版权所有(c)2015-2114 chencheng。 根据MIT许可获得许可。
该文件为使用spm的详细说明,也可以在spm官网上下载
学习Niftynet平台中,读取nii格式的文件,用于医学图像处理第...SPM(Statistical Parametric Mapping)是由UCL(University College London)的Wellcome Trust Centre中心的成员及其合作者开发的应用于神经影像的软件。
脑功能成像分析软件SPM在医学脑功能图像(MRI、CT、SPECT、PET)中的使用介绍
粗体信号MATLAB代码spm12-dartel 使用 SPM12 和 DARTEL 将功能和结构 MRI 数据预处理到标准化 MNI 空间的代码。 仅可用于一次结构扫描(例如 T1 MPRAGE 或 T2 匹配带宽) 可用于两个结构扫描(例如 T1 MPRAGE和T2 ...
spm是基于matlab平台的医学图像处理工具 本pdf详细介绍了用最新版spm8进行T检验的具体步骤方法
SPM5操作手册,详尽每一个操作步骤,解答你的疑惑
spm 文件压缩 jasmine测试框架
使用 spm 安装: $ spm install seajs/seajs-preload 用法 < script src =" path/to/sea.js " > </ script > < script src =" path/to/seajs-preload.js " > </ script > < script &...
磁共振数据处理必备,已经有spm12,但是这个spm8更稳定
myspmspm 标准构建 seajs 项目
珠海派诺 智能电表 SPM91 串行 MODBUS 通信协议,版本V2.0,简介:详细描述了SPM91电表在MODUS通讯模式下的输入和输出命令,信息和资料,以便第三方使用和开发。