Eclipse (How to add file to Project?)

Discussion in 'Java' started by Duke McPherson, May 8, 2006.

  1. Using Eclipse, how do you get an existing java file to become part of
    the project, so that other java files can use it (equivalent to
    #include in C)? This seems like it should be easier than it is...

    Thanks!
    Duke McPherson, May 8, 2006
    #1
    1. Advertising

  2. Duke McPherson

    Larry Guest

    Duke McPherson wrote:
    > Using Eclipse, how do you get an existing java file to become part of
    > the project, so that other java files can use it (equivalent to
    > #include in C)? This seems like it should be easier than it is...
    >
    > Thanks!


    If it is a JAR file you want to add, goto Projects -> Properties ->
    Java Build Path and select "Add External JARs".
    Larry, May 8, 2006
    #2
    1. Advertising

  3. Duke McPherson

    IchBin Guest

    Duke McPherson wrote:
    > Using Eclipse, how do you get an existing java file to become part of
    > the project, so that other java files can use it (equivalent to
    > #include in C)? This seems like it should be easier than it is...
    >
    > Thanks!
    >

    You did not specify if this is a java source and or class file. There
    are at least three two ways to do what you want to do.

    First
    - put your target file into a jar file.
    - Right click on your Eclipse project and select "Properties"
    - Select "Java Build Path"
    - Select "Add External Jar" and add that jar file you created
    - Your project now has access.

    Second
    - Select main menu Windows\Preferences\Java\Build Path\Classpath Variables
    - Add a path to your external code
    - then you can add to your projects

    Third
    - Create a project in Eclipse for you external code.
    - House it here
    - Any other project that wants to reference this code the do the
    following:
    - Right click on your Eclipse project sand select "Properties"
    - Select Project references
    - Select the project you just created do that


    Thanks in Advance...
    IchBin, Pocono Lake, Pa, USA
    http://weconsultants.servebeer.com/JHackerAppManager
    __________________________________________________________________________

    'If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)
    IchBin, May 8, 2006
    #3
  4. Duke McPherson

    Oliver Wong Guest

    "Duke McPherson" <> wrote in message
    news:...
    > Using Eclipse, how do you get an existing java file to become part of
    > the project, so that other java files can use it (equivalent to
    > #include in C)? This seems like it should be easier than it is...


    Two others have given you some answers. Note that "#INCLUDE" in C is a
    preprocessor directive, and is part of the preprocessor language. It's
    independent of any IDE. That is, the #INCLUDE directive should function the
    same way whether you're using Notepad, Emacs, vi, or anything else.

    The way you've phrased your question makes it sound like you're asking
    about how to do something specifically within Eclipse, which is why the
    others have given the answers they did. If they answered the "wrong"
    question, you should probably clarify this inconsistency above.

    - Oliver
    Oliver Wong, May 8, 2006
    #4
  5. IchBin wrote:
    > You did not specify if this is a java source and or class file. There
    > are at least three two ways to do what you want to do.


    Java source file. I already have my Eclipse project. I just want
    other .java files to be part of the project.

    Thanks for the help!
    Duke McPherson, May 9, 2006
    #5
  6. Duke McPherson

    James McGill Guest

    On Mon, 2006-05-08 at 16:28 -0700, Duke McPherson wrote:

    > Java source file. I already have my Eclipse project. I just want
    > other .java files to be part of the project.



    Put them in the correct dir under your project, and hit File->refresh in
    Eclipse.
    James McGill, May 9, 2006
    #6
  7. Duke McPherson

    IchBin Guest

    Duke McPherson wrote:
    > IchBin wrote:
    >> You did not specify if this is a java source and or class file. There
    >> are at least three two ways to do what you want to do.

    >
    > Java source file. I already have my Eclipse project. I just want
    > other .java files to be part of the project.
    >
    > Thanks for the help!
    >

    OK.. Just select you project or package you want load then into:

    - right click and the select "Import"
    - Select file system
    - Browse to the when the programs are then select the ones you want
    - Then "finish"


    Thanks in Advance...
    IchBin, Pocono Lake, Pa, USA
    http://weconsultants.servebeer.com/JHackerAppManager
    __________________________________________________________________________

    'If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)
    IchBin, May 9, 2006
    #7
  8. Thanks you guys, that worked. ; )
    Duke McPherson, May 9, 2006
    #8
  9. Duke McPherson

    Alex Guest

    Easiest way is drag/drop java file from your windows folder to folder
    inside Eclipse (not Windows! Just in the Eclipse!).
    Alex, May 9, 2006
    #9
  10. Duke McPherson

    JimDanz

    Joined:
    Aug 10, 2009
    Messages:
    1
    Thank you James, this is exactly what I needed.
    JimDanz, Aug 10, 2009
    #10
  11. Duke McPherson

    piyushgupta77

    Joined:
    Jun 1, 2012
    Messages:
    1
    using Jar files in a Java project

    I have made a java class named "JavaApplication5.java" .

    The class has following structure:

    public class JavaApplication5 {

    public static int app5_int;

    public JavaApplication5()
    { app5_int=111;
    }
    public static void main(String[] args) {
    app5_int=1;

    System.out.println("In main");

    }

    public static void fun(){
    app5_int=11;
    }

    }

    I have generated a jar file named "MyJarFile.jar" of this Java file .

    Now I want to use this jar file into another Java project and want to read value of integer variable app5_int .

    I have included the jar file in new project but still I am unable to access any of the class, data members of jar file .
    piyushgupta77, Jun 1, 2012
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. javaguy44
    Replies:
    1
    Views:
    982
  2. Gunter Hansen
    Replies:
    10
    Views:
    41,641
    Paul Hamaker
    Apr 3, 2006
  3. Garg
    Replies:
    1
    Views:
    384
  4. Veerle
    Replies:
    0
    Views:
    1,352
    Veerle
    Mar 13, 2009
  5. Stephane Wirtel
    Replies:
    0
    Views:
    120
    Stephane Wirtel
    Jul 5, 2007
Loading...

Share This Page