D
Darren
i'm invoking to use Java's 'exec' but the documentation says its in the
java.lang.runtime class.. i import it as well as java.lang.process but the
when i compile the programme that calls it i get a "cannot resolve symbol"
on the "exec" line. which is 'exec(JarSignerPath);'
The code for this class alone is below;
package uk.me.g7wap.jarmaker;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.lang.Runtime;
import java.lang.Process;
public class Jarmaker
{
private static String JarSignerPath=null;
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel
");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
ex.printStackTrace();
}
final JFrame w = new JFrame("Desktop Window");
final JDesktopPane desktop = new JDesktopPane();
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu("File");
JMenuItem menuItem = new JMenuItem("New");
JMenuItem menuFileNewJar = new JMenuItem("Create JAR",KeyEvent.VK_J);
JMenuItem menuFileNewZip = new JMenuItem ("Create ZIP",KeyEvent.VK_Z);
JMenuItem menuFileOpenJar = new JMenuItem("Open JAR",KeyEvent.VK_F3);
JMenuItem menuFileOpenZip = new JMenuItem ("Open ZIP",KeyEvent.VK_F3);
JMenuItem menuFileSetRoot = new JMenuItem("Set Root
Dir",KeyEvent.VK_R);
JMenuItem menuFileSignJar =new JMenuItem("Sign Jar",KeyEvent.VK_J);
JMenuItem menuFileExit = new JMenuItem("Exit",KeyEvent.VK_X);
w.setContentPane(desktop);
w.setJMenuBar(menuBar);
menuBar.add(menuFile);
menuFile.add(menuItem);
menuFileNewJar.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J,ActionEve
nt.ALT_MASK));
menuFileNewZip.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,ActionEve
nt.ALT_MASK));
menuFileSetRoot.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,ActionEv
ent.ALT_MASK));
menuFileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
ActionEvent.ALT_MASK));
menuFileExit.getAccessibleContext().setAccessibleDescription("Exit");
menuFile.add(menuFileNewJar);
menuFile.add(menuFileNewZip);
menuFile.add(menuFileOpenJar);
menuFile.add(menuFileOpenZip);
menuFile.add(menuFileSetRoot);
menuFile.add(menuFileSignJar);
menuFile.add(menuFileExit);
menuBar.add(menuFile);
menuItem.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
//-- Create a JarFileFrame --
JarFileFrame JIF = new JarFileFrame("pickles");
desktop.add(JIF);
try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
//---------------------
}
});
menuFileNewZip.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ZipFileFilter myfilter=new ZipFileFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int lnReturnVal = fc.showSaveDialog(w);
ZipFileFrame JIF = new
ZipFileFrame(fc.getSelectedFile().getAbsolutePath(),desktop);
File loJarOutFile = fc.getSelectedFile();
if (loJarOutFile.exists())
{
String title = "New";
JOptionPane loOverwriteConfirm = new JOptionPane();
int lnResult=loOverwriteConfirm.showConfirmDialog(w,"File
exists, overwrite?","File Exists",JOptionPane.YES_NO_OPTION);
if(lnResult==0)
{
desktop.add(JIF);
try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
}
}
else
{
desktop.add(JIF);
try
{
Zip outzip = new
Zip("*.*",loJarOutFile.getCanonicalPath(),"c:\\Applets");
}
catch (java.io.IOException eee)
{
}
try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
}
}
}
);
menuFileOpenZip.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JarFileFilter myfilter=new JarFileFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int lnReturnVal = fc.showOpenDialog(w);
ZipFileFrame JIF = new
ZipFileFrame(fc.getSelectedFile().getAbsolutePath(),desktop);
File loJarOutFile = fc.getSelectedFile();
desktop.add(JIF);
try
{
JIF.openZipFile(loJarOutFile.getCanonicalPath());
}
catch (java.io.IOException eee)
{
}
try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
}
}
);
menuFileSignJar.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (JarSignerPath==null)
{
JarSignerFilter myfilter=new JarSignerFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setDialogTitle("Where is JarSigner?");
int lnReturnVal = fc.showOpenDialog(w);
File loJarSignerFile = fc.getSelectedFile();
JarSignerPath=loJarSignerFile.getAbsolutePath();
}
JarFileFilter myfilter=new JarFileFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setDialogTitle("Jar File to Sign?");
int lnReturnVal = fc.showOpenDialog(w);
File loJarOutFile = fc.getSelectedFile();
exec(JarSignerPath);
}
}
);
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
w.setSize(700,500);
w.setLocation(50,50);
w.setVisible(true);
}
}
java.lang.runtime class.. i import it as well as java.lang.process but the
when i compile the programme that calls it i get a "cannot resolve symbol"
on the "exec" line. which is 'exec(JarSignerPath);'
The code for this class alone is below;
package uk.me.g7wap.jarmaker;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.lang.Runtime;
import java.lang.Process;
public class Jarmaker
{
private static String JarSignerPath=null;
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel
");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
ex.printStackTrace();
}
final JFrame w = new JFrame("Desktop Window");
final JDesktopPane desktop = new JDesktopPane();
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu("File");
JMenuItem menuItem = new JMenuItem("New");
JMenuItem menuFileNewJar = new JMenuItem("Create JAR",KeyEvent.VK_J);
JMenuItem menuFileNewZip = new JMenuItem ("Create ZIP",KeyEvent.VK_Z);
JMenuItem menuFileOpenJar = new JMenuItem("Open JAR",KeyEvent.VK_F3);
JMenuItem menuFileOpenZip = new JMenuItem ("Open ZIP",KeyEvent.VK_F3);
JMenuItem menuFileSetRoot = new JMenuItem("Set Root
Dir",KeyEvent.VK_R);
JMenuItem menuFileSignJar =new JMenuItem("Sign Jar",KeyEvent.VK_J);
JMenuItem menuFileExit = new JMenuItem("Exit",KeyEvent.VK_X);
w.setContentPane(desktop);
w.setJMenuBar(menuBar);
menuBar.add(menuFile);
menuFile.add(menuItem);
menuFileNewJar.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J,ActionEve
nt.ALT_MASK));
menuFileNewZip.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,ActionEve
nt.ALT_MASK));
menuFileSetRoot.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,ActionEv
ent.ALT_MASK));
menuFileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
ActionEvent.ALT_MASK));
menuFileExit.getAccessibleContext().setAccessibleDescription("Exit");
menuFile.add(menuFileNewJar);
menuFile.add(menuFileNewZip);
menuFile.add(menuFileOpenJar);
menuFile.add(menuFileOpenZip);
menuFile.add(menuFileSetRoot);
menuFile.add(menuFileSignJar);
menuFile.add(menuFileExit);
menuBar.add(menuFile);
menuItem.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
//-- Create a JarFileFrame --
JarFileFrame JIF = new JarFileFrame("pickles");
desktop.add(JIF);
try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
//---------------------
}
});
menuFileNewZip.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ZipFileFilter myfilter=new ZipFileFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int lnReturnVal = fc.showSaveDialog(w);
ZipFileFrame JIF = new
ZipFileFrame(fc.getSelectedFile().getAbsolutePath(),desktop);
File loJarOutFile = fc.getSelectedFile();
if (loJarOutFile.exists())
{
String title = "New";
JOptionPane loOverwriteConfirm = new JOptionPane();
int lnResult=loOverwriteConfirm.showConfirmDialog(w,"File
exists, overwrite?","File Exists",JOptionPane.YES_NO_OPTION);
if(lnResult==0)
{
desktop.add(JIF);
try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
}
}
else
{
desktop.add(JIF);
try
{
Zip outzip = new
Zip("*.*",loJarOutFile.getCanonicalPath(),"c:\\Applets");
}
catch (java.io.IOException eee)
{
}
try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
}
}
}
);
menuFileOpenZip.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JarFileFilter myfilter=new JarFileFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int lnReturnVal = fc.showOpenDialog(w);
ZipFileFrame JIF = new
ZipFileFrame(fc.getSelectedFile().getAbsolutePath(),desktop);
File loJarOutFile = fc.getSelectedFile();
desktop.add(JIF);
try
{
JIF.openZipFile(loJarOutFile.getCanonicalPath());
}
catch (java.io.IOException eee)
{
}
try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
}
}
);
menuFileSignJar.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (JarSignerPath==null)
{
JarSignerFilter myfilter=new JarSignerFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setDialogTitle("Where is JarSigner?");
int lnReturnVal = fc.showOpenDialog(w);
File loJarSignerFile = fc.getSelectedFile();
JarSignerPath=loJarSignerFile.getAbsolutePath();
}
JarFileFilter myfilter=new JarFileFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setDialogTitle("Jar File to Sign?");
int lnReturnVal = fc.showOpenDialog(w);
File loJarOutFile = fc.getSelectedFile();
exec(JarSignerPath);
}
}
);
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
w.setSize(700,500);
w.setLocation(50,50);
w.setVisible(true);
}
}