Meaningless Drivel is fun!*
The moose likes IDEs, Version Control and other tools and the fly likes Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Eclipse "nutshell" concepts for a Netbeans refugee?" Watch "Eclipse "nutshell" concepts for a Netbeans refugee?" New topic
Author

Eclipse "nutshell" concepts for a Netbeans refugee?

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

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?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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."


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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

Joined: Aug 11, 2007
Posts: 4646
    
    5

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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

Joined: Aug 11, 2007
Posts: 4646
    
    5

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

Joined: Aug 11, 2007
Posts: 4646
    
    5

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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

Joined: Aug 11, 2007
Posts: 4646
    
    5

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

Right click project
Properties
Java Build Path
Add jar
navigate to jars
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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

Joined: Aug 11, 2007
Posts: 4646
    
    5

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

Joined: Aug 11, 2007
Posts: 4646
    
    5

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: Eclipse "nutshell" concepts for a Netbeans refugee?
     
    Similar Threads
    Creating Build.xml for a project
    Maven: What's the big deal?
    Boggled by Eclipse - help!
    Getting Tomcat To Stop Trying To Open A Web App
    Eclipse projects on removable media