有兩個問題Java導出爲Jar有錯誤
1)當將Java項目導出爲JAR文件時,應用程序如何知道程序包中的哪個類首先運行?我的應用程序特別要求userInterface.java文件在CommonDenom.java文件之前運行。
2)運行java文件時出現錯誤,提示「Java JAR文件」commonDenom.jar「無法啓動,請檢查控制檯是否有可能的消息。
我從哪裏開始弄清楚這一點?我檢查了控制檯,但在錯誤信息彈出時它似乎沒有註冊任何東西。
package commonDenom;
import java.util.Arrays;
import java.util.Scanner;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class UserInterface {
Shell shell;
Button btnNext;
Button btnDone;
Text input;
Text output;
static int count;
static int[] finalNums;
int[] nums = new int[1000];
public static void main(String[] args){
Display display = new Display();
new UserInterface(display);
display.dispose();
}
public UserInterface(Display display){
shell = new Shell(display);
shell.setSize(220,350);
shell.open();
input = new Text(shell, SWT.SINGLE);
input.setBounds(10, 10, 100, 20);
btnNext = new Button(shell, SWT.PUSH);
btnNext.setBounds(10, 40, 100, 30);
btnNext.setText("Next");
nextPress();
btnDone = new Button(shell, SWT.PUSH);
btnDone.setBounds(10, 80, 100, 30);
btnDone.setText("Done");
donePress();
output = new Text(shell, SWT.SINGLE);
output.setBounds(10, 120, 200, 200);
while(!shell.isDisposed()){
if(!display.readAndDispatch()){
display.sleep();
}
}
}
public void nextPress(){
btnNext.addSelectionListener(new SelectionAdapter(){
int x = 0;
@Override
public void widgetSelected(SelectionEvent e) {
nums[x] = Integer.parseInt(input.getText());
System.out.println("nums[" + x + "]:" + nums[x]);
x++;
count++;
}
});
}
public void donePress(){
btnDone.addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent e) {
finalNums = new int[count];
for(int i = 0; i < count; i++){
finalNums[i] = nums[i];
}
System.out.println("finalNums:" + Arrays.toString(finalNums));
commonDenom.compare();
if(commonDenom.getResult() == 0){
output.setText(Arrays.toString(finalNums) + "\nThese numbers do not have a \ncommon multiplier");
}
else{
output.setText(Arrays.toString(finalNums) + "\nResult:" + String.valueOf(commonDenom.getResult()));
}
}
});
}
public static int[] getNums(){
return finalNums;
}
}
Manifest.txt位置:/升降梭箱/工作區/ commonDenom/bin中
類位置:/升降梭箱/工作區/ commonDenom/bin中/ commonDenom/
類名:
commonDenom.class
UserInterface.class
UserInterface$1.class (I didn't create this)
UserInterface$2.class (I didn't create this)
Manifest.txt內容(帶有兩個尾隨空白行):
Main-Class: commonDenom.UserInterface
罐子TF CommonDenom.jar返回如下:
META-INF/
META-INF/MANIFEST.MF
Manifest.txt
commonDenom/
commonDenom/commonDenom.class
commonDenom/UserInterface$1.class
commonDenom/UserInterface$2.class
commonDenom/UserInterface.class
你的意思是_My applicatino(sic)特別要求userInterface.java文件在CommonDenom.java_之前運行?只有**一個**類被運行 - 在你的'META-INF/MANIFEST.MF'中被指定爲'Main-Class'的類。有關更多信息,請參見[this](http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html)。附:你發佈了**拼寫錯誤**。這表明你很少或沒有努力。如果你不能被打擾,爲什麼我們應該付出努力? –