gpt4 book ai didi

java - 尽管从命令提示符下运行完美,但双击后 jar 文件无法打开

转载 作者:行者123 更新时间:2023-11-29 09:32:02 26 4
gpt4 key购买 nike

我正在尝试创建我的项目的可执行文件。我已经创建了我的应用程序的 .jar 文件。

当我双击这个 jar 文件时,它没有打开。当我使用

从命令提示符运行 jar 文件时,它成功运行
java -jar app.jar

可能是什么原因?这是我的源代码:

package app;

import java.awt.Color;


public class MainApplication extends JFrame {

/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainApplication frame = new MainApplication();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public MainApplication() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(130, 20, 1100, 700);
contentPane = new JPanel();
contentPane.setBackground(Color.WHITE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

ImageIcon F1Icon = new ImageIcon("C:\\Users\\Bruce\\workspace\\OSTNashik\\src\\app\\F1.jpg");
JLabel labelImage = new JLabel("");
labelImage.setBounds(381, 11, 230, 161);
contentPane.add(labelImage);
Image image = F1Icon.getImage(); // transform it
Image newimg = image.getScaledInstance(230, 190, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
F1Icon = new ImageIcon(newimg);
labelImage.setIcon(F1Icon);

ImageIcon osTechIcon = new ImageIcon("C:\\Users\\Bruce\\workspace\\OSTNashik\\src\\app\\a.gif");
JLabel osTechLabel = new JLabel("");
osTechLabel.setBounds(22, 11, 230, 111);
contentPane.add(osTechLabel);
Image image1 = osTechIcon.getImage(); // transform it
Image newimg1 = image1.getScaledInstance(230, 130, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
osTechIcon = new ImageIcon(newimg1);
osTechLabel.setIcon(osTechIcon);

ImageIcon ninedotIcon = new ImageIcon("C:\\Users\\Bruce\\workspace\\OSTNashik\\src\\app\\ninedots.jpg");
JLabel nineDotLabel = new JLabel("");
nineDotLabel.setBounds(826, 11, 248, 111);
contentPane.add(nineDotLabel);
Image image2 = ninedotIcon.getImage(); // transform it
Image newimg2 = image2.getScaledInstance(230, 110, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
ninedotIcon = new ImageIcon(newimg2);
nineDotLabel.setIcon(ninedotIcon);

JPanel panel = new JPanel();
panel.setBackground(Color.CYAN);
panel.setBounds(25, 200, 512, 439);
contentPane.add(panel);
panel.setLayout(null);

JButton btnLogANew = new JButton("Log New Call ");
btnLogANew.setBounds(10, 84, 220, 23);
panel.add(btnLogANew);

JButton btnViewOpenCalls = new JButton("View Open Calls");
btnViewOpenCalls.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
OpenCallSummary frame = new OpenCallSummary();
frame.setVisible(true);
}
});
btnViewOpenCalls.setBounds(10, 132, 220, 23);
panel.add(btnViewOpenCalls);

JButton btnEnggDesk = new JButton("View Engineer Desk Calls");
btnEnggDesk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EnggDeskCallSummary frame = new EnggDeskCallSummary();
frame.setVisible(true);
}
});
btnEnggDesk.setBounds(10, 178, 220, 23);
panel.add(btnEnggDesk);

JLabel lblServiceCenterRelated = new JLabel("Service Center Related Tasks");
lblServiceCenterRelated.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 16));
lblServiceCenterRelated.setBounds(138, 25, 212, 23);
panel.add(lblServiceCenterRelated);

JButton closedCalls = new JButton("View Closed Calls");
closedCalls.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ClosedCallSummary cc=new ClosedCallSummary();
cc.setVisible(true);
}
});
closedCalls.setBounds(10, 271, 220, 23);
panel.add(closedCalls);

JButton btnViewEdmaCalls = new JButton("View EDMA Calls");
btnViewEdmaCalls.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EDMACallSummary ed=new EDMACallSummary();
ed.setVisible(true);
}
});
btnViewEdmaCalls.setBounds(10, 225, 220, 23);
panel.add(btnViewEdmaCalls);

JPanel panel_2 = new JPanel();
panel_2.setBackground(SystemColor.inactiveCaptionText);
panel_2.setBounds(251, 89, 251, 99);
panel.add(panel_2);
panel_2.setLayout(null);

JButton btnTravelPending = new JButton("View Pending Travel Approvals");
btnTravelPending.setBounds(10, 21, 220, 23);
panel_2.add(btnTravelPending);

