Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Eclipse .java file without project and package creation

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Eclipse .java file without project and package creation

    I am beginner in Java and new to Eclipse. I initially used Edit Plus and I feel it very convenient to create .java file and compile it in the command prompt. I recently started using Eclipse but not able to create .java files without project and packages. As I am a beginner , I want to try lot of basic programs to understand the concepts for which packages and project not required.

    1 ) Can .java files be created and compiled in the Eclipse without project and package creation as I do it in Edit plus ?

    2 ) Also, when I tried creating a new project and want to put all the files that into that project. I right clicked the project and click import and selected the files. Now I have many .java files under my project same. I removed Exlcude buildpath for each .java file ( so that it recognizes different mains in each .java files - Not sure this is correct way of doing it or not ) and tried compiling it. But it shows error in the main function line. Though all are simple programs using Println, but I am not able to rectify the errors.

    I do not want to go back to Edit Plus as Eclipse is widely used and I want to get comfortable with Eclipse. Please do help.

    Thanks & regards
    Geek Bits
    Last edited by geekbits; October 25th, 2012 at 11:24 PM.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Eclipse .java file without project and package creation

    A package is just a folder to keep related files in.
    A project is just a folder to keep related packages in.

    In eclipse just create a new project, and give it a name. Project Hello (for example)
    Create a new package in the project. packagehello (for example)
    Create a new class in the package. HelloWorld (for example)
    Turn that class into the standard issue hello world class and run it. If it does not run post the exact error message so someone can determine what is out of place

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse .java file without project and package creation

    Thanks for the reply. I used to have two different folders in my drive. One is for .java files and other is for .class files ( ie ) I direct at the command prompt to put .class files in the specific folder using -d option.

    But when I create Project -- > Packages - then class ---- > .java files getting placed in Src ( source ) "filename.java " and .class files in bin folder. When I create a project it automatically creates src and bin as you know.

    I just want to create .java file and complie it in command prompt without package and project creation like in Edit Plus. Any way to get around ?

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Eclipse .java file without project and package creation

    You are basically asking how to use eclipse without using eclipse.

    This is how things are organized. The organization allows the IDE to make sure things are in order, to build and check things live as you type. It is the very heart of what any IDE has to offer.
    Do you not understand what is going on or do you just not like it?

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse .java file without project and package creation

    Thanks for the reply.

    I am asking whether any way to get around with options.

    If not, then I have already lot of .java files. I need to run this in Eclipse IDE. So I created a project and then package and imported the .java files . How to compile these files ? When I click ctrl + F11 and it says unresolved compilation and pointing to main function

    Edit == > Again did the above from first. can compile and run from Eclipse ; Also from the command prompt.

    In order to run in Eclipse, we must create project and packages even for simple hello world program.

    Thanks
    Last edited by geekbits; October 26th, 2012 at 02:24 AM.

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Eclipse .java file without project and package creation

    Quote Originally Posted by geekbits View Post
    Thanks for the reply.

    I am asking whether any way to get around with options.

    If not, then I have already lot of .java files. I need to run this in Eclipse IDE. So I created a project and then package and imported the .java files . How to compile these files ? When I click ctrl + F11 and it says unresolved compilation and pointing to main function

    Edit == > Again did the above from first. can compile and run from Eclipse ; Also from the command prompt.

    In order to run in Eclipse, we must create project and packages even for simple hello world program.

    Thanks
    That's one of the trade-offs with using Eclipse. It is able to provide those advanced tools for you because it has projects to manage the build process. Because the build process can be quite complicated the settings are quite extensive, and thus can be extremely over-kill for a simple program.

    Packages aren't really necessary but highly recommended. Eclipse will complain and moan about them being missing (or, Eclipse will complain that you're using the default package), but at the end of the day you can tell Eclipse to work without packages anyways.

    There are a few solutions:

    1. Don't use Eclipse and stick with your advanced text-editor. I do this from time to time.

    2. Deal with the fact that you have to create an Eclipse project every time.

    3. Create a test project which can house your small test projects. You can add as many Java files as you want to a single project (even multiple classes with main entry point methods), and since Eclipse will automatically compile all your classes and is fairly smart at figuring out which class entry point to start in (just open up the source file and make sure it's active in the editor), you can run each of these small projects inside a single Eclipse project without too much hassle. Sometimes I even take the laziness one step further and "cannibalize" a single class file, adding methods which perform some small test and modifying the main method to call the method I really want to start in. Furthermore, as long as the classes your entry point is in or relies on doesn't have any compile errors, you don't have to worry about other classes in the same project which won't compile or have bugs.

  7. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Eclipse .java file without project and package creation

    To what helloworld922 said, I think a mix of all three is about right. Especially 1 and 3.

Similar Threads

  1. Replies: 1
    Last Post: August 5th, 2012, 05:01 AM
  2. Replies: 3
    Last Post: September 19th, 2011, 03:42 AM
  3. Eclipse plugin - Analyzing a package
    By dunnkers in forum Java Theory & Questions
    Replies: 0
    Last Post: March 12th, 2011, 05:27 PM
  4. How to instal JDBC driver package in eclipse
    By sathish in forum JDBC & Databases
    Replies: 2
    Last Post: September 2nd, 2010, 10:09 AM
  5. WAR file creation in Eclipse JEE
    By katty in forum Java IDEs
    Replies: 5
    Last Post: May 21st, 2009, 09:45 AM