M
M
Maly2022-03-19 08:54:20
Java
Maly, 2022-03-19 08:54:20

How to rename java to jar?

There is a test.java file with classes. You need to rename this file to test.jar format so that when you double-click the file opens. I tried via IntelegiIde c build artifacts. But it didn't work there. Tried via command line with
java -jar test.jar. It gave an error: Error: Could not find or load main class jdk Caused by: java.lang.ClassNotFoundException: jdk. Are there any other ways or where am I making a mistake?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Michael, 2022-03-19
@Akela_wolf

"How to rename .txt to .exe so that it can be opened by double clicking?"
This is not called "rename", but "compile". I won’t tell you about your IDE, but in general, in general, it’s done like this:

  1. Compile java files into classes (.class) using javac (not java, namely javac compiler)
  2. Add a manifest file to this class set
  3. Optionally add dependencies there (if you need a fat jar)
  4. Collect it all in a zip archive
  5. Change the extension to jar

In more or less complex projects, this is all automated by a build system such as gradle or maven.

O
Orkhan, 2022-03-19
Hasanly @azerphoenix

Good afternoon.
I think you need to start by learning the basics.
jar is a java archive.
java is the file extension before compilation
class is the file extension after compilation (where the bytecode is stored)

Error: Could not find or load main class jdk Caused by: java.lang.ClassNotFoundException: jdk.

jdk class not found. Post the source code so you can see what the problem is. I hope you didn't forget to add the main method?
You also need a MANIFEST.mf file where you need to write Main-Class: jdk
And one more thing, if you have a lot of dependencies, you may need to make a fat jar (jar with dependencies)
https://stackoverflow.com/questions/16222748/build ...

4
4auka DomamaN, 2022-03-23
@dmn_202_01

Compile.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question