• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Eclipse "nutshell" concepts for a Netbeans refugee?

 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been using NetBeans for a very long time, maybe 10 years. Long ago, maybe 6 years ago, I tried Eclipse and didn't think it fit as well as Netbeans did for the way I work. But NetBeans doesn't have the rich corporate sponsorship that it used to have, and Eclipse is getting lots of support. So i've often wondered if I should switch back to Eclipse. Recently, Netbeans's latest update broke tons of my stuff, and its time to look long and hard at Eclipse.

I've got Eclipse installed and written the "hello world" sample. So far so good.

But I don't understand what the equivalents are in the Eclipse world. Can someone provide me a quick cheat sheet overview?

For example, all of my Netbeans code is in git, in directories under my sandbox. A Netbeans "Project" is simply a directory, and under that directory
you have subdirectories for the source files (src) generated .class files (build) and the resulting jar/war (dist), plus of course, the 'nbproject' directory with all the magic config files for the project so that netbeans can know what to feed ant for the actual build.

Eclipse has "workspaces" and other directories/projects, but I can't figure out the mapping.

Googling gets too many hits to be useful, and the main ones deal with migrating from netbeans to eclipse (including a lot of links to an old thread here on the 'ranch).
I don't care so much about automated migration, but rather about best practices and mental translations.

Can anyone help give me the overview?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Eclipse, a project is a bunch of files that will generate an artifact - jar, war or ear - usually. It has a .project and .classpath file used to tell the project where to look for files. There isn't an automatically generated Ant file. Eclipse doesn't use Ant to do the build. There also isn't a "main project."
 
Pat Farrell
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

I have one git repository that has three targets:
1) a jar file of business objects and related stuff that gets used by the next two
2) a jar file that creates stand alone utility programs that manipulate the business objects
3) a full blown Web app, with HTML, JSP, beans, servlets, etc that manipulate the business objects onto the client's web browser

In NetBeans lingo, these are three "projects" that generate there own JAR (or WAR) files. Of course, the third WAR files contains the JAR file
from the first, plus lots more like Log4J, JDBC, Guava, etc.

What is the proper Eclipse lingo and setup for this?
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pat Farrell wrote:Thanks.

I have one git repository that has three targets:
1) a jar file of business objects and related stuff that gets used by the next two
2) a jar file that creates stand alone utility programs that manipulate the business objects
3) a full blown Web app, with HTML, JSP, beans, servlets, etc that manipulate the business objects onto the client's web browser

In NetBeans lingo, these are three "projects" that generate there own JAR (or WAR) files. Of course, the third WAR files contains the JAR file
from the first, plus lots more like Log4J, JDBC, Guava, etc.

What is the proper Eclipse lingo and setup for this?


Three projects as well. You have two Java projects and one web project. The jars live in the web project in the WEB-INF/lib directory like you are used to. The web project points to your other two projects as project dependencies. The jar projects reference the web project's jar files in the classpath for compilation purposes. When you are ready to export the web project, it will grab the java projects (making them jars) too.

(Presuming you aren't using Maven. If you are, that changes everything.)
 
Pat Farrell
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote: When you are ready to export the web project, it will grab the java projects (making them jars) too.

(Presuming you aren't using Maven. If you are, that changes everything.)



Thanks.

I'm not using Maven in my projects, altho a fair number of the libraries that I use are built with it. I tried to learn about poms, and my head was spinning.

What does "export" mean in this context? Does that mean "build the jar/war?"
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pat Farrell wrote:What does "export" mean in this context? Does that mean "build the jar/war?"


Yes. See you are catching on to Eclipse speak .
 
Pat Farrell
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Yes. See you are catching on to Eclipse speak .



I'm sure it will do everything I need, but there is a language and a cultural divide that I must cross.

I'm keeping notes and will post the whole journey on my webpages.
 
Pat Farrell
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the best practices for JUnit test code within an Eclipse project?

In NetBeans, they would have a separate, parallel source tree "test" to the usual "src" tree. Thus if the package was com.pfarrell.foo there would be two trees:

src/com/pfarrell/foo
and
test/com/pfarrell/foo

Hmmm, is there a handy link to using JUnit with Eclipse?
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know of two approaches:
1) Have parallel projects:
Project
- src
- com/javaranch/....
Project.junit
- src
- com/javaranch/...

2) Have one project: (this is the Maven directory structure)
Project
- src/main/java
- src/test/java

#2 works well if you are allowed to have test code in your jar. Or you are using Ant or Maven to build the code.
 
Pat Farrell
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Next question, this has to be easy.


I've created a 'lib' directory in the project, along with bin and src
Into the lib, I put the usual libraries, log4j, guava, jdbc drivers, etc.

How do I tell the project that the lib directory is there and belongs on the classpath for compiling, debugging and "exporting"
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right click project
Properties
Java Build Path
Add jar
navigate to jars
 
Pat Farrell
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Right click project
Properties
Java Build Path
Add jar
navigate to jars



This lets me add each jar.
Is there something that will add the subdirectory to the classpath so that any jar will work?
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pat Farrell wrote:

Jeanne Boyarsky wrote:Right click project
Properties
Java Build Path
Add jar
navigate to jars



This lets me add each jar.
Is there something that will add the subdirectory to the classpath so that any jar will work?


You can add all the jars currently in a directory at once. You can't add any jar that might appear in the directory in the future/
 
Pat Farrell
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:You can add all the jars currently in a directory at once. You can't add any jar that might appear in the directory in the future/



OK, so its not really the classpath. Its a fairly easy way to specify the jars to include.

Thanks
 
Pat Farrell
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pat Farrell wrote:What is the best practices for JUnit test code within an Eclipse project? ...Hmmm, is there a handy link to using JUnit with Eclipse?



When I google for junit and eclipse, there are zillions of hits. Many describe how to use JUnit with versions of Eclipse from many years ago, and are clearly out of date.

I think I have JUnit properly plugged-in or whatever the phrase is for eclipse, and there is a right-click menu option to run a file as a test. But I am still missing at least two things:

1) I can't find the jar file for Junit itself. In Netbeans, they automatically link in the junit.jar for testing, and not include it for production use. I can't even find the jar, let alone figure out how to selectively link it in when appropriate.

2) I don't see any option to run all the Junit tests for the whole project. I tend to write a lot of JUnit tests, and run them all a lot. Many hundreds of test source files. I really don't want have to kick each one off manually
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pat Farrell wrote:1) I can't find the jar file for Junit itself. In Netbeans, they automatically link in the junit.jar for testing, and not include it for production use. I can't even find the jar, let alone figure out how to selectively link it in when appropriate.


  • Right click project to view build path
  • Add library
  • JUnit
  • Select version of JUnit if more than one choice



  • Pat Farrell wrote:2) I don't see any option to run all the Junit tests for the whole project. I tend to write a lot of JUnit tests, and run them all a lot. Many hundreds of test source files. I really don't want have to kick each one off manually


    Click on the source directory in the project and then do run as - junit test. This will find all the test classes in that directory and subdirectory running them all as one suite. If you want to restrict by package name, you can create a class that specifies them using ClasspathSuite
    reply
      Bookmark Topic Watch Topic
    • New Topic