0

I sincerely hope the answer to my question will be no.

I just wanted to quickly test a hypothesis on a simple java program (4 lines). I already tested that with C++ in Visual Studio where the experiment took 5 minutes.

Eclipse is different. First, I was unable to find where did it save my project - unlike NetBeans or Visual Studio, it doesn't provide Open in file browser option.

Afterwards I had to google up "create jar file eclipse" since Project -> build does not seem to produce a jar file, or anything else for that matter. The article I found is correct and works. But it has 10 steps and actually doing the thing takes long time because you have to specify the main class every time.

Is that normal? I make simple test programs quite often, this is definitely gonna slow me down a lot.

To clarify the question: How to quickly create a project and produce a jar file in Eclipse? (time limit 180 seconds)

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • It's still not clear exactly what you're trying to accomplish. Answers have been provided that explain a) creating a JAR isn't necessary to run tests of simple Java programs, and b) You can easily invoke **Export JAR** wizard from your project. Try to explain in more details what you're looking for. – E-Riz Jan 04 '16 at 15:32
  • I replied to every answer with a comment. I feel no need to justify the need to create jar files when programming in java, I thought it's obvious part of the process. Export JAR wizard is an advanced tool with many useful options, but definitely **not a quick** tool for beginners. I want what other IDEs provide: Create project, click build and have an executable ready. – Tomáš Zato Jan 04 '16 at 15:36
  • For long time eclipse users it is not obvious why a JAR is needed. I've written a 6 digit number of Java lines with Eclipse, and I've used the JAR export maybe 4 times during the years. – Bananeweizen Jan 04 '16 at 15:37
  • I lived under the impression jar files are used to distribute java programs (I do distribute mine that way). I wouldn't send my friend zip file full of `.class` files... I understand libraries can probably work differently, but I suppose majority of beginners will surely want to start with a single `jar` file that does something when you double click it. – Tomáš Zato Jan 04 '16 at 15:40

4 Answers4

0

You can always right click a project in Eclipse and pick the option "Export", which will lead you to create a jar/Runnable jar file. Another option would be to transform your projects into Maven Projects and then run maven install with the target packaging set to jar. Another way would be to directly compile your code using the javac : http://www.skylit.com/javamethods/faqs/createjar.html

Since you are testing small stuff, you have a lot of options which may fit you, and the answer is not bound to an IDE (Eclipse) for example

catacavaco
  • 55
  • 1
  • 1
  • 10
  • It is bound to IDE because the question has `eclipse` tag. I already did the test, my concern is how to do it next time so that it takes less than 10 minutes. – Tomáš Zato Jan 04 '16 at 15:31
0

Once you get used to it the eclipse tooling for java is no worse than that of netbeans. And I've never found building java applications with either tool to be much different than building c# projects in Visual Studio.

As for having a main class, not every type of application requires you to create one. It's no that much different than c++ is in that respect, is it?

Take a look at this thread:

Build project into a JAR automatically in Eclipse

It seems any number of those methods would take less than 3 minutes. And once you do it once (for example using an ant file), future builds will take seconds.

Also, look at this maven article:

https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Five minutes from the command line. The eclipse tooling will cut that down considerably.

Community
  • 1
  • 1
Robert Moskal
  • 21,737
  • 8
  • 62
  • 86
  • My question was more specific, I will try to edit and clarify. I want to know how to set-up the IDE so that I can make a new project and produce executable within 3 minutes. Currently it would take much more even though I already know exactly how to do it. Test application definitely does require main class - otherwise there's nothing to test. – Tomáš Zato Jan 04 '16 at 15:28
0

You don't have to produce a JAR to test a program in Eclipse. You can right-click on any class, package, or project that includes an appropriate main(String[]) method, and select Run or Debug.

E-Riz
  • 31,431
  • 9
  • 97
  • 134
0

Use Show in > System explorer from the context menu on the project (or any file) to open Windows Explorer (or whatever your OS uses).

If you just want to test some lines of code, there is no need to create a jar file at all, just use the Run As > Java application menu.

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
  • I needed a jar file to exist. I was verifying this answer: http://stackoverflow.com/a/10108158/607407 Also `System Explorer` is missing in my version. Maybe I have outdated IDE. – Tomáš Zato Jan 04 '16 at 15:31
  • Okay, totally reasonable. Was wondering a bit about the JAR requirement before I knew that. I still feel there is no faster way to create the JAR in Eclipse, as it is normally not needed. However, if you want to repeat the JAR export a lot of times, you could mark the "save as Ant script" checkbox during your first export, and then add an "Ant builder" to the project (via context menu, project properties, builders). This would then invoke the script during every build of the project automatically, in the background. – Bananeweizen Jan 04 '16 at 15:36
  • Ok thanks. However I hope you understand this is not fast either... Could I create one ant script and use it for every new project, every new test/experiment? – Tomáš Zato Jan 04 '16 at 15:37
  • 1
    Yes, your exact need is described at http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2FgettingStarted%2Fqs-93_project_builder.htm, if I get it right. – Bananeweizen Jan 04 '16 at 15:39