List of usage examples for java.util.jar JarOutputStream write
public synchronized void write(byte[] b, int off, int len) throws IOException
From source file:com.taobao.android.tools.TPatchTool.java
/** * add files to jar/*from w w w . j a va 2s . com*/ * * @param jos * @param file */ private void addFile(JarOutputStream jos, File file) throws IOException { byte[] buf = new byte[8064]; String path = file.getName(); InputStream in = null; try { in = new FileInputStream(file); ZipEntry fileEntry = new ZipEntry(path); jos.putNextEntry(fileEntry); // Transfer bytes from the file to the ZIP file int len; while ((len = in.read(buf)) > 0) { jos.write(buf, 0, len); } // Complete the entry jos.closeEntry(); } finally { IOUtils.closeQuietly(in); } }
From source file:JarHelper.java
/** * Recursively jars up the given path under the given directory. */// w ww .j a va2 s . c om private void jarDir(File dirOrFile2jar, JarOutputStream jos, String path) throws IOException { if (mVerbose) System.out.println("checking " + dirOrFile2jar); if (dirOrFile2jar.isDirectory()) { String[] dirList = dirOrFile2jar.list(); String subPath = (path == null) ? "" : (path + dirOrFile2jar.getName() + SEP); if (path != null) { JarEntry je = new JarEntry(subPath); je.setTime(dirOrFile2jar.lastModified()); jos.putNextEntry(je); jos.flush(); jos.closeEntry(); } for (int i = 0; i < dirList.length; i++) { File f = new File(dirOrFile2jar, dirList[i]); jarDir(f, jos, subPath); } } else { if (dirOrFile2jar.getCanonicalPath().equals(mDestJarName)) { if (mVerbose) System.out.println("skipping " + dirOrFile2jar.getPath()); return; } if (mVerbose) System.out.println("adding " + dirOrFile2jar.getPath()); FileInputStream fis = new FileInputStream(dirOrFile2jar); try { JarEntry entry = new JarEntry(path + dirOrFile2jar.getName()); entry.setTime(dirOrFile2jar.lastModified()); jos.putNextEntry(entry); while ((mByteCount = fis.read(mBuffer)) != -1) { jos.write(mBuffer, 0, mByteCount); if (mVerbose) System.out.println("wrote " + mByteCount + " bytes"); } jos.flush(); jos.closeEntry(); } catch (IOException ioe) { throw ioe; } finally { fis.close(); } } }
From source file:org.infoglue.deliver.portal.deploy.Deploy.java
/** * Prepare a portlet according to Pluto (switch web.xml) * /*from w ww . j a va2 s . c o m*/ * @param file .war to prepare * @param tmp the resulting updated .war * @param appName name of application (context name) * @return the portlet application definition (portlet.xml) * @throws IOException */ public static PortletApplicationDefinition prepareArchive(File file, File tmp, String appName) throws IOException { PortletApplicationDefinitionImpl portletApp = null; try { Mapping pdmXml = new Mapping(); try { URL url = Deploy.class.getResource("/" + PORTLET_MAPPING); pdmXml.loadMapping(url); } catch (Exception e) { throw new IOException("Failed to load mapping file " + PORTLET_MAPPING); } // Open the jar file. JarFile jar = new JarFile(file); // Extract and parse portlet.xml ZipEntry portletEntry = jar.getEntry(PORTLET_XML); if (portletEntry == null) { throw new IOException("Unable to find portlet.xml"); } InputStream pisDebug = jar.getInputStream(portletEntry); StringBuffer sb = new StringBuffer(); int i; while ((i = pisDebug.read()) > -1) { sb.append((char) i); } pisDebug.close(); InputSource xmlSource = new InputSource(new ByteArrayInputStream(sb.toString().getBytes("UTF-8"))); DOMParser parser = new DOMParser(); parser.parse(xmlSource); Document portletDocument = parser.getDocument(); //InputStream pis = jar.getInputStream(portletEntry); //Document portletDocument = XmlParser.parsePortletXml(pis); //pis.close(); InputStream pis = jar.getInputStream(portletEntry); ZipEntry webEntry = jar.getEntry(WEB_XML); InputStream wis = null; if (webEntry != null) { wis = jar.getInputStream(webEntry); /* webDocument = XmlParser.parseWebXml(wis); wis.close(); */ } Unmarshaller unmarshaller = new Unmarshaller(pdmXml); unmarshaller.setWhitespacePreserve(true); unmarshaller.setIgnoreExtraElements(true); unmarshaller.setIgnoreExtraAttributes(true); portletApp = (PortletApplicationDefinitionImpl) unmarshaller.unmarshal(portletDocument); // refill structure with necessary information Vector structure = new Vector(); structure.add(appName); structure.add(null); structure.add(null); portletApp.preBuild(structure); /* // now generate web part WebApplicationDefinitionImpl webApp = null; if (webDocument != null) { Unmarshaller unmarshallerWeb = new Unmarshaller(sdmXml); // modified by YCLI: START :: to ignore extra elements and // attributes unmarshallerWeb.setWhitespacePreserve(true); unmarshallerWeb.setIgnoreExtraElements(true); unmarshallerWeb.setIgnoreExtraAttributes(true); // modified by YCLI: END webApp = (WebApplicationDefinitionImpl) unmarshallerWeb.unmarshal(webDocument); } else { webApp = new WebApplicationDefinitionImpl(); DisplayNameImpl dispName = new DisplayNameImpl(); dispName.setDisplayName(appName); dispName.setLocale(Locale.ENGLISH); DisplayNameSetImpl dispSet = new DisplayNameSetImpl(); dispSet.add(dispName); webApp.setDisplayNames(dispSet); DescriptionImpl desc = new DescriptionImpl(); desc.setDescription("Automated generated Application Wrapper"); desc.setLocale(Locale.ENGLISH); DescriptionSetImpl descSet = new DescriptionSetImpl(); descSet.add(desc); webApp.setDescriptions(descSet); } org.apache.pluto.om.ControllerFactory controllerFactory = new org.apache.pluto.portalImpl.om.ControllerFactoryImpl(); ServletDefinitionListCtrl servletDefinitionSetCtrl = (ServletDefinitionListCtrl) controllerFactory .get(webApp.getServletDefinitionList()); Collection servletMappings = webApp.getServletMappings(); Iterator portlets = portletApp.getPortletDefinitionList().iterator(); while (portlets.hasNext()) { PortletDefinition portlet = (PortletDefinition) portlets.next(); // check if already exists ServletDefinition servlet = webApp.getServletDefinitionList() .get(portlet.getName()); if (servlet != null) { ServletDefinitionCtrl _servletCtrl = (ServletDefinitionCtrl) controllerFactory .get(servlet); _servletCtrl.setServletClass("org.apache.pluto.core.PortletServlet"); } else { servlet = servletDefinitionSetCtrl.add(portlet.getName(), "org.apache.pluto.core.PortletServlet"); } ServletDefinitionCtrl servletCtrl = (ServletDefinitionCtrl) controllerFactory .get(servlet); DisplayNameImpl dispName = new DisplayNameImpl(); dispName.setDisplayName(portlet.getName() + " Wrapper"); dispName.setLocale(Locale.ENGLISH); DisplayNameSetImpl dispSet = new DisplayNameSetImpl(); dispSet.add(dispName); servletCtrl.setDisplayNames(dispSet); DescriptionImpl desc = new DescriptionImpl(); desc.setDescription("Automated generated Portlet Wrapper"); desc.setLocale(Locale.ENGLISH); DescriptionSetImpl descSet = new DescriptionSetImpl(); descSet.add(desc); servletCtrl.setDescriptions(descSet); ParameterSet parameters = servlet.getInitParameterSet(); ParameterSetCtrl parameterSetCtrl = (ParameterSetCtrl) controllerFactory .get(parameters); Parameter parameter1 = parameters.get("portlet-class"); if (parameter1 == null) { parameterSetCtrl.add("portlet-class", portlet.getClassName()); } else { ParameterCtrl parameterCtrl = (ParameterCtrl) controllerFactory.get(parameter1); parameterCtrl.setValue(portlet.getClassName()); } Parameter parameter2 = parameters.get("portlet-guid"); if (parameter2 == null) { parameterSetCtrl.add("portlet-guid", portlet.getId().toString()); } else { ParameterCtrl parameterCtrl = (ParameterCtrl) controllerFactory.get(parameter2); parameterCtrl.setValue(portlet.getId().toString()); } boolean found = false; Iterator mappings = servletMappings.iterator(); while (mappings.hasNext()) { ServletMappingImpl servletMapping = (ServletMappingImpl) mappings.next(); if (servletMapping.getServletName().equals(portlet.getName())) { found = true; servletMapping.setUrlPattern("/" + portlet.getName().replace(' ', '_') + "/*"); } } if (!found) { ServletMappingImpl servletMapping = new ServletMappingImpl(); servletMapping.setServletName(portlet.getName()); servletMapping.setUrlPattern("/" + portlet.getName().replace(' ', '_') + "/*"); servletMappings.add(servletMapping); } SecurityRoleRefSet servletSecurityRoleRefs = ((ServletDefinitionImpl) servlet) .getInitSecurityRoleRefSet(); SecurityRoleRefSetCtrl servletSecurityRoleRefSetCtrl = (SecurityRoleRefSetCtrl) controllerFactory .get(servletSecurityRoleRefs); SecurityRoleSet webAppSecurityRoles = webApp.getSecurityRoles(); SecurityRoleRefSet portletSecurityRoleRefs = portlet.getInitSecurityRoleRefSet(); Iterator p = portletSecurityRoleRefs.iterator(); while (p.hasNext()) { SecurityRoleRef portletSecurityRoleRef = (SecurityRoleRef) p.next(); if (portletSecurityRoleRef.getRoleLink() == null && webAppSecurityRoles.get(portletSecurityRoleRef.getRoleName()) == null) { logger.info("Note: The web application has no security role defined which matches the role name \"" + portletSecurityRoleRef.getRoleName() + "\" of the security-role-ref element defined for the wrapper-servlet with the name '" + portlet.getName() + "'."); break; } SecurityRoleRef servletSecurityRoleRef = servletSecurityRoleRefs .get(portletSecurityRoleRef.getRoleName()); if (null != servletSecurityRoleRef) { logger.info("Note: Replaced already existing element of type <security-role-ref> with value \"" + portletSecurityRoleRef.getRoleName() + "\" for subelement of type <role-name> for the wrapper-servlet with the name '" + portlet.getName() + "'."); servletSecurityRoleRefSetCtrl.remove(servletSecurityRoleRef); } servletSecurityRoleRefSetCtrl.add(portletSecurityRoleRef); } } */ /* * TODO is this necessary? TagDefinitionImpl portletTagLib = new * TagDefinitionImpl(); Collection taglibs = * webApp.getCastorTagDefinitions(); taglibs.add(portletTagLib); */ // Duplicate jar-file with replaced web.xml FileOutputStream fos = new FileOutputStream(tmp); JarOutputStream tempJar = new JarOutputStream(fos); byte[] buffer = new byte[1024]; int bytesRead; for (Enumeration entries = jar.entries(); entries.hasMoreElements();) { JarEntry entry = (JarEntry) entries.nextElement(); JarEntry newEntry = new JarEntry(entry.getName()); tempJar.putNextEntry(newEntry); if (entry.getName().equals(WEB_XML)) { // Swap web.xml /* log.debug("Swapping web.xml"); OutputFormat of = new OutputFormat(); of.setIndenting(true); of.setIndent(4); // 2-space indention of.setLineWidth(16384); of.setDoctype(Constants.WEB_PORTLET_PUBLIC_ID, Constants.WEB_PORTLET_DTD); XMLSerializer serializer = new XMLSerializer(tempJar, of); Marshaller marshaller = new Marshaller(serializer.asDocumentHandler()); marshaller.setMapping(sdmXml); marshaller.marshal(webApp); */ PortletAppDescriptorService portletAppDescriptorService = new StreamPortletAppDescriptorServiceImpl( appName, pis, null); File tmpf = File.createTempFile("infoglue-web-xml", null); WebAppDescriptorService webAppDescriptorService = new StreamWebAppDescriptorServiceImpl(appName, wis, new FileOutputStream(tmpf)); org.apache.pluto.driver.deploy.Deploy d = new org.apache.pluto.driver.deploy.Deploy( webAppDescriptorService, portletAppDescriptorService); d.updateDescriptors(); FileInputStream fis = new FileInputStream(tmpf); while ((bytesRead = fis.read(buffer)) != -1) { tempJar.write(buffer, 0, bytesRead); } tmpf.delete(); } else { InputStream entryStream = jar.getInputStream(entry); if (entryStream != null) { while ((bytesRead = entryStream.read(buffer)) != -1) { tempJar.write(buffer, 0, bytesRead); } } } } tempJar.flush(); tempJar.close(); fos.flush(); fos.close(); /* * String strTo = dirDelim + "WEB-INF" + dirDelim + "tld" + dirDelim + * "portlet.tld"; String strFrom = "webapps" + dirDelim + strTo; * * copy(strFrom, webAppsDir + webModule + strTo); */ } catch (Exception e) { log.error("Failed to prepare archive", e); throw new IOException(e.getMessage()); } return portletApp; }
From source file:gov.nih.nci.restgen.util.JarHelper.java
/** * Recursively jars up the given path under the given directory. *//*from ww w .jav a 2s . c o m*/ private void jarDir(File dirOrFile2jar, JarOutputStream jos, String path) throws IOException { //if (mVerbose) { //System.out.println("checking " + dirOrFile2jar); } if (dirOrFile2jar.isDirectory()) { String[] dirList = dirOrFile2jar.list(); String subPath = (path == null) ? "" : (path + dirOrFile2jar.getName() + SEP); if (path != null) { JarEntry je = new JarEntry(subPath); je.setTime(dirOrFile2jar.lastModified()); jos.putNextEntry(je); jos.flush(); jos.closeEntry(); } for (int i = 0; i < dirList.length; i++) { File f = new File(dirOrFile2jar, dirList[i]); jarDir(f, jos, subPath); } } else { if (dirOrFile2jar.getCanonicalPath().equals(mDestJarName)) { //if (mVerbose) { //System.out.println("skipping " + dirOrFile2jar.getPath()); } return; } if (mVerbose) { //System.out.println("adding " + dirOrFile2jar.getPath()); } FileInputStream fis = new FileInputStream(dirOrFile2jar); try { JarEntry entry = new JarEntry(path + dirOrFile2jar.getName()); entry.setTime(dirOrFile2jar.lastModified()); jos.putNextEntry(entry); while ((mByteCount = fis.read(mBuffer)) != -1) { jos.write(mBuffer, 0, mByteCount); if (mVerbose) { //System.out.println("wrote " + mByteCount + " bytes"); } } jos.flush(); jos.closeEntry(); } catch (IOException ioe) { throw ioe; } finally { fis.close(); } } }
From source file:org.apache.hadoop.mapreduce.v2.TestMRJobs.java
private void createAndAddJarToJar(JarOutputStream jos, File jarFile) throws FileNotFoundException, IOException { FileOutputStream fos2 = new FileOutputStream(jarFile); JarOutputStream jos2 = new JarOutputStream(fos2); // Have to have at least one entry or it will complain ZipEntry ze = new ZipEntry("lib1.inside"); jos2.putNextEntry(ze);/* w w w . ja v a 2s . c o m*/ jos2.closeEntry(); jos2.close(); ze = new ZipEntry("lib/" + jarFile.getName()); jos.putNextEntry(ze); FileInputStream in = new FileInputStream(jarFile); byte buf[] = new byte[1024]; int numRead; do { numRead = in.read(buf); if (numRead >= 0) { jos.write(buf, 0, numRead); } } while (numRead != -1); in.close(); jos.closeEntry(); jarFile.delete(); }
From source file:net.sf.keystore_explorer.crypto.signing.JarSigner.java
private static void writeJarEntries(JarFile jar, JarOutputStream jos, String signatureName) throws IOException { for (Enumeration<?> jarEntries = jar.entries(); jarEntries.hasMoreElements();) { JarEntry jarEntry = (JarEntry) jarEntries.nextElement(); if (!jarEntry.isDirectory()) { String entryName = jarEntry.getName(); // Signature files not to write across String sigFileLocation = MessageFormat.format(METAINF_FILE_LOCATION, signatureName, SIGNATURE_EXT) .toUpperCase();//w ww . jav a2 s .c om String dsaSigBlockLocation = MessageFormat.format(METAINF_FILE_LOCATION, signatureName, DSA_SIG_BLOCK_EXT); String rsaSigBlockLocation = MessageFormat.format(METAINF_FILE_LOCATION, signatureName, RSA_SIG_BLOCK_EXT); // Do not write across existing manifest or matching signature files if ((!entryName.equalsIgnoreCase(MANIFEST_LOCATION)) && (!entryName.equalsIgnoreCase(sigFileLocation)) && (!entryName.equalsIgnoreCase(dsaSigBlockLocation)) && (!entryName.equalsIgnoreCase(rsaSigBlockLocation))) { // New JAR entry based on original JarEntry newJarEntry = new JarEntry(jarEntry.getName()); newJarEntry.setMethod(jarEntry.getMethod()); newJarEntry.setCompressedSize(jarEntry.getCompressedSize()); newJarEntry.setCrc(jarEntry.getCrc()); jos.putNextEntry(newJarEntry); InputStream jis = null; try { jis = jar.getInputStream(jarEntry); byte[] buffer = new byte[2048]; int read = -1; while ((read = jis.read(buffer)) != -1) { jos.write(buffer, 0, read); } jos.closeEntry(); } finally { IOUtils.closeQuietly(jis); } } } } }
From source file:rita.widget.SourceCode.java
private void createCompileButton() { ImageIcon imgIcon = new ImageIcon(getClass().getResource("/images/sourcecode/bytecode.png")); this.compileButton = new JButton(imgIcon); this.compileButton.setToolTipText(Language.get("compileButton.tooltip")); final File basePathRobots = new File(Settings.getRobotsPath()); compileButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { // guardar el codigo fuente File sourcePath = saveSourceCode(); // COMPILA EN EL DIRECTORIO POR DEFAULT + LA RUTA DEL PACKAGE Collection<File> inFiles = createClassFiles(sourcePath); if (inFiles != null) { /* transformar el codigo fuente, que no tiene errores, para que los println aparezcan en una ventana. * La transformacin no deberia generar errores. *//*from www. j av a 2 s .co m*/ writeSourceFile(sourcePath, AgregadorDeConsola.getInstance().transformar(readSourceFile(sourcePath))); // volver a compilar, ahora con el codigo transformado inFiles = createClassFiles(sourcePath); if (inFiles != null) { createJarFile(inFiles); System.out.println("INSTALLPATH=" + Settings.getInstallPath()); System.out.println("SE ENVIA ROBOT:" + HelperEditor.currentRobotPackage + "." + HelperEditor.currentRobotName); // si quiere seleccionar enemigos if (Settings.getProperty("level.default").equals(Language.get("level.four"))) { try { DialogSelectEnemies.getInstance(); } catch (NoEnemiesException e2) { new MessageDialog(Language.get("robot.noEnemies"), MessageType.ERROR); } return; } else { callBatalla(null, null); } } else { System.out.println("Error en codigo transformado por AgregadorDeConsola"); } } } catch (Exception e1) { e1.printStackTrace(); } } /** Recibe un archivo conteniendo codigo fuente java, y crea el .class correspondiente * @param sourcePath El archivo .java * @return Un archivo conteniendo el path al .class generado, o null si no fue posible compilar porque hubo errores en el codigo fuente. */ private Collection<File> createClassFiles(File sourcePath) throws Exception, IOException { Collection<File> f = CompileString.compile(sourcePath, basePathRobots); if (CompileString.hasError()) { int cantErrores = 0; for (Diagnostic<?> diag : CompileString.diagnostics) { if (!diag.getKind().equals(Kind.WARNING)) { int line = (int) diag.getLineNumber(); int col = (int) diag.getColumnNumber(); if (line > 0 && col > 0) { highlightCode(line, col); cantErrores++; } } } if (cantErrores > 0) { new MessageDialog(Language.get("compile.error"), MessageType.ERROR); } return null; } else { return f; } } /* crea un jar con todas las clases del robot. el nombre del jar es el nombre del robot */ private void createJarFile(Collection<File> inFiles) throws FileNotFoundException, IOException { File jarFile = new File(basePathRobots, HelperEditor.currentRobotName + ".jar"); if (jarFile.exists()) { jarFile.delete(); } System.out.println("Path del JAR ==" + jarFile); jarFile.createNewFile(); FileOutputStream fos = new FileOutputStream(jarFile); BufferedOutputStream bo = new BufferedOutputStream(fos); Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); JarOutputStream jarOutput = new JarOutputStream(fos, manifest); int basePathLength = basePathRobots.getAbsolutePath().length() + 1; // +1 para incluir al "/" final byte[] buf = new byte[1024]; int anz; try { // para todas las clases... for (File inFile : inFiles) { BufferedInputStream bi = new BufferedInputStream(new FileInputStream(inFile)); try { String relative = inFile.getAbsolutePath().substring(basePathLength); // copia y agrega el archivo .class al jar JarEntry je2 = new JarEntry(relative); jarOutput.putNextEntry(je2); while ((anz = bi.read(buf)) != -1) { jarOutput.write(buf, 0, anz); } jarOutput.closeEntry(); } finally { try { bi.close(); } catch (IOException ignored) { } } } } finally { try { jarOutput.close(); } catch (IOException ignored) { } try { fos.close(); } catch (IOException ignored) { } try { bo.close(); } catch (IOException ignored) { } } } }); compileButton.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @Override public void mouseExited(MouseEvent e) { e.getComponent().setCursor(Cursor.getDefaultCursor()); } }); compileButton.setBounds(MIN_WIDTH, 0, MAX_WIDTH - MIN_WIDTH, BUTTON_HEIGHT); compileButton.setFont(smallButtonFont); compileButton.setAlignmentX(LEFT_ALIGNMENT); compileButton.setText(Language.get("compileButton.title")); }
From source file:org.apache.oozie.action.hadoop.TestMapReduceActionExecutor.java
private void createAndAddJarToJar(JarOutputStream jos, File jarFile) throws Exception { FileOutputStream fos2 = new FileOutputStream(jarFile); JarOutputStream jos2 = new JarOutputStream(fos2); // Have to have at least one entry or it will complain ZipEntry ze = new ZipEntry(jarFile.getName() + ".inside"); jos2.putNextEntry(ze);/*from w ww .ja v a2s. co m*/ jos2.closeEntry(); jos2.close(); ze = new ZipEntry("lib/" + jarFile.getName()); jos.putNextEntry(ze); FileInputStream in = new FileInputStream(jarFile); byte buf[] = new byte[1024]; int numRead; do { numRead = in.read(buf); if (numRead >= 0) { jos.write(buf, 0, numRead); } } while (numRead != -1); in.close(); jos.closeEntry(); jarFile.delete(); }
From source file:com.taobao.android.tools.TPatchTool.java
/** * Adds a directory to a {@link} with a directory prefix. * * @param jos ZipArchiver to use to archive the file. * @param directory The directory to add. * @param prefix An optional prefix for where in the Jar file the directory's contents should go. */// w w w.j a va2 s . c om protected void addDirectory(JarOutputStream jos, File directory, String prefix) throws IOException { if (directory != null && directory.exists()) { Collection<File> files = FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); byte[] buf = new byte[8064]; for (File file : files) { if (file.isDirectory()) { continue; } String path = prefix + "/" + PathUtils.toRelative(directory, file.getAbsolutePath()); InputStream in = null; try { in = new FileInputStream(file); ZipEntry fileEntry = new ZipEntry(path); jos.putNextEntry(fileEntry); // Transfer bytes from the file to the ZIP file int len; while ((len = in.read(buf)) > 0) { jos.write(buf, 0, len); } // Complete the entry jos.closeEntry(); in.close(); } finally { IOUtils.closeQuietly(in); } } } }
From source file:lu.fisch.moenagade.model.Project.java
public void jar() { try {//from w ww. j a v a2 s . c o m // compile all if (!save()) return; generateSource(true); if (compile()) { // adjust the dirname String bdir = getDirectoryName(); if (!bdir.endsWith(System.getProperty("file.separator"))) { bdir += System.getProperty("file.separator"); } // adjust the filename String bname = getDirectoryName(); if (bname.endsWith(System.getProperty("file.separator"))) { bname = bname.substring(0, bname.length() - 1); } bname = bname.substring(bname.lastIndexOf(System.getProperty("file.separator")) + 1); // default class to launch String mc = "moenagade.Project"; // target JVM String target = "1.8"; /* String[] targets = new String[]{"1.1","1.2","1.3","1.5","1.6"}; if(System.getProperty("java.version").startsWith("1.7")) targets = new String[]{"1.1","1.2","1.3","1.5","1.6","1.7"}; if(System.getProperty("java.version").startsWith("1.8")) targets = new String[]{"1.1","1.2","1.3","1.5","1.6","1.7","1.8"}; target= (String) JOptionPane.showInputDialog( frame, "Please enter version of the JVM you want to target.", "Target JVM", JOptionPane.QUESTION_MESSAGE, Moenagade.IMG_QUESTION, targets, "1.6");*/ File fDir = new File(directoryName + System.getProperty("file.separator") + "bin"); if (!fDir.exists()) fDir.mkdir(); // get all the files content Hashtable<String, String> codes = new Hashtable<>(); String srcdir = directoryName + System.getProperty("file.separator") + "src"; Collection files = FileUtils.listFiles(new File(srcdir), new String[] { "java" }, true); File[] javas = new File[files.size()]; int i = 0; for (Iterator iterator = files.iterator(); iterator.hasNext();) { File file = (File) iterator.next(); javas[i++] = file; } try { // make class files Runtime6.getInstance().compileToPath(javas, fDir.getAbsolutePath(), target, ""); StringList manifest = new StringList(); manifest.add("Manifest-Version: 1.0"); manifest.add("Created-By: " + Moenagade.E_VERSION + " " + Moenagade.E_VERSION); manifest.add("Name: " + bname); if (mc != null) { manifest.add("Main-Class: " + mc); } // compose the filename fDir = new File(bdir + "dist" + System.getProperty("file.separator")); fDir.mkdir(); bname = bdir + "dist" + System.getProperty("file.separator") + bname + ".jar"; String baseName = bdir; String libFolderName = bdir + "lib"; String distLibFolderName = bdir + "dist" + System.getProperty("file.separator") + "lib"; File outFile = new File(bname); FileOutputStream bo = new FileOutputStream(bname); JarOutputStream jo = new JarOutputStream(bo); String dirname = getDirectoryName(); if (!dirname.endsWith(System.getProperty("file.separator"))) { dirname += System.getProperty("file.separator"); } // add the files to the array addToJar(jo, "", new File(dirname + "bin" + System.getProperty("file.separator"))); // add the files to the array addToJar(jo, "", new File(dirname + "src" + System.getProperty("file.separator")), new String[] { "java" }); //manifest.add("Class-Path: "+cp+" "+cpsw); // adding the manifest file manifest.add(""); JarEntry je = new JarEntry("META-INF/MANIFEST.MF"); jo.putNextEntry(je); String mf = manifest.getText(); jo.write(mf.getBytes(), 0, mf.getBytes().length); jo.close(); bo.close(); // delete bin directory deleteDirectory(new File(getDirectoryName() + System.getProperty("file.separator") + "bin" + System.getProperty("file.separator"))); // generate java code with dispose_on_exit generateSource(); JOptionPane.showMessageDialog(frame, "The JAR-archive has been generated and can\nbe found in the \"dist\" directory.", "Success", JOptionPane.INFORMATION_MESSAGE, Moenagade.IMG_INFO); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } } } /*catch (ClassNotFoundException ex) { JOptionPane.showMessageDialog(frame, "There was an error while creating the JAR-archive ...", "Error :: ClassNotFoundException", JOptionPane.ERROR_MESSAGE,Unimozer.IMG_ERROR); }*/ catch (IOException ex) { JOptionPane.showMessageDialog(frame, "There was an error while creating the JAR-archive ...", "Error :: IOException", JOptionPane.ERROR_MESSAGE, Moenagade.IMG_ERROR); ex.printStackTrace(); } }