1

I have a working java project (in ubuntu 12.04LTS, configured and compiled using ant). Is there a way I can configure and run it in Eclipse? Every time I try to load it in eclipse it gives a bunch of errors because of packages not being where its expecting I guess. Also, it will help if you could tell whats build path. I'm using Eclipse Java EE IDE Kepler Release. My project structure looks like this:

project
  build.xml
  build.properties
  build.common
  projFolder - proj code, 3rd party lib/bin/src, 
  commons - proj code, ui code, 3rd party lib and binaries
  dist - has a bunch of scripts and jars and may be some binaries

And how I got my project in Eclipse (this is probably not the most efficient way to have the project running in Eclipse, not sure) I did new->java project then enter project name, unchecked 'use default location' and provided the location of my project so it imported my project in eclipse. then in my classes i have all the errors (red cross at the display) and it says imports cannot be resolved, objects can't be resolved to a type and such.

import com.psid.codedata.projects.TProjectDRD; import com.psid.codedata.projects.TProjectsDRD;

error on above imports: The import cannot be resolved

pink panther
  • 31
  • 1
  • 2
  • 6
  • Welcome to Stack Overflow! Please edit your question to include the steps you use to import your project into Eclipse and the exact error messages you get. – Code-Apprentice Jun 27 '13 at 17:05
  • I do new->java project then enter project name, uncheck 'use default location' and provide the location of my project so it imports my project in eclipse. then in my classes i have all the errors (red cross at the display) and it says imports cannot be resolved, objects can't be resolved to a type and such. – pink panther Jun 27 '13 at 17:16
  • By paraphrasing error messages, you have removed important information we need in order to help you. Be sure to include *complete* error messages along with the code that causes the error. – Code-Apprentice Jun 27 '13 at 17:59
  • possible duplicate of [importing ant build.xml in eclipse](http://stackoverflow.com/questions/3880350/importing-ant-build-xml-in-eclipse) – Code-Apprentice Jun 27 '13 at 18:04
  • My question is how to successfully import my project with the ant build file in Eclipse? Also, how to set the class path and do all the jars I have in multiple locations need to go in one folder? – pink panther Jun 27 '13 at 18:04
  • I have given you a link to the answer to the first part. – Code-Apprentice Jun 27 '13 at 18:06
  • I have tried that before , it only imports build.xml for me not my source code. – pink panther Jun 28 '13 at 15:50
  • I've used those steps successfully myself. I suggest that you try again and keep notes about the steps you follow and descriptions of the problems you follow along the way. Feel free to come back with this detailed information and we can help you from there. – Code-Apprentice Jun 28 '13 at 22:45

3 Answers3

1

It probably needs you to add all your source folders to the build path:

  1. Right-click on your project and select Properties,
  2. Along the left-hand side click "Java Build Path",
  3. Click the "Source" tab if it isn't already selected,
  4. Click the "Add Folder..." button on the right-hand side,
  5. Select whatever your source folders are in projFolder and commons,
  6. Click the "Libraries" tab,
  7. Click the "Add JARs..." button on the right-hand side,
  8. Select whatever your libraries are in projFolder, commons and dist,
  9. Click the "OK" button.
davidfmatheson
  • 3,539
  • 19
  • 27
  • it looks like my project already has src folders and jars added to the classpath and lib by default – pink panther Jun 27 '13 at 18:37
  • Is `com.psid.codedata.projects.TProjectDRD` import from a JAR or from a source folder? – davidfmatheson Jun 27 '13 at 18:43
  • I don't see this file in source code so good chances it could be in jar. Is there a way to see which jar it would be from? I have over 1000 jars used in this project. Also it would help me to be able to get to the .class file for debuggin purposes. Thanks. – pink panther Jun 27 '13 at 19:06
  • alright I could spot the class file in a jar but when i goto lib and try to add that jar its path doesnt come up in lib -> add jar project drop down menu. Why is this? I have that particular src file added in Java build path source. – pink panther Jun 27 '13 at 19:28
  • aha! that was it! I had to do add external and it resolved the error. It'll take me a while to manually add all the jars. But once done i guess it should work. Thanks for your help. – pink panther Jun 27 '13 at 19:50
  • If the JAR is within your project, it should show up in "Add JARs...". If it is outside the project, use "Add External JARs...". – davidfmatheson Jun 27 '13 at 19:58
  • Its in the my project but for some reason didn't get imported in Eclipse, so I had to add them as external :/. I wish there was a way it could get all the jars in the project automatically since I have too many and adding them manually can be very time consuming – pink panther Jun 28 '13 at 15:48
  • If the JAR is beneath the top-level folder that represents your project, you should be able to add them with "Add JARs...", which allows multi-select, so you should not have add them one by one. – davidfmatheson Jun 28 '13 at 17:32
0

Note that "New -> Java project" is for creating a brand new, empty project. Since you want to create an Eclipse project from an existing project with an Ant script, you should select the appropriate selection under the "Ant" subsection in the New Project dialog. See this answer to a related SO question for details.

Community
  • 1
  • 1
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • when i do import "existing projects into workspace" and specify my project folder, it doesn't really find any of the projects to import. Please help how I could have eclipse identify my projects I have very less clarity here, if it helps I have several daemons that need to start before I could run my real project, those daemons are also included in the src code – pink panther Jun 27 '13 at 18:42
  • "existing projects" refers to existing *Eclipse* projects, not just existing Java source code (with or without an Ant build file). You need to use the option to import a project with an existing Ant build file as described in the link I gave. – Code-Apprentice Jun 27 '13 at 20:38
0

add this line to nbproject/project.properties:

j2ee.server.home=http://localhost

Puneet Pandey
  • 960
  • 2
  • 14
  • 28