this.environment.set( Packager.KEY_ENVIRONMENT, packager );
	protected void jar( Device device, Locale locale ) {		File classesDir = new File( device.getClassesDir() );				try {			// copy resources:			this.resourceManager.copyResources(classesDir, device, locale);		} catch (IOException e) {			System.out.println("creating JAR for device [" + device.getIdentifier() + "]." );			e.printStackTrace();			throw new BuildException("Unable to assemble resources: " + e.toString(), e );		}				// retrieve the name of the jar-file:		String jarName = this.environment.getVariable("polish.jarName");		File jarFile = new File( this.buildSetting.getDestDir().getAbsolutePath() 						+ File.separatorChar + jarName );		device.setJarFile( jarFile );		String test = this.polishProject.getCapability("polish.license");		if ( !this.infoSetting.getlicense().equals(test)) {			throw new BuildException("Encountered invalid license.");		}				// create manifest:		HashMap attributesByName = new HashMap();		attributesByName.put( "Manifest-Version", new Attribute( "Manifest-Version", "1.0" ) ); 		// set MicroEdition-Profile:		String profile = this.infoSetting.getProfile();		if (profile == null) {						if (device.isMidp2()) {				profile = InfoSetting.MIDP2;			} else {				profile = InfoSetting.MIDP1;			}		}		attributesByName.put( InfoSetting.MICRO_EDITION_PROFILE, new Attribute(InfoSetting.MICRO_EDITION_PROFILE, profile) );		// set MicroEdition-Configuration:		String config = this.infoSetting.getConfiguration();		if (config == null) {						if (!device.isCldc10()) {				config = InfoSetting.CLDC1_1;			} else {				config = InfoSetting.CLDC1_0;			}		}		attributesByName.put( InfoSetting.MICRO_EDITION_CONFIGURATION, new  Attribute(InfoSetting.MICRO_EDITION_CONFIGURATION, config) );		// add info attributes:		Attribute[] jadAttributes = this.infoSetting.getManifestAttributes( this.environment.getVariables() );		for (int i = 0; i < jadAttributes.length; i++) {			Attribute attribute = jadAttributes[i];			attributesByName.put( attribute.getName(), attribute );		}				// add build properties - midlet infos:		String mainClassName = this.environment.getVariable( "polish.classes.main" );		if (mainClassName != null) {			//System.out.println("Using Main-Class " + mainClassName );			attributesByName.put( "Main-Class", new Attribute( "Main-Class", mainClassName ) );			attributesByName.put( "MIDlet-1", new Attribute( "MIDlet-1", ",," ) );		} else {			String[] midletInfos = this.buildSetting.getMidletInfos( this.infoSetting.getIcon(), this.useDefaultPackage, this.environment );			for (int i = 0; i < midletInfos.length; i++) {				String info = midletInfos[i];				attributesByName.put( InfoSetting.NMIDLET + (i+1), new  Attribute(InfoSetting.NMIDLET + (i+1), info ) );			}		}		// add user-defined attributes:		Project antProject = getProject();		BooleanEvaluator evaluator = this.environment.getBooleanEvaluator();		if (this.buildSetting.getJadAttributes() != null) {			Attribute[] attributes = this.buildSetting.getJadAttributes().getAttributes(antProject, evaluator, this.environment);			for (int i = 0; i < attributes.length; i++) {				Attribute attribute = attributes[i];				if ( attribute.targetsManifest() ) {					attributesByName.put(attribute.getName(),attribute );				}			}		}				//add polish version:		attributesByName.put( "Polish-Version", new Attribute("Polish-Version", VERSION ) );				// sort and filter the attributes if this is requested:		Attribute[] manifestAttributes = null;		try {			manifestAttributes = this.buildSetting.filterManifestAttributes(attributesByName, this.environment.getBooleanEvaluator() );		} catch (BuildException e) {			System.err.println("Unable to filter MANIFEST attributes: " + e.getMessage() );			throw e;		}		this.environment.set( ManifestCreator.MANIFEST_ATTRIBUTES_KEY, manifestAttributes );		this.environment.set( ManifestCreator.MANIFEST_ENCODING_KEY, this.buildSetting.getEncoding() );//		Jad jad = new Jad( this.environment );//		jad.setAttributes(manifestAttributes);				try {			if (jarFile.exists()) {				boolean success = jarFile.delete();				if (!success) {					throw new BuildException("Unable to delete the existing JAR-file [" + jarFile.getAbsolutePath() + "], please call \"ant clean\" or remove the folder \"" + jarFile.getParent() + "\"-folder manually." );				}			}			System.out.println("creating JAR file ["+ jarFile.getAbsolutePath() + "].");			// writing manifest:			String creatorName = this.environment.getVariable( "polish.build.ManifestCreator" );			if (creatorName == null ) {				creatorName = "default";			}			this.extensionManager.executeTemporaryExtension(ExtensionManager.TYPE_MANIFEST_CREATOR, creatorName, this.environment );//			Manifest manifest = new Manifest( this.environment, this.buildSetting.getEncoding() );//			manifest.setAttributes( manifestAttributes );//			File manifestFile = new File( device.getClassesDir() //					+ File.separator + "META-INF" + File.separator + "MANIFEST.MF");//			manifest.write(manifestFile);			//FileUtil.writeTextFile( manifestFile, jad.getContent(), this.buildSetting.getEncoding() );			// package all classes and resources:			Packager packager = (Packager) this.extensionManager.getActiveExtension( ExtensionManager.TYPE_PACKAGER, this.environment );			if (packager == null ) {				packager = new DefaultPackager();			}			packager.createPackage(classesDir, jarFile, device, locale, this.environment );		} catch (IOException e) {			e.printStackTrace();			throw new BuildException("Unable to create final JAR file: " + e.getMessage(), e );		}			}