2

I'm using Closure Compiler in my application. For the moment, I use XML to send my javascript to the CC's web service and compile the code. What I want to do is include CC into the project itself so that the compilation doesn't rely on the web service but is done entirely on the server. How do you include the .jar files that are downloaded in the CC download package and make it work in .net?

Thanks.

frenchie
  • 51,731
  • 109
  • 304
  • 510
  • Do you want to invoke it at run time from your C# code? Or is it just part of your standard build process? By the way you can just install it on your server, modify your $PATH variable so it can be references directly and then invoke it as a command line process like you would any other random executable on your local hard drive. – evanmcdonnal Dec 27 '13 at 19:44
  • @evanmcdonnal: I want to be able to invoke it at runtime. – frenchie Dec 27 '13 at 19:47
  • Just to be clear, you want to use Closure-compiler on the server in a compile-on-demand setting? – Chad Killingsworth Dec 30 '13 at 18:02
  • @ChadKillingsworth: yes, I want to write a write method that compiles some js file at runtime. – frenchie Dec 31 '13 at 04:07
  • @ChadKillingsworth: BTW, I've asked a follow-up question regarding implementing the answer that evan provided below: http://stackoverflow.com/questions/20851606/including-closure-compiler-into-an-asp-net-app-using-command-line – frenchie Dec 31 '13 at 04:15

1 Answers1

3

The simplest solution is just to put the CC folder on that server and then add it's path to your $PATH. Another option is to add it as a resource in the project and then set Copy to Output Dir to Always or If Newer and use a relative path to access it. I believe the second option is better because it removes the outside dependency.

Once you have the file there you can start a command line process with the commands like they have in the docs java -jar compiler.jar --js hello.js --js_output_file hello-compiled.js and it will do what you want. There is of course also a Java dependency. For some basic info on starting process' in C# check out http://msdn.microsoft.com/en-us/library/system.diagnostics.process(v=vs.110).aspx

evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115
  • @frenchie the first answer here has a good example http://stackoverflow.com/questions/1469764/run-command-prompt-commands it's pretty much the same regardless of what you're running, you just change the `Arguments` parameter to be something like "google-cc filenameToMinify otherOptionsIcantRembmer" – evanmcdonnal Dec 30 '13 at 18:13
  • Ok, the answer shows how to access the command line. Do I just put the .jar file in any directory in my app or do I need to put it in the Bin directory? – frenchie Dec 30 '13 at 21:59
  • @frenchie it can be anywhere, you just need to invoke it with the correct path. Personally, I would add it to my project. If the project was sufficiently large I would have an ExternalResources folder where it would go. When the project built that folder would exist in the bin and would have the jar file in it. From there, I could always use the relative path `.\ExternalResources\compiler.jar`. If my project were small enough I would just add it directly under the csproj file so it would go in the bin itself, if that were the case the path would just be `.\compiler.jar` – evanmcdonnal Dec 30 '13 at 22:11
  • Ok, thanks for the answer; I'll try it out in the next few days and let you know how GCC works without the web service API. – frenchie Dec 30 '13 at 22:13
  • Hey, can you take a look at this follow-up question: http://stackoverflow.com/questions/20851606/including-closure-compiler-into-an-asp-net-app-using-command-line – frenchie Jan 08 '14 at 22:09