Results 1 to 8 of 8
- 06-22-2012, 09:13 PM #1
Member
- Join Date
- Jan 2011
- Location
- Riveside, CA
- Posts
- 16
- Rep Power
- 0
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.
AFAIK I exported this in the same manner as some other classes.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(); }
I'd like to know what is causing this and what to do about it.
TIA
- 06-22-2012, 09:21 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-22-2012, 09:34 PM #3
Member
- Join Date
- Jan 2011
- Location
- Riveside, CA
- Posts
- 16
- Rep Power
- 0
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:
Here's the contents of the manifest: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(); } }
Manifest-Version: 1.0
Rsrc-Class-Path: ./
Class-Path: .
Rsrc-Main-Class: fireScience.airborne.server.SocketThrdServer
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoa derLast edited by Shellback3; 06-22-2012 at 10:05 PM.
- 06-22-2012, 10:26 PM #4
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.
- 06-22-2012, 11:58 PM #5
Member
- Join Date
- Jan 2011
- Location
- Riveside, CA
- Posts
- 16
- Rep Power
- 0
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".
- 06-23-2012, 01:01 AM #6
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.
- 06-23-2012, 02:10 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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).
- 06-23-2012, 04:45 AM #8
Member
- Join Date
- Jan 2011
- Location
- Riveside, CA
- Posts
- 16
- Rep Power
- 0
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
-
Could not find or load main class (Windows 7 command line)
By jbean079 in forum New To JavaReplies: 17Last Post: 04-25-2012, 03:42 PM -
Open a URL and read it line by line (Works in Eclipse but not from Command Line)
By rosco544 in forum NetworkingReplies: 16Last Post: 09-17-2011, 02:41 AM -
can i run line by line command in netbean?
By choconlongxu in forum NetBeansReplies: 1Last Post: 07-19-2010, 08:41 PM -
Formatting java command line output - Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07-02-2010, 02:20 PM -
Unable to execute command line command in java
By LordSM in forum New To JavaReplies: 1Last Post: 08-08-2007, 12:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks