java.lang.NoClassDefFoundError: BoothServer - java

I'm following this tutorial http://stilius.net/java/java_ssl.php to create simple SSLServer and client sockets. I've created the certificate using keytool but I've a problem executing this line from the above tutorial,
"java -Djavax.net.ssl.keyStore=mySrvKeystore -Djavax.net.ssl.keyStorePassword=123456 EchoServer".
Where should I put the certificate? in project directory?
how can I pass the parameters mentioned above?
I'm doing this and getting error;
C:\Users\abc\workspace\VirtualElectionBoothServer\bin>java -Djavax.net.ssl.keyStore=mySrvKeystore -Djavax.net.ssl.keyStorePassword=123456 BoothServer
Exception in thread "main" java.lang.NoClassDefFoundError: BoothServer
Caused by: java.lang.ClassNotFoundException: BoothServer
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: BoothServer. Program will exit.
Edit:
my problem is that I never run a project from command line so I don't know how to run this line from command line;
C:\Users\abc\workspace\VirtualElectionBoothServer\bin>java -Djavax.net.ssl.keyStore=mySrvKeystore -Djavax.net.ssl.keyStorePassword=123456 BoothServer
From which directory should i run it? I've more than one .java files. which one to run? one having main()?

It looks like you don't know how to run a Java application from the command line.
I'll just assume that your BoothServer class isn't in a package. If it is, use its full name (e.g. the.package.name.BoothServer).
I'll also assume that you've compiled this within eclipse and that the resulting class file is in the bin directory. (If you are using packages, you should have your file under bin\the\package\name\BoothServer.class. Replace the directory names with the actual package names if this is the case, of course.)
javax.net.ssl.SSLException: No available certificate or key
corresponds to the SSL cipher suites which are enabled
This is the typical error that happens when the keystore can't be found (amongst other reasons).
Make sure the path you're using with -Djavax.net.ssl.keyStore= points to the actual keystore you've generated. For example, -Djavax.net.ssl.keyStore=..\mySrvKeyStore if your file is under C:\Users\abc\workspace\VirtualElectionBoothServer.
I also suspect that Eclipse might clear the content of bin every time it recompiles (not sure), so bin would not necessarily be a good place to keep that keystore file.

Related

Apache Qpid:Error while running qpid-server.bat

When I am running qpid-server.bat, I am getting following error:
C:\qpid\qpid-0.24\java\broker\bin>qpid-server.bat
Warning: Qpid classpath not set. CLASSPATH set to C:\qpid\qpid-0.24\java\broker\lib\qpid-all.jar;C:\qpid\qpid-0.24\java\broker\lib\plugins\*;C:\qpid\qpid-0.24\java\broker\lib\opt\*
Info: QPID_JAVA_GC not set. Defaulting to JAVA_GC -XX:+UseConcMarkSweepGC -XX:+HeapDumpOnOutOfMemoryError
Info: QPID_JAVA_MEM not set. Defaulting to JAVA_MEM -Xmx1024m
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/qpid/server/Main
Caused by: java.lang.ClassNotFoundException: org.apache.qpid.server.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.apache.qpid.server.Main. Program will exit.
I am not running any code. I am just starting qpid-server.bat and getting above error.
I would be really thankful if anyone would suggest me the solution.
After downloading the code from Apache "qpid-java-6.1.0", I also had errors running the broker. I found that the broker folder I was using was incorrect. I was able to run the broker by setting the system variable QPID_HOME to "C:\qpid\qpid-java-6.1.0\systests\target\qpid-broker\6.1.0" and running the "qpid-server.bat" in that location. You can then log into the broker at "http://localhost:8080" with user = admin and password = admin. I am not sure what the "systests" folder is or why the bin and lib files are here, but it works. Navigate to that folder and look at the files there. Let me know if there is a better folder I am supposed to be in. I then create a connection factory with the URL "amqp://admin:admin#clientid/?brokerlist='tcp://localhost:5672" and it works.
I have seen this problem caused by an incorrect setting of the QPID_HOME environment variable.
With a normal installation QPID_HOME needs to refer to the immediate parent of the lib directory. The batch file tries to determine QPID_HOME if it is not set, but will use its current value otherwise. Check you have not set it erroneously.

