-2

I read and searched almost everywhere, yet i have no answer.

I have a project with multiple .java files, and i need to export them as a single .jar file.

One of the main questions is based on the fact that i don't have a main class. What can i do to go through that ? Shall i create a main but never run it? Or there's any way around?

Offtopic ( might be usefull): i want to do this in order to use the jar file in IKVM

Thank you!

noidea
  • 184
  • 5
  • 22
  • Do you want to _compile_ the Java files and then package them into a JAR or simply JAR them? – Tunaki Jun 03 '16 at 12:49
  • 3
    You do not convert java int jar. You compile java source code into .class bytecode files; and then you package one or more of these .class files (plus maybe additional other resources like pictures, properties, ...) into a JAR container. Plus: I think there is no **detour** for you. You will have to **learn** some of the essential java basics in order to master this. This is not something that can be given to you in a single SO answer. In other words: if you want to be an IT professional - then you **have** to understand the components in your system to a certain degree. – GhostCat Jun 03 '16 at 12:51
  • 2
    https://docs.oracle.com/javase/tutorial/deployment/jar/build.html – Romain Hippeau Jun 03 '16 at 12:58
  • @Jägermeister yes i didn't mean "convert" . English is not my native language, i tried to explain the best i can. And the main reason i want to .jar the files is because i don't work in java, and i'm trying to do it in .net .. – noidea Jun 03 '16 at 13:02
  • And so many downvotes.. yet the answers don't match each other. – noidea Jun 03 '16 at 13:02
  • @noidea I understood that you "don't work in Java". And I am telling you: this idea of yours will not work out. If you are the person who has to "integrate" that java code into something else - then you will be on the spot when that java code needs to be enhanced, changed, fixed. So you **have** to understand it to a certain degree. On the other hand, if you are **not** the person responsible for this code; then turn to **real** owner of that code, as he is then **responsible** for providing a "complete product". Anything else will lead into chaos. Believe me. – GhostCat Jun 03 '16 at 13:05
  • @Jägermeister Well, but there's a problem there. I'm trying to integrate two machines. One has libs like .dll or .tlb .. the other only .java ... Do you think the developers of the machine will do something to help me ? ( it's not a real question, i've asked them and they can't help me there ) – noidea Jun 03 '16 at 13:12
  • So you got your answer: you are the person **responsible** for that part of the system, thus you better understand what is going on. And honestly; I don't really understand your problem. If you are an IT professional, you should understand the idea of source code, compiled code, and build output artifacts. And the answer from micker should get you going into your first steps. If you are not ready or willing to get into the required learning, then you better tell your manager today that the intended plan doesn't work. Or ... as said: you start learning the essentials you will need for this job! – GhostCat Jun 03 '16 at 13:17
  • @Jägermeister Well thank you for your cooperation. I prefer people like you that say things directly, not going around . Ima find a way around this ! ( and i'll delete the post ). Thank you ! :) – noidea Jun 03 '16 at 13:21
  • You are welcome. Wishing you luck; however you go forward from here. – GhostCat Jun 03 '16 at 13:22

3 Answers3

3

You do not need a main method to create a jar. There are many such jars out there such as utilities packages. They don't contain any code that would make sense to execute on it's own since it only contains code that makes your application easier to write.

First compile your code using Netbeans or command line javac utility. This will give you .class files.

Now for creating the jar... You can simply create the jar (which is basically a glorified zip archive) by using the command-line jar tool.

jar -cvf my archive.jar myprogram/

Make sure that the file path within the jar archive match the package name of the classes. It is not uncommon to accidentally get an extra layer of directories.

You probably should have searched stackoverflow first since how-to-create-a-jar-file-in-netbeans seems to cover exactly what you're looking for.

Community
  • 1
  • 1
micker
  • 878
  • 6
  • 13
0

Do you want to use the jar as a external library or a program itself?

If it will be a external library, you don't need a main class. In eclipse you can export as a jar file (select classes-> right click-> export as jar).

If it will be a program itself, then you need a main class.

  • You said eclipse cause u work in eclipse or is it not available in netbeans? my network connection doesn't allow me to make big downloads.. – noidea Jun 03 '16 at 13:03
-1

You really need to create main class file, write code in function main(String args[]) which use your java classes and compile it by javac.

Alex Fly
  • 96
  • 9