[英]Export as Runnable Jar file , java executing errors
Working with my project, which is done already, want it to compile and run from a single .jar file, as other mentioned that I should be using Export -> Runnable Jar file. 使用我已经完成的项目,希望它从单个.jar文件编译和运行,正如其他提到的那样,我应该使用Export - > Runnable Jar文件。
I select my main Server class, also selecting "Package required libraries into generated JAR" and pressing Finish. 我选择我的主要Server类,同时选择“将所需的库打包到生成的JAR中”并按Finish。
Now I got a file named : Server.jar 现在我得到了一个名为Server.jar的文件
Trying to run from console : java -jar Server.jar
and getting error: 试图从控制台运行:
java -jar Server.jar
并获取错误:
java.lang.NullPointerException
at server.Server.main(Server.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
which refers to : 指的是:
Socket socket = serverSocket.accept();
MANIFEST.MF File (Created auto): MANIFEST.MF文件(创建自动):
Manifest-Version: 1.0
Rsrc-Class-Path: ./ json-simple.jar mysql-connector-java-5.1.42-bin.ja
r
Class-Path: .
Rsrc-Main-Class: server.Server
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
I'm tired of guessing the problems, I'm new in Java, first doing the compiling. 我厌倦了猜测问题,我是Java新手,首先进行编译。 Any help?
有帮助吗?
My Server.java class : 我的Server.java类:
package server;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import org.json.simple.parser.*;
public class Server {
public static void main(String args[]) throws ParseException{
ServerSocket serverSocket = null;
ArrayList<ClientComm> clients = new ArrayList<ClientComm>();
try{
new Config();
serverSocket = new ServerSocket(Config.getPort()); // can also use static final PORT_NUM , when defined
System.out.println("Server started");
System.out.println("test");
}
catch(IOException e){
e.printStackTrace();
System.out.println("Server error");
}
int clientID = 0;
while(true){
try{
System.out.println("Waiting for new connection");
Socket socket = serverSocket.accept();
clientID++;
System.out.println("New connection on socket: " + socket);
ClientComm clientComm = new ClientComm(socket, clientID);
clients.add(clientComm);
if(clientComm.checkAuth() == false) {
System.out.println("Client was dropped from connection because auth codes did not match");
socket.close();
}
else {
clientComm.start();
}
}
catch(Exception e){
e.printStackTrace();
System.out.println("Connection Error");
}
}
}
}
The problem was solved long time ago. 问题很久以前就解决了。 Was my personal bad with lack of experience in programming with java.
由于缺乏使用java编程的经验,我的个人不好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.