2009-07-10 4 views
2

Je construis un script de construction pour notre équipe de développement web. Nous allons utiliser ce script pour préparer tout notre code frontal pour la production. J'utilise le compresseur YUI pour compresser nos fichiers CSS et JavaScript. Tout fonctionne correctement pour la partie CSS, mais je rencontre un problème avec l'instance de la classe JavaScriptCompressor.Java YUI Javascript-Compressor Error

Je l'importation des fichiers YUI via cette ligne:

import com.yahoo.platform.yui.compressor.*; 

Voici mon exemple JavaScriptCompressor:

FileReader ftcreader = new FileReader(ftc); 
JavaScriptCompressor js = new JavaScriptCompressor(ftcreader); 

Pour référence, voici comment j'utilise la classe CssCompressor, qui fonctionne correctement :

FileReader ftcreader = new FileReader(ftc); 
CssCompressor css = new CssCompressor(ftcreader); 

Pour une raison quelconque, j'obtiens une erreur pour JavaScriptCompress ou classe, indiquant:

The constructor JavaScriptCompressor(FileReader) is undefined 

Est-ce que j'importe les fichiers YUI Compressor incorrectement? Ou s'agit-il d'autre chose? Toute aide serait grandement appréciée.

Répondre

2

vous ErrorReporter absent, le second argument du constructeur:

JavaScriptCompressor compressor = 
     new JavaScriptCompressor(in, new SystemOutErrorReporter()); 
    compressor.compress(out, 1 << 20, false, false, false, false); 

puis un échantillon ErrorReporter:

class SystemOutErrorReporter implements ErrorReporter { 

    private String format(String arg0, String arg1, int arg2, String arg3, int arg4) { 
     return String.format("%s%s at line %d, column %d:\n%s", 
      arg0, 
      arg1 == null ? "" : ":" + arg1, 
      arg2, 
      arg4, 
      arg3); 
    } 

    @Override 
    public void warning(String arg0, String arg1, int arg2, String arg3, int arg4) { 
     System.out.println("WARNING: " + format(arg0, arg1, arg2, arg3, arg4)); 
    } 

    @Override 
    public void error(String arg0, String arg1, int arg2, String arg3, int arg4) { 
     System.out.println("ERROR: " + format(arg0, arg1, arg2, arg3, arg4)); 
    } 

    @Override 
    public EvaluatorException runtimeError(String arg0, String arg1, int arg2, String arg3, int arg4) { 
     System.out.println("RUNTIME ERROR: " + format(arg0, arg1, arg2, arg3, arg4)); 
     return new EvaluatorException(arg0); 
    } 
}