0

I am new to Java and was hoping someone could help me with this issue.

I have set up a project in eclipse; and have three packages: Client, Interfaces, and Server.

When I run the server as java application (through eclipse), it launches fine. If I then run the client as java application through eclipse the results are exactly as I would expect.

I am now trying to run them through the command line. First I created a jar containing all my Interfaces *.class files

I am now trying to compile the Server.java file, but it is saying that package Interface does not exist.

So currently I have:

src/Interfaces
       |--inter1.java
       |--inter2.java
       |--inter1.class
       |--inter2.class
       |--inter12.jar 
             |--inter1.class
             |--inter2.class
src/Server
      |-myServer.java
      |-fileThat'myServer.java'dependson.java
src/Client
      |-myClient.java 

And in myServer.java I have for example:

 package Server
 ...
 import Interfaces.inter1;

It appears I am breaking the package structure trying to run this; thus far I have tried several things, including

java -cp ../Interfaces/inter12.jar: myServer.java

which throws "Exception in thread "main" java.lang.NoClassDefFoundError: myServer/java"

Any help is appreciated, I am admittedly a little lost here and the more I read the more confused I get.

EDIT: I cannot compile the myServer.java; on running 'javac myServer.java' I get:

myServer.java:8: package Interfaces does not exist
           import Interfaces.inter1;

1 Answers1

0

Run the compiled class not the source file.

Also consider that when using java -cp you are required to provide fully qualified main class name, e.g.

java -cp com.mycompany.MyMain

To compile the server class try the following:

How to include jar files with java file and compile in command prompt

Or.. why don't you export all the classes from eclipse as a jar file? (same thing you did for interfaces)

When running server class you must add to running classpath the interfaces jar. See: How to run a java class with a jar in the classpath?

Something like:

java -cp interfaces.jar;. server.MyServer
Community
  • 1
  • 1
jj88
  • 91
  • 1
  • 7
  • I created the jar file on the command line....I am still running into the same errors but thank you for your help – David Lemporo Sep 19 '13 at 22:20
  • You've given the command line here correctly the second time but not the first time. – user207421 Sep 19 '13 at 22:36
  • I am still getting the same errors: package Interfaces does not exist...I have tried both jar files with the Interfaces directory (and the two class files in it) and jar files with just the class files) but neither seems to work – David Lemporo Sep 19 '13 at 22:36
  • what command did you actually use? did you use your own jar, package and classes names? what was the error? – jj88 Sep 19 '13 at 22:41