11

I'm new to Java Programming using Eclipse, so would really appreciate your help for this question.

I have doing Java programming both at college and home. At home, I have all my Java classes under a single project-(Java Reference). Now, in college, the java programs are compiled on the lab machines. And I would really like to have all these programs in a single project, on my laptop.

I had recently copied all the .class and .java files from the programs we did in college labs, so I could have them under the "Java Reference" project in my laptop. I copied the .class and .java files under the "bin" and "src" folders of the java project, on my laptop. However, I don't see anyway to import them through Eclipse.

From what I read here, it looks like having an entire project(created somewhere else) could be copied into one place, through the import option, but in my case, I only have the .class and .java files.

3
  • 2
    after you copy your .java files into src folder, have you refreshed the src folder in eclipse ide ? Commented Nov 24, 2013 at 2:48
  • 1
    Show your current JavaReference file structure. Commented Nov 24, 2013 at 2:50
  • @user3020494 ten years down feature is not yet available. Looks Oracle is still working on refresh issue. Commented Aug 4, 2022 at 5:18

5 Answers 5

10

First, you don't need the .class files if they are compiled from your .java classes.

To import your files, you need to create an empty Java project. They you either import them one by one (New -> File -> Advanced -> Link file) or directly copy them into their corresponding folder/package and refresh the project.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 for the solution, I was looking for something similar. I would be good though if you have several files to be able to link them all at once. Thank you!
I do not see "New -> File" anywhere. Only "New -> Class" and "New -> Project". I am using Eclipse 4.7.3a.
7

create a new java project in Eclipse and copy .java files to its src directory, if you don't know where those source files should be placed, right click on the root of the project and choose new->class to create a test class and see where its .java file is placed, then put other files with it, in the same directory, you may have to adjust the package in those source files according to the new project directory structure.

if you use external libraries in your code, you have two options: either copy / download jar files or use maven if you use maven you'll have to create the project at maven project in the first place, creating java projects as maven projects are the way to go anyway but that's for another post...

1 Comment

maybe worth it to note i had to right click on the src folder and refresh before it was visible.
7

You can import a bunch of .java files to your existing project without creating a new project. Here are the steps:

  1. Right-click on the Default Package in the Project Manager pane underneath your project and choose Import
  2. An Import Wizard window will display. Choose File system and select the Next button
  3. You are now prompted to choose a file
  4. Simply browse your folder with .java files in it
  5. Select desired .java files
  6. Click on Finish to finish the import wizard

Check the following webpage for more information: http://people.cs.uchicago.edu/~kaharris/10200/tutorials/eclipse/Step_04.html

1 Comment

Please do not post an answer that consists essentially of a link. Include the important points in your answer; leave the link for extra information or as a reference.
2

import class folder does not work for me, but add jar worked!

1. put the class folder under the project folder

2. Zip the class folder

3. Highlight project name, click "Project" in the top toolbar, click "Properties", click "Libraries" tab, click "Add External jars".

4. Add the zip file. Done!

1 Comment

Wow, thank you! Totally works to import class files instead of java ones.
1

I had the same problem. But What I did is I imported the .java files and then I went to Search->File-> and then changed the package name to whatever package it should belong in this way I fixed a lot of java files which otherwise would require to go to every file and change them manually.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.