Note that there are some explanatory texts on larger screens.

plurals
  1. POJar does not run on command line
    primarykey
    data
    text
    <p>I did search through google and various forums, (this one as well).</p> <p>I have created an application, a java benchmark, and wanted to create a runnable jar file, to use the program on other machines. Unfortunately, the jar is not working, everything is done perfect with the code to make jar file, the program runs on command line. I tried tricks found on this forum to fix my jar creation, but it didn't work as well.</p> <p>Strangely enough, when i compile the JavaBenchmark.java file i do not get only one file (JavaBenchmark.class), but also JavaBenchmark$1.class :O (anyone knows why?)</p> <p>So I ask you to check my code if THERE might be some problems, I must say its a GUI app.</p> <pre><code>import java.io.*; import java.util.Date; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JavaBenchmark implements ActionListener { private Frame mainWindow; private Button exit; private String dateAndTime; private TextArea values; private String stringMaxMemory; private String stringFreeMemory; private String stringTotalFreeMemory; private String stringAllocatedMemory; public JavaBenchmark(String s) { Date myDate = new Date(); dateAndTime = String.format("%tA, %&lt;tF", myDate); File[] roots = File.listRoots(); mainWindow = new Frame(s); mainWindow.setSize(640,480); mainWindow.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent we){System.exit(0);}}); String version = System.getProperty("java.version"); String jvmversion = System.getProperty("java.jvm.version"); String checkedJvmVersion; if (jvmversion == null) { checkedJvmVersion = "Java Virtual Machine version: N/A"; } else { checkedJvmVersion = "Java Virtual Machine version: " + jvmversion; } String jvmname = System.getProperty("java.vm.name"); String osname = System.getProperty("os.name"); String osarchitecture = System.getProperty("os.arch"); String osversion = System.getProperty("os.version"); String processor = System.getenv("PROCESSOR_IDENTIFIER"); int processorCores = Runtime.getRuntime().availableProcessors(); Runtime runtime = Runtime.getRuntime(); double freeMemory = runtime.freeMemory(); double allocatedMemory = runtime.totalMemory(); double maxMemory = runtime.maxMemory(); double totalFreeMemory = (freeMemory + (maxMemory - allocatedMemory)); stringFreeMemory = String.format("%5.2f", (freeMemory)/1024/1024); stringAllocatedMemory = String.format("%5.2f", (allocatedMemory)/1024/1024); stringMaxMemory = String.format("%5.2f", (maxMemory)/1024/1024); stringTotalFreeMemory = String.format("%5.2f", (totalFreeMemory)/1024/1024); exit = new Button("Exit"); exit.addActionListener(this); values = new TextArea(30, 120); Panel exitButton = new Panel(); exitButton.add(exit); mainWindow.add(values, "North"); mainWindow.add(exitButton); values.append("Your Java benchmark, as on: " + dateAndTime + "\n\n"); values.append("Java version: " + version + "\n"); values.append("Java Virtual machine version: " + checkedJvmVersion + "\n"); values.append("Java Virtual Machine name: " + jvmname + "\n"); values.append("\n"); values.append("Operating System: " + osname + "\n" + osarchitecture + " os version: " + osversion + "\n"); values.append("\n"); values.append("Processor: " + processor + " (number of cores: " + processorCores + ")\n"); values.append("\n"); values.append("Memory info: \n"); values.append("Maximum RAM memory for JVM: " + stringMaxMemory + " Mb\n"); values.append("Allocated RAM memory for JVM: " + stringAllocatedMemory + " Mb\n"); values.append("Free RAM memory for JVM: " + stringFreeMemory + " Mb\n"); values.append("Total free RAM memory for JVM: " + stringTotalFreeMemory + " Mb\n\n\n"); values.append("HardDrive, and VirtualDrive details:\n"); for (File root : roots) { if (root.getTotalSpace() == 0) { continue; } else { values.append("Disk: " + root.getAbsolutePath() + " space allocation:\n"); values.append("Total space :"); values.append(String.format("%5.2f", Double.valueOf(root.getTotalSpace())/1024/1024/1024)); values.append(" Gb\n"); values.append("Free space : "); values.append(String.format("%5.2f", Double.valueOf(root.getFreeSpace())/1024/1024/1024)); values.append(" Gb\n"); values.append("Occupied disk space : "); values.append(String.format("%5.2f", Double.valueOf(root.getTotalSpace() - root.getFreeSpace())/1024/1024/1024)); values.append(" Gb\n\n"); } } mainWindow.pack(); //Creating the window mainWindow.setLocationRelativeTo(null); //true: position at (0,0) false: position at center mainWindow.setResizable(false); //Intuitively known commands mainWindow.setVisible(true); //Intuitively known commands } public static void main(String[] args) { new JavaBenchmark("Display"); } public void actionPerformed(ActionEvent e) { if(e.getSource()==exit) { System.exit(0); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload