简体   繁体   中英

Java application won't start after exporting

Noob here.

Using Eclipse to try and program a cost calculator.

Source code:

import java.util.Scanner;


public class Costtransport {

    public static void main(String[] args) {
        double ctotal;
        double ctransp;
        double cpers;
        double persvar1;
        double persvar2;


        Scanner keyboard = new Scanner(System.in);

        System.out.println("Care este costul total al comenzii, excluzand transportul");
        ctotal = keyboard.nextInt();
        System.out.println("Care este costul transportului?");
        ctransp = keyboard.nextInt();
        System.out.println("Care este valoarea produselor cumparate de individul pentru care se calculeaza taxa de transport?");
        cpers = keyboard.nextInt();
        persvar1 = cpers / ctotal;
        persvar2 = ctransp * persvar1;
        System.out.print("Persoana respectiva trebuie sa plateasca ");
        System.out.print(persvar2);
        System.out.println( " lei.");

        keyboard.close();
        }


    }

If I try to run it in Eclipse, it runs fine. However, if I try to export it, it won't start.

Tried exporting it as "runnable JAR file" and as "JAR file". I've been reading about some manifest file, but the latter option should generate it apparently.

Any help please?

Thank you.

If you create an executable jar , you're gonna wanna use it mainly for GUI applications ( Swing, FX.. ).

Remember that the jar will not start the console on its own !

You can either create your own, or run the jar from terminal, so that the output can be displayed.

java -jar <yourfile>

If you want the console at all costs, make one with a black JPanel and a JTextArea .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM