Forums Register Login

Problem of Server-client connection

+Pie Number of slices to send: Send
Hi, guys! I learn Java with "Head First Java" book. There are server and cleint classes like a "DailyAdviceClient.java" and "DailyAdviceServer.java".
Just I've edited it by my code for visualization and graphics. It runs on localhost.
But then I made JAR files for client and server. And after my runnig try it doesn't run.
I've used IntelliJ IDEA for it.
Could you help me please. Classes code is below. Thank you for your advices beforehand.

1. Client code:



2. Server code:

1
+Pie Number of slices to send: Send
Please show us the contents of the .jar, and the contents of its manifest file.
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:contents of the .jar, and the contents of its manifest file.








+Pie Number of slices to send: Send
Please post text; screenshots are very difficult to read. But even with the difficult reading, I can see a problem. You haven't got a main class named in the manifest file. Read the section in the Java™ Tutorials, particularly the part about an application's entry point.
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:Please post text; screenshots are very difficult to read. But even with the difficult reading, I can see a problem. You haven't got a main class named in the manifest file. Read the section in the Java™ Tutorials, particularly the part about an application's entry point.



Contents of manifest files:

Manifest-Version: 1.0
Main-Class: Client.DailyAdviceClient

Manifest-Version: 1.0
Main-Class: Server.DailyAdviceServer


But it doesn't run.
+Pie Number of slices to send: Send
 

Alex Chun wrote:
Contents of manifest files:

Manifest-Version: 1.0
Main-Class: Client.DailyAdviceClient

Manifest-Version: 1.0
Main-Class: Server.DailyAdviceServer


But it doesn't run.



That says that you have two packages, Client and Server.
However the screenshot of your jar files shows that neither of the two classes are in a package...they both sit at the root level.
+Pie Number of slices to send: Send
Both classes are in them packages.

+Pie Number of slices to send: Send
Look at your screenshot for either of those jar files (forget the project).
There are no packages in them.
+Pie Number of slices to send: Send
 

Dave Tolls wrote:Look at your screenshot for either of those jar files (forget the project).
There are no packages in them.



I added it but no changes.

+Pie Number of slices to send: Send

Instead of showing us screenshots, can you just list what's in the jar file for us?

> jar tvf DailyAdviceClient.jar


Henry
+Pie Number of slices to send: Send
 

Henry Wong wrote:
Instead of showing us screenshots, can you just list what's in the jar file for us?

> jar tvf DailyAdviceClient.jar


Henry



Content of Client.jar:

META-INF/MANIFEST.MF
DailyAdviceClient.java
META-INF/

Content of Server.jar:
META-INF/MANIFEST.MF
DailyAdviceServer.java
META-INF/
+Pie Number of slices to send: Send
Which (as with the screenshots) shows clearly that the files are not in packages in the jar file.
It also shows that they are .java files and not .class files, so they won't run.

I don't know how the Eclipse jarring stuff works offhand, so I can't give you the solution, but it looks to me like you haven't told it to jar up the correct bits.
+Pie Number of slices to send: Send
In Eclipse you have an option to export the project as a jar and in the process you can set a “Main” class.
+Pie Number of slices to send: Send
Oh, hang on, that's IntelliJ in those screenshots isn't it?

When I add an artifact and select an empty jar, I get the <Module name> compile output option to add in, over in Available Elements.
Your's should be under Head First Project I think.
+Pie Number of slices to send: Send
 

Dave Tolls wrote:Oh, hang on, that's IntelliJ in those screenshots isn't it?

When I add an artifact and select an empty jar, I get the <Module name> compile output option to add in, over in Available Elements.
Your's should be under Head First Project I think.



Ouch, Dave, exactly! You are my big boss!
Campbell, thank you very much again.

I added "'Head First Project' compile output" into "Output layout" (jar archive).

PS. How can I stop server now?
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1003 times.
Similar Threads
Question about ServerSocket port number and Socket port number
UnknownHostException when trying to connect to localhost
Chapter 15 Head First - DailyAdviceClient and DailyAdviceService
client-server error
Socket Problems :(
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:46:13.