tags:

views:

91

answers:

8

Hi,

I've been tasked with picking up someone elses Java code and adding some functionality to it.

I'ved pull down the source tree from CVS and see a bunch of .jar files in different folders. I'm guessing the developer did not use Eclipse.

I am new to Java (coming from .NET background) and have used Eclipse so far to create one Java project. I'm wondering now that I have this guys files (he has classpath.jar and other .jar files along with some subfolders each with 'java' files in them), how do I open them? I tried opening one at a time, etc.. but doesn't seem to work. IS tehre an easy way to do this? I thought there' might be some kind of 'import existing code' thing in Eclipse but I can find it. How can I do this? Do I re-create the folder structure and just add the existing files one a time?

Thanks much for any help

+4  A: 

something like 'create project from existing source'?

http://www.stanford.edu/class/cs108/JavaTools/eclipse-guide/

if the existing code is not structured well, you are either going to have to heavily configure your project sources, or just change the project structure.

hvgotcodes
I did File->New Java Project (give it name) -> Next -> Link Addictional Source -> Finish
dferraro
This gives me 2 issues - when I pick JRE1.5 it says bunch of errors about 1.5 not supporting the code when I try to open a .jar file. When I do this same thing but for JRE 1.6, when I try to open the .jar file it says 'Failed to load Main-Class attribute...'
dferraro
+1  A: 

File -> new

Than select general->folder.

To make developing easier in eclipse i recommend some refactoring to the project.

Mark Baijens
I tried doing this. When I get to the 'New Folder' dialog it says 'This specified project does not exist'... when I put the folder in 'parent folder' textbox. FYI im using windows XP JRE 1.6
dferraro
+1  A: 
  • create a new eclipse project using the parent folder as the home.

  • every folder that's the root of a hierarchy of java classes becomes a folder in the "source" tab (either on creation, or add through "project->properties").

  • every jar (at least the ones he's using, there may be extras) gets added in the project->properties libraries tab.

This is assuming that all of the hierarchies belong together and that the thing isn't structured to build little sub-projects out of pieces of the hierarchy. If there's a build file for this thing you might want to be sure that if the build file is doing that you're building things appropriately.

Steve B.
+1  A: 

File->Import->General->Existing Projects into Workspace

OR

File->New->Java Project

This will create a sample java project for you. You can add the files appropriately.

Below is an example of a j2ee Project:

http://java.sun.com/blueprints/code/projectconventions.html

sjt
+1  A: 

If C:\Workspace is the folder you are using as the workspace and you have your existing project placed as "C:\Workspace\ExistingProject"

  1. Open Eclipse Got to File->New Project
  2. Select the type of Project you want to create Use the name as "ExistingProject" for the project and click Finish or complete the remaining steps of project creation wizard normally.
  3. Internally a .project file would be created in the ExistingProject folder and a .metadata folder would be generated under Workspace folder.

If you want to place the ExistingProject not under the workspace u follow the same steps.

frictionlesspulley
+1  A: 

There's 2 possibilities:

Import project from file system:

  • Create a blank Eclipse Project.
  • Then select File -> Import -> General -> File System. Select project, and point it to your created project.

Importing from CVS

  • Goto File -> Import -> CVS -> Project from CVS
  • Enter your CVS Host, Repository Path, Username and Password, and click next,....
  • Add what you need and click next (follow the instructions) until you're satisfied and click finish.

Hope this helps.

A simple tutorial that incorporates my 1st option and commmits it to CVS: http://thedesignspace.net/MT2archives/000662.html

The Elite Gentleman
+1  A: 

Two options:

Maven - highly recommended but rather read this: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html than have me re-write it here. Maven might seem like more effort up front but it pays for itself a hundred times over during the course of even a simple project.

Do it yourself (assuming Helios):

  1. Move the source code Java files to ~/development/MyProject/src/java. Move the jars to ~/development/MyProject/resources.
  2. In Eclipse, File > New > Java Project. Type in your project name.
  3. Untick "Use default location" and browse to ~/development/MyProject.
  4. Select src/java as your source folder (if Eclipse doesn't pick it up automatically).
  5. Finish.

Then, for each error, you will need to find the corresponding JAR and add it as a library to your classpath in the project properties.

The important thing to bear in mind is that Eclipse is not like Visual Studio - you cannot easily just edit one file at a time and that is not what it is designed for. People can get frustrated with Eclipse after working with VS but if you just allow it to do things the way it wants you, your life will be much easier.

alpian
+1  A: 

trick is finding the root folder. Generally, developers use the following:

project root  
   -- src  
   -- bin  

at least, what's what Eclipse does by default. There are other ways it can be organized as Maven uses the following:

project root
  -- src
  --  --  main
  --  --  --  java
etc...

More info on how Maven standardizes here:

That said, finding out how the source is organized shouldn't be too hard. Open up one of the .java files and look for the line at the top that starts with "package ". Should be something like this:

package com.somecompany.client.utils

Note, that's just an example, it won't be that exactly although it should start with "package". The value after package represents the path that the file should be in relative to the root of the source folder.

source folder/com/somecompany/client/utils

So, if you follow the default way that Eclipse organizes things, it should look look like this:

project root
  -- src
  -- -- com
  -- -- -- somecompany
  -- -- -- -- client
... etc

SO, as other people have mentioned, you'll import from existing filesystem, point to the folder at the project root. You may need to configure it to point to "src" folder as a source folder. You may also need to import those .jar files into your project as well.

Good luck

Bryce Fischer