Jar file with Jaudiotagger, NoClassDefFoundError

I made a java class using the library Jaudiotagger, and it runs without problems. I then made a jar out of it and I got NoClassDefFoundError. Here's how it went:
I put the main class id3tag.java and the library jaudiotagger-2.0.3.jar in a folder and compiled using the command line. The program ran smoothly without problems.
javac -cp .;jaudiotagger-2.0.3.jar id3tag.java
java -cp .;jaudiotagger-2.0.3.jar id3tag
I then created the manifest and the jar file.
echo Main-Class: id3tag >manifest.txt
jar cvfm id3tag.jar manifest.txt id3tag.class jaudiotagger-2.0.3.jar
I got the following output:
added manifest
adding: id3tag.class(in = 5952) (out= 2997)(deflated 49%)
adding: jaudiotagger-2.0.3.jar(in = 811441) (out= 740599)(deflated 8%)
I then ran the jar file, and got "A Java Exception has occurred.". I also tried:
java -jar id3tag.jar
And I got the output:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/tag/
FieldDataInvalidException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.tag.FieldDataInval
idException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more
I then replaced all (both) error classes used from Jaudiotagger with Exception and recreated the jar. Now the same thing happens as for seemingly all other jar files when I run them (with Java(TM) Platform SE binary, or through writing id3tag.jar in the command prompt) - nothing. java -jar, however, works and gave me a runtime error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/audi
o/AudioFileIO
at id3tag.tagSong(id3tag.java:112)
at id3tag.tagAlbum(id3tag.java:82)
at id3tag.tagArtist(id3tag.java:40)
at id3tag.main(id3tag.java:170)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.audio.AudioFileIO
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 4 more
It seems like the entire library just doesn't do shit for me. How do I fix this, and how do I get jar files to run without java -jar? (Also, how do I get the full pile'o'errors in case someone needs it, rather than just having it say "x more"?)
I'm not very savvy with this kinda shit so the more specific the answer, the better. Thanks.
I'm on windows 8 and latest java (1.7.0_17).
this is informing you that you have no main class, as you might or might not already know all programs in almost all non web based programming languages must have a main class to start from. In java it looks like this
public static int main(String[] args){
}
The message is informing you that this class is no longer there, this could be a compiler error or something entirely different.
please try downloading the library again, and downloading eclipse ide for java ee developers.
this ide has a built in compiler that will work better than a command line sometimes.
i hope this helped.
I worked around it by including the org folder from jaudiotagger in my .jar instead of the actual .jar file, and I then used a .bat file to run it instead of running the .jar directly. Feel free to add your own answer if you find a better solution, and I'll check back.
I extracted jaudiotagger-2.0.3.jar with winrar so that the org folder was in the same folder as my main class. Then I could compile and run the main class simply by:
javac id3tag.java
java id3tag
I then created the manifest file the same way as before, and created the jar:
jar cvfm id3tag.jar manifest.txt id3tag.class org
The jar file worked with java -jar id3tag.jar, but simply writing id3tag.jar still did nothing. Turns out it's because jar files are by default run by the javaw.exe file, so you have to right click the jar file -> open with -> choose default program and navigate to the java.exe file in your java folder (just search the folder). Running the .jar then gets you "Error: Could not find or load main class path\id3tag.jar". I worked around this by using a .bat file. I entered
java -jar path\id3tag.jar
into Notepad and saved as whatevername.bat (save as type: all files).
I created a new question for getting the .jar file to work properly. See .jar error - could not find or load main class.

SNMP4J.jar - java.lang.ClassNotFoundException

