1

Compiled

I've compiled the java code, but I'm not able to run it. I compiled the code with the following:

javac -cp "streamer-client-java.jar:kafka-clients-3.4.0.jar:snappy-java-1.1.10.0.jar:lz4-java-1.8.0.jar:slf4j-api-2.0.7.jar:." EnduserCredentialExample.java

Currently, I'm getting this output:

Note: EnduserCredentialExample.java uses unchecked or unsafe operations. 
Note: Recompile with -Xlint:unchecked for details. 

Tried running the compiled class

I also tried running with another approach:

java -cp "streamer-client-java.jar:kafka-clients-3.4.0.jar:snappy-java-1.1.10.0.jar:lz4-java-1.8.0.jar:slf4j-api-2.0.7.jar:." EnduserCredentialExample

Which, unfortunately, produces the following error:

Error: Could not find or load main class EnduserCredentialExample Caused by: java.lang.NoClassDefFoundError: com/quotemedia/streamer/client/example/EnduserCredentialExample (wrong name: EnduserCredentialExample)

And then I also tried running the code using .java (I added .java to it):

java -cp "streamer-client-java.jar:kafka-clients-3.4.0.jar:snappy-java-1.1.10.0.jar:lz4-java-1.8.0.jar:slf4j-api-2.0.7.jar:." EnduserCredentialExample.java

But this worked when running the normal java code but when I tried running the compiled class, I got this error:

Error: Could not find or load main class EnduserCredentialExample Caused by: java.lang.NoClassDefFoundError: com/quotemedia/streamer/client/example/EnduserCredentialExample (wrong name: EnduserCredentialExample)
  • Looks like your class argument should be `com.quotemedia.streamer.client.example.EnduserCredentialExample` – g00se Jun 04 '23 at 07:50
  • All details relevant to your question must be in the question. Hint: your question will become meaningless to others the instant that your google drive links are disabled. – Stephen C Jun 04 '23 at 08:01
  • @g00se When I try below command `java -cp "streamer-client-java.jar:kafka-clients-3.4.0.jar:snappy-java-1.1.10.0.jar:lz4-java-1.8.0.jar:slf4j-api-2.0.7.jar:." com/quotemedia/streamer/client/example/EnduserCredentialExampl` Im getting following error, Error: LinkageError occurred while loading main class com.quotemedia.streamer.client.example.EnduserCredentialExample java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/quotemedia/streamer/client/example/EnduserCredentialExample (class file version 61.65535). Try running with '--enable-preview' – Navaneeth Busha Jun 04 '23 at 08:28
  • Navethaneeth - You don't get it. Please don't give us links to your Google Drive. Not in the question. Not in the comments. **Not at all**. – Stephen C Jun 04 '23 at 08:39
  • You didn't use what I gave you – g00se Jun 04 '23 at 08:41

1 Answers1

0

You appear to be making a number of mistakes ...

Firstly you appear to be ignoring warnings about unchecked / unsafe conversions:

Note: EnduserCredentialExample.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

You need to do what the message says. Recompile that class with the -Xlint:unchecked option. Then read the error messages and correct your source code.

(Hint: I am NOT going to look at your Google drive to figure out errors are. You know what you need to do about that. I have told you ... twice already!!)


Next we have this error

Error: Could not find or load main class EnduserCredentialExample 
    Caused by: java.lang.NoClassDefFoundError: com/quotemedia/streamer/client/example/EnduserCredentialExample 
    (wrong name: EnduserCredentialExample)

That means that there is a mismatch between the package name of the class and its pathname in the file system. See this Q&A for an explanation:


Finally we have this error:

Error: LinkageError occurred while loading main class com.quotemedia.streamer.client.example.EnduserCredentialExample java.lang.UnsupportedClassVersionError: 
Preview features are not enabled for com/quotemedia/streamer/client/example/EnduserCredentialExample (class file version 61.65535). 
Try running with '--enable-preview'

It appears that you have (previously) compiled EnduserCredentialExample with Java 17 preview features enabled. That's OK ... but you also need to include --enable-preview in the java command line options when you load and run the class. This Q&A may help you understand:

Unless you are intentionally using preview features in your code, it is inadvisable to enable them at compile time.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216