JButton btnViewApprovedTravel = new JButton("View Approved Travel Approvals");
btnViewApprovedTravel.setBounds(10, 55, 220, 23);
panel_2.add(btnViewApprovedTravel);

JPanel panel_3 = new JPanel();
panel_3.setBackground(SystemColor.inactiveCaptionText);
panel_3.setLayout(null);
panel_3.setBounds(251, 199, 251, 99);
panel.add(panel_3);

JButton btnViewMaterialRequired_1 = new JButton("View Material Required Calls");
btnViewMaterialRequired_1.setBounds(10, 21, 220, 23);
panel_3.add(btnViewMaterialRequired_1);

JButton btnViewMaterialApproved = new JButton("View Material Approved Calls");
btnViewMaterialApproved.setBounds(10, 55, 220, 23);
panel_3.add(btnViewMaterialApproved);
btnViewMaterialApproved.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
MaterialApprovedSummary ma=new MaterialApprovedSummary();
ma.setVisible(true);
}
});
btnViewMaterialRequired_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
MaterialRequiredSummary mr=new MaterialRequiredSummary();
mr.setVisible(true);
}
});
btnViewApprovedTravel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ApprovedTravelSummary ats=new ApprovedTravelSummary();
ats.setVisible(true);
}
});
btnTravelPending.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
PendingTravelApprovalSummary ps=new PendingTravelApprovalSummary();
ps.setVisible(true);
}
});

JPanel panel2 = new JPanel();
panel2.setBackground(Color.CYAN);
panel2.setBounds(547, 200, 527, 439);
contentPane.add(panel2);
panel2.setLayout(null);

JLabel lblOtherTasks = new JLabel("Reports");
lblOtherTasks.setBounds(238, 22, 209, 22);
lblOtherTasks.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 16));
panel2.add(lblOtherTasks);

JButton enggwisebtn = new JButton("Engineer Wise Reports");
enggwisebtn.setBounds(48, 127, 181, 23);
panel2.add(enggwisebtn);

JButton opencallbtn = new JButton("Open Calls Reports");
opencallbtn.setBounds(48, 172, 181, 23);
panel2.add(opencallbtn);

JButton closedcallbtn = new JButton("Closed Calls Reports");
closedcallbtn.setBounds(48, 220, 181, 23);
panel2.add(closedcallbtn);

JButton btnOtherCallsReports = new JButton("Other Calls Reports");
btnOtherCallsReports.setBounds(48, 268, 181, 23);
panel2.add(btnOtherCallsReports);

JButton btnSearchByRma = new JButton("Search By RMA Number");
btnSearchByRma.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
RMASearch rma=new RMASearch();
rma.setVisible(true);
}
});
btnSearchByRma.setBounds(48, 83, 181, 23);
panel2.add(btnSearchByRma);



btnLogANew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Main m=new Main();
m.setVisible(true);
}
});
}

最佳答案

如果您使用 Eclipse 或 Netbeans 作为 IDE,则有两种可能的解决方案:

Eclipse :

  1. From the menu bar's File menu, select Export.
    1. Expand the Java node and select Runnable JAR file. Click Next.
    2. In the Opens the Runnable JAR export wizard Runnable JAR File Specification page, select a 'Java Application' launch configuration to use to create a runnable JAR.
    3. In the Export destination field, either type or click Browse to select a location for the JAR file.
    4. Select an appropriate library handling strategy.
    5. Optionally, you can also create an ANT script to quickly regenerate a previously created runnable JAR file.

Netbeans :

[...]

  1. In NetBeans IDE, choose File > New Project.
  2. In the General Category page of the New Project wizard, select Java Project With Existing Sources. Click Next.
  3. On the Name and Location page of the wizard, fill in a name and folder for your project. Leave the Set as Main Project checkbox selected. Click Next. For example, type AnotherGrep for Project Name. For the Project Folder field, you can just accept the default. The project folder does not have to be in the same location as the source files that you are importing into the project.
  4. On the Existing Sources page of the wizard, you specify the sources that will be in the project. Click the Add Folder button that is to the right of the Source Package Folders field. Then navigate to the DeploymentTutorial folder that you have just unzipped on your system, expand the folder, select the src folder, and click Open. The src folder is added to your Source Package Folders field.
  5. Click Finish.

关于java - 尽管从命令提示符下运行完美,但双击后 jar 文件无法打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29165290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com