I'm trying to check some SNMP example, so
i've downloaded snmp4j.jar
compiled SNMP.java using javac -cp snmp4j.jar SNMP.java (it's OK)
tried to start it using java -cp snmp4j.jar SNMP, but
it reports:
root#comp:~/workspace_c/SNMP# java -cp snmp4j.jar SNMP
Exception in thread "main" java.lang.NoClassDefFoundError: SNMP
Caused by: java.lang.ClassNotFoundException: SNMP
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: SNMP. Program will exit.
UPDATE:
And when I import snmp4j.jar to the java project, it works normally in ECLIPSE...
UPDATE#2: main part of SNMP.java
import org.snmp4j.CommunityTarget;
...
public class SNMP {
public static void main(String[] args) {
...
}
}
what i'm doing wrong? it's first time i've met snmp4j so i know noting about it
If I understand correctly, SNMP is your example class, which isn't inside the jar. In that case, you need to add to the classpath both the jar and your current directory:
java -cp .:snmp4j.jar SNMP
As far as I can see you are trying to run your application with SNMP4J.jar (upper case) but when you compiled your application you probably used lower case version.
Your prompt shows that your are using unix OS that has case sensitive file system. So, check the case of the JAR file name. I believe that all letters are in lower case.

Cannot get -javaagent to run without error

I'm trying to create a simple Java Agent program before I implement the real thing. I cannot get it to run. Clearly I have some sort of configuration or class path problem. No amount of looking and trying has lead to me the problem.
If I run:
java -cp ./demoAgent.jar -javaagent:./demoAgent.jar com.kingtigerbooks.demoMod.Main
I get the following error:
Exception in thread "main" java.lang.ClassNotFoundException: com.kingtigerbooks.demoAgent.Agent
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:280)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)
FATAL ERROR in native method: processing of -javaagent failed
Abort trap
I'm running this on my Mac. The jar file with the agent is in the current directory. The manifest for the jar file looks like this:
Manifest-Version: 1.0
Premain-class: com.kingtigerbooks.demoAgent.Agent
Can-Redefine-Classes: true
If smells like a class path problem, but as you can see I have included the jar on the class path. Any help would be appreciated. Its a very simple project.
Problem solved. I had a bad jar file. The agent jar file did not contain the agent class. By building the correct jar file and putting the fully qualified path to the jar on in the javaagent parameter it all works.
when you run an agent, you do not add the agent jar to the normal classpath.
as a side note, you can add -verbose:class to the command line to get info about the class loading process.

Javac compilation and execution of 2 java files

The program is written with 2 files filter.java - in which is the main function and ClasifiedWord.java which is only container class. I wrote that on windows on eclipse but want to compile it on Linux javac compiler.
javac filter.java ClasifiedWord.java
runs without mistakes, but when I try to run the program:
snowy:Filter$ java filter
Exception in thread "main" java.lang.NoClassDefFoundError: filter
Caused by: java.lang.ClassNotFoundException: filter
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: filter. Program will exit.
snowy:Filter$ javac filter.java ClasifiedWord.java
snowy:Filter$ java filter ClasifiedWord
Exception in thread "main" java.lang.NoClassDefFoundError: filter
Caused by: java.lang.ClassNotFoundException: filter
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: filter. Program will exit.
How can I run the program ? It seems that the compilation is ok. I have doubts that maybe I have made a mistake about the file paths in the program.... but I think that this is not the case?
Thanks for your answers!
Type the following command.
java -classpath . filter
If you want to type just java filter, please following these guides.
Linux http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/
Windows http://ac-support.europe.umuc.edu/~arnoldyl/NetBeansTutorials/Setting-Classpath.html
P.S. The last command java filter ClasifiedWord means to run a program filter and use a string ClasifiedWord as an argument.
Roland is right in the comment, you should be able to run it with java -classpath <folderContainingDotClassFiles> filter. Also, you should change filter.java to Filter.java as the standard Java convention for class names (including the files containing them) is to capitalize the first letter.
This looks like you either have a wrong CLASSPATH setting (usually you don't need this at all, but if you have it, it should include . in the list, for the current directory), or you are using packages (wrongly), or both. For the classpath issue, see the other answers.
If you are using packages, i.e. your files contain a package ...; line at the beginning, you should put your source files in a directory structure according to the package structure. For example, if you have package example;, you should have an example directory in your current directory, and in this the two source files.
Then call compiler and interpreter like this:
javac example/filter.java example/ClasifiedWord.java
java example.filter
(This assumes that filter is the main class, otherwise replace its name.)

Categories