C#调用jar包压缩js
压缩库为google提供的 Closure Compiler
https://developers.google.com/closure/compiler/?hl=zh-cn
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace TestProcessDosCmd
{
class Program
{
static void Main(string[] args)
{
Process p = null;
p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.RedirectStandardError = false;
p.StartInfo.CreateNoWindow = false;
p.Start();
String sResult = string.Empty;
string strCmd = "java -jar compiler.jar --help";
//string strCmd = @"java -jar compiler.jar --js D:\DevSoft\Library\compiler-latest\js_name.js --js_output_file D:\DevSoft\Library\compiler-latest\js_name_compressed_prog.js";
//不能源文件与目的文件放同一位置
//string strCmd = @"java -jar compiler.jar --js D:\DevSoft\Library\compiler-latest\js_name_bak.js --js_output_file D:\DevSoft\Library\compiler-latest\js_name_bak.js";
//string strCmd = "java -version";
p.StandardInput.WriteLine(strCmd);
//while (!p.StandardError.EndOfStream)
//{
// sResult = p.StandardError.ReadLine();
// Console.WriteLine(sResult);
//}
//p.StandardInput.Flush();
//while (!p.StandardOutput.EndOfStream)
//{
// sResult = p.StandardOutput.ReadLine();
// Console.WriteLine(sResult);
//}
p.StandardInput.WriteLine("exit");
p.WaitForExit();
p.Close();
Console.WriteLine("Press Any Key to exit.");
Console.ReadKey();
}
}
}
from: https://developers.google.com/closure/compiler/docs/api-tutorial1?hl=zh-cn
#!/usr/bin/python2.4
import httplib, urllib, sys
# Define the parameters for the POST request and encode them in
# a URL-safe format.
params = urllib.urlencode([
('js_code', sys.argv[1]),
('compilation_level', 'WHITESPACE_ONLY'),
('output_format', 'text'),
('output_info', 'compiled_code'),
])
# Always use the following value for the Content-type header.
headers = { "Content-type": "application/x-www-form-urlencoded" }
conn = httplib.HTTPConnection('closure-compiler.appspot.com')
conn.request('POST', '/compile', params, headers)
response = conn.getresponse()
data = response.read()
print data
conn.close

浙公网安备 33010602011771号