0

Exclaimer: I am pretty much a complete noob when it comes to eclipse and java, but I am learning! :D Thanks for your help

I am using the apache commons io to create an external server log that is saved in a file along with showing in the server console itself. I added the right file to the external jar library and it all works inside eclipse, but when I export it and try to run it on it's own, I get these errors

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/io/output/TeeOutputStream
at com.josh.chat.server.ServerMain.<init>(ServerMain.java:10)
at com.josh.chat.server.ServerMain.main(ServerMain.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.output.TeeOutputStream
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more

What is going on? How do I fix this, or at least is there another way for me to use the console AND save a log of that console to a text file?

EDIT: I didn't change anything (at least I don't think I did...) and tried to run it again and then got this different error, what did I do?

no main manifest attribute, in InstantChatServer.jar
jmaster2013
  • 33
  • 1
  • 7
  • 1
    How do you "run it on it's own", do you have the commons-io library in the Classpath ? – Arnaud Feb 25 '16 at 15:24
  • can you explain that in a "dumber" way? I added the correct commons-io jar file to the library through the properties tab in eclipse. I then export it and run it through my terminal, os it returns that error, if that answers your question. Sorry for not understanding... – jmaster2013 Feb 25 '16 at 15:26
  • Just post the command line you use to launch your application through the terminal . – Arnaud Feb 25 '16 at 15:28
  • java -jar InstantChatServer.jar 8192 – jmaster2013 Feb 25 '16 at 15:33
  • Possible duplicate of [Setting multiple jars in java classpath](http://stackoverflow.com/questions/219585/setting-multiple-jars-in-java-classpath) , you have to add the commons-io jar to the -classpath argument. – Arnaud Feb 25 '16 at 15:39
  • okay thank you for that recommendation, I will try that – jmaster2013 Feb 25 '16 at 16:16
  • @Berger, thank you for that response. It definitely fixed the other error, except now it is saying `Error: Could not find or load main class InstantChatServer.jar` I didn't change anything, and it was working before. What did I do? ALSO really sorry for all the questions, I am trying to fix this and I am new to this, so I am really happy I found someone who knows more than me and can help me. If you ever get upset with me for needing more help or if you can't help don't worry about it. – jmaster2013 Feb 25 '16 at 16:36
  • the thing is that you can't use "-jar" option at the same time as "-classpath" option . See the examples in the topic, you will have to add your own jar to the classpath, and specify "package+name" of your main class . – Arnaud Feb 25 '16 at 16:39
  • Just to clarify for myself, in my path I should be doing this: `java -cp “commons-io-2.4.jar:lib/*” InstantChatServer.MainServer` right? That is still returning the same error, again really sorry, I feel bad for that. – jmaster2013 Feb 25 '16 at 16:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/104557/discussion-between-berger-and-jmaster2013). – Arnaud Feb 25 '16 at 16:50

1 Answers1

0

Probably your issue might have been fixed by now but on broader scope if you need further dependencies/libraries to be there then you will have to edit the class path and also the client(the one who is doing the java -jar ... stuff) needs to have those dependencies be present in his box.What if there are hundred such dependencies. Ideally you should prefer a build tool like maven,gradle etc. and bundle the jars/dependencies with your code. So that the client need not have to bother about having the libraries in local box.

AbhishekAsh
  • 421
  • 2
  • 15