Results 1 to 8 of 8
  1. #1
    Shellback3 is offline Member
    Join Date
    Jan 2011
    Location
    Riveside, CA
    Posts
    16
    Rep Power
    0

    Default Loader won't load when I attempt to run an executable jar from the command line

    I am attempting to learn about socket communications by creating the threaded socket server I found on Oracle: Lesson 1: Socket Communications

    When I run it from Eclipse Indigo on Ubuntu the GUI is displayed and I can telnet a line of text to the GUI.

    I exported the class as an executable jar but when I run it from the command line (with or without sudo) I get a loader error that I don't understand at all:

    programmer@blue:~/var/jars$ sudo java -jar SocketServer.jar
    [sudo] password for programmer:
    Exception in thread "main" java.lang.IllegalAccessException: Class org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoa der can not access a member of class fireScience.airborne.server.SocketThrdServer with modifiers "public static"
    at sun.reflect.Reflection.ensureMemberAccess(Reflecti on.java:95)
    at java.lang.reflect.Method.invoke(Method.java:607)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoa der.main(JarRsrcLoader.java:58)

    This is the main() FWIW.

    Java Code:
    	public static void main(String[] args) {
    		SocketThrdServer frame = new SocketThrdServer();
    		frame.setTitle("Server Program");
    		WindowListener l = new WindowAdapter() {
    			public void windowClosing(WindowEvent e) {
    				System.exit(0);
    			}
    		};
    		frame.addWindowListener(l);
    		frame.pack();
    		frame.setLocation(100, 100);
    		frame.setVisible(true);
    		frame.listenSocket();
    	}
    AFAIK I exported this in the same manner as some other classes.
    I'd like to know what is causing this and what to do about it.
    TIA

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Loader won't load when I attempt to run an executable jar from the command line

    Your code is (in)directly refering to an Eclipse class; why? e.g. what is a SocketThrdServer?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Shellback3 is offline Member
    Join Date
    Jan 2011
    Location
    Riveside, CA
    Posts
    16
    Rep Power
    0

    Default Re: Loader won't load when I attempt to run an executable jar from the command line

    SocketThrdServer is the class which includes main.
    Here is the whole class:

    Java Code:
    package fireScience.airborne.server;
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import java.net.Socket;
    
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    
    class ClientWorker implements Runnable {
    	private Socket client;
    	private JTextArea textArea;
    
    	ClientWorker(Socket client, JTextArea textArea) {
    		this.client = client;
    		this.textArea = textArea;
    	}
    
    	public void run() {
    		String line;
    		BufferedReader in = null;
    		PrintWriter out = null;
    		try {
    			in = new BufferedReader(new InputStreamReader(
    					client.getInputStream()));
    			out = new PrintWriter(client.getOutputStream(), true);
    		} catch (IOException e) {
    			System.out.println("in or out failed");
    			System.exit(-1);
    		}
    
    		while (true) {
    			try {
    				line = in.readLine();
    				// Send data back to client
    				out.println(line);
    				textArea.append(line);
    			} catch (IOException e) {
    				System.out.println("Read failed");
    				System.exit(-1);
    			}
    		}
    	}
    }
    
    @SuppressWarnings("serial")
    class SocketThrdServer extends JFrame {
    
    	public int myListenPort = 4444;
    	JLabel label = new JLabel("Text received over socket:");
    	JPanel panel;
    	JTextArea textArea = new JTextArea();
    	ServerSocket server = null;
    
    	SocketThrdServer() { // Begin Constructor
    		panel = new JPanel();
    		panel.setLayout(new BorderLayout());
    		panel.setBackground(Color.white);
    		getContentPane().add(panel);
    		panel.add("North", label);
    		panel.add("Center", textArea);
    	} // End Constructor
    
    	public void listenSocket() {
    		try {
    			server = new ServerSocket(myListenPort);
    		} catch (IOException e) {
    			System.out.println("Could not listen on port " + myListenPort);
    			System.exit(-1);
    		}
    		while (true) {
    			ClientWorker w;
    			try {
    				w = new ClientWorker(server.accept(), textArea);
    				Thread t = new Thread(w);
    				t.start();
    			} catch (IOException e) {
    				System.out.println("Accept failed: " + myListenPort);
    				System.exit(-1);
    			}
    		}
    	}
    
    	protected void finalize() {
    		// Objects created in run method are finalized when
    		// program terminates and thread exits
    		try {
    			server.close();
    		} catch (IOException e) {
    			System.out.println("Could not close socket");
    			System.exit(-1);
    		}
    	}
    
    	public static void main(String[] args) {
    		SocketThrdServer frame = new SocketThrdServer();
    		frame.setTitle("Server Program");
    		WindowListener l = new WindowAdapter() {
    			public void windowClosing(WindowEvent e) {
    				System.exit(0);
    			}
    		};
    		frame.addWindowListener(l);
    		frame.pack();
    		frame.setLocation(100, 100);
    		frame.setVisible(true);
    		frame.listenSocket();
    	}
    }
    Here's the contents of the manifest:

    Manifest-Version: 1.0
    Rsrc-Class-Path: ./
    Class-Path: .
    Rsrc-Main-Class: fireScience.airborne.server.SocketThrdServer
    Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoa der
    Last edited by Shellback3; 06-22-2012 at 10:05 PM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,435
    Rep Power
    25

    Default Re: Loader won't load when I attempt to run an executable jar from the command line

    It looks like your IDE is confused about what should be in the jar file. The manifest file's Main-Class: should refer to your class with the main() method: fireScience.airborne.server.SocketThrdServer not to what it has now.
    Check the options you are using to create the jar file.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Shellback3 is offline Member
    Join Date
    Jan 2011
    Location
    Riveside, CA
    Posts
    16
    Rep Power
    0

    Default Re: Loader won't load when I attempt to run an executable jar from the command line

    Here are the contents of a manifest that works with another class with a main():

    Manifest-Version: 1.0
    Rsrc-Class-Path: ./
    Class-Path: .
    Rsrc-Main-Class: fireScience.airborne.image.ImageDisplay
    Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoa der

    Here's the one, again, that doesn't :

    Manifest-Version: 1.0
    Rsrc-Class-Path: ./
    Class-Path: .
    Rsrc-Main-Class: fireScience.airborne.server.SocketThrdServer
    Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoa der

    The only lines that differ are in bold and SocketThrdServer is the class with main in it not ClientWorker.
    The only option i pick in exporting is to "package the required libraries into generated jar".
    When I looked into the contents of the executable jar that works and this one that doesn't I don't find any mention of "main".

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,435
    Rep Power
    25

    Default Re: Loader won't load when I attempt to run an executable jar from the command line

    I create the manifest files with an editor and use the jar command to create the jar. The Main-Class: entry refers to my class with the main() method where the execution of the program starts.
    Your IDE has put its own classes in the jar and manifest file as the starting program in place of your program.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Loader won't load when I attempt to run an executable jar from the command line

    It might be worth trying *without* using Eclipse's jar-in-jar magic.

    As Norm says try creating the jar (and compiling the source?) and running it from the command line. If you're used to clinging to the IDE's apron strings this would be a good time to break free and master the command line options necessary to compile and run when a 3rd party library is involved. The idea is to try and see whether the options you have set in Eclipse are faulty or whether there is something awry with the code itself (like a missing resource or part of the library).

  8. #8
    Shellback3 is offline Member
    Join Date
    Jan 2011
    Location
    Riveside, CA
    Posts
    16
    Rep Power
    0

    Default Re: Loader won't load when I attempt to run an executable jar from the command line

    Thanks, I'll give it a shot. The other example, for a client socket, has the same problem and while rummaging around in an executable jar that works I found references to another package that not is referenced in any way by my code.

Similar Threads

  1. Replies: 17
    Last Post: 04-25-2012, 03:42 PM
  2. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  3. can i run line by line command in netbean?
    By choconlongxu in forum NetBeans
    Replies: 1
    Last Post: 07-19-2010, 08:41 PM
  4. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •