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 6 of 6

Thread: API in one file

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile API in one file

    Hello,

    I have an package called 'dunkscripts'.
    The file DunkTest.java uses this package.




    I want all the methods and classes used by DunkTest.java to be placed within the file itself, so it can be run 'stand alone', as one file. This is required for a program that loads DunkTest.

    How can i do this?
    Last edited by dunnkers; February 19th, 2011 at 11:08 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: API in one file

    If I understand your question correctly, then package it all into a jar. You can package them separately (eg the 'drunkscripts' in its own jar and add this to the class path of your DunkTest.java) or together - ultimately you get a single, runnable jar. You can find a lot of information online about how to do this, for example Packaging Programs in Jar

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: API in one file

    No, this is not what i meant. I need all methods and classes in one .java file, so it doesn't use anything outside its own file anymore.

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

    Default Re: API in one file

    Copy and paste all the code from the other files into DrunkTest.java

    However, this is generally a very bad idea. Java classes are suppose to be contained in their own class file and only in some specific situations do you want other classes/interfaces to be placed as member classes/interfaces (is that the correct terminology?).

    Why do you want all your code to be in one file?

  5. #5
    Junior Member
    Join Date
    Dec 2010
    Location
    New York
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: API in one file

    Yeah that is a terrible idea.
    You throw all the rules out the window for cohesion, modularity and good code design.

  6. #6
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: API in one file

    Yeah, it is a horrible idea. As it was needed for a program to run, it was the only solution. I now figured out the program can also load .jars and dir's (jars).

    Thanks though.

Similar Threads

  1. Replies: 10
    Last Post: January 12th, 2011, 05:48 AM
  2. insert(embed) a file object (.txt file) in MS excel sheet using java.
    By jyoti.dce in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 12th, 2010, 08:16 AM
  3. How to change File Type of a File Using java
    By akash169 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: March 31st, 2010, 02:58 AM
  4. Inputing file (.txt) and finding the highest number in the file
    By alf in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 15th, 2010, 09:11 AM
  5. Replies: 8
    Last Post: January 6th, 2010, 09:59 AM