-1

In my Java application I am developing a secure client server using jsse. I have 3 Java files that correspond to the Server and 3 that correspond to the Client. (Server,ServerController,ServerView) and the same for client.

Each one of these files is in there own package e.g. ServerView is in the View package.

The main Server and Client java files use classes from the other files so I am importing them using import server.serverSender; etc, this means I need to declare the package names at the top of my files.

However when I export the class files and attempt to run the application and view the JSSE debug output using java -Djavax.net.debug=all in terminal i get an exception in thread 'main' java.lang.NoClassDefFoundError: now I have found the source of the error, it is because I am declaring package etc at the top of my files because as I explained above I am importing classes into the main java files. I found the solution here exception in thread 'main' java.lang.NoClassDefFoundError:

How would I solve this problem? I tried adding all the files to the default package but I can't import classes from the default package they need there own package.

So basically my problem is, I need to use package names at top of my files to import classes but I also need to run application in debug mode that doesn't work when using package names at top of files.

Community
  • 1
  • 1
roukzz
  • 129
  • 1
  • 2
  • 10
  • 2
    You should always use a package. You should learn to use a build tool and/or an IDE so that you can launch. The -D has nothing to do with your package problem. – bmargulies Jan 13 '15 at 22:11
  • I am using an IDE to launch but I want to see the JSSE debug output which I am trying to do through terminal but the package names are causing the error. If I remove the package names it will run but encounters errors due to the imports now not available. – roukzz Jan 13 '15 at 22:14
  • Then you are not launching correctly from the command line. – bmargulies Jan 13 '15 at 22:22

1 Answers1

0

You need to supply a proper classpath when you launch a java program.

If a class is in package a.b.c, then it should be sitting the directory CLASSES/a/b/c, where CLASSES is where you've told the compiler to put it. So, a.b.c.MyClass

CLASSES
  a/
   b/
    c/
     MyClass.class

and then you run:

java -cp CLASSES -Dwhatever a.b.c.MyClass
bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • I have exported the jar file and extracted the folders on my desktop. I am trying to run the Server class file which is in the Server package folder inside the fyp folder on my desktop. When inside the Server package folder i run `java -cp Server -Djavax.net.debug=all Server` and it displays an error `Error: Could not find or load main class Server` – roukzz Jan 13 '15 at 22:39
  • okay i got it working, going back one directory and running `java -Djavax.net.debug=all Server.Server`has worked – roukzz Jan 13 '15 at 22:49