Organizing java projects, packages

I'm making an application that has about 50 classes. I am using the project to learn how to do a lot of things, but one is how to use packages. I would like to get your comments on what I've done, since I've never done this before.
I set up a directory called /java/classes/package_name/ for all my .class files.
Likewise, /java/src/package_name/ has the source files.
Now, I'd like to be able to build all the source files and put them into the appropriate class path directory. Is there a standard way of doing this? Do you use make? I like make, but is there a better tool? I like simple things.
I have several classes in my package that have mutual dependencies. I think this is a bad thing, but it's because some of them are input dialogs and such, so I couldn't think of any way to handle buttons and input fields other than to have some mutual dependencies.
I can't compile them at all because they depend on each other (or so I think). Is there a standard way to organize the GUI files like this? Do they not even belong in a package?
If they don't belong in the package, where do they belong?
I also want to be able to package this up nicely in a jar file or something so I can give it to friends to run (it's a game with some 2D graphics). I would have to include the class files in package_name package, but how do i related them to the main class when I jar them up?
There are actually two programs that use all most of the files, and there could be more later.
Thanks very much ahead of time; I appreciate all your info and tips.

I am not opposed to learning to use Eclipse for Java type things,Good, good, good... also download and play with Netbeans, among others... use the one which suits you most... I use several IDE's for different jobs.
but I'd rather learn to do it manually first. Otherwise I will by as mystified as ever when things go wrong.You'll go far. A BIG downside of the modern IDE's automatic build-and-deploy features is they hide all the "plumbing", which is great as long as it works, but leaves the user (esp noobs) totally at a loss when something goes wrong, coz the user doesn't even what should be happening... let alone what's not happening, or why, or what to do about it.
Resolving dependencies like you suggested works fine when you don't have mutual dependencies.AFAIK the Java compiler doesn't have a problem building classes with "mutual dependencies"... for instance if class A uses class B which uses class A the compiler doesn't require a definition of type B (trusting that such will be forthcoming) when it compiles A... it then compiles B... and the picture is complete.
An experiment to dis/prove the above notion
package forums;
public class A {
  public final String message = "A";
  public static void main(String[] args) {
    A a = new A();
    System.out.println(new B(a).message);
class B {
  final String message;
  B (A a) {
    this.message = a.message + "B";
}This works, so I don't get the whole "Resolving dependencies" problem. Do you know something that I don't?
Javac "follows" dependendencies automatically, as long as the files are in the expected place.
Me thinks you're just having classpath issues... you're directory structure must EXACTLY match your package structure... and remember that Java is cAsE sEnSiTiVe, even if the underlying operating system is not... ie: I think the "circular dependencies" problem is a furphy.
Read that classpath article... of you're still stuck give us a yell and we'll work through compiling and running the above program.
Cheers. Keith.

Similar Messages

  • Packaging and installing a java project

    Hi everyone,
    I have a java project which has been developed in Eclipse IDE. I would like to package the project so that i it can be installed and can be run as a stand alone product.
    Any tools that would help me do packaging and installing a java project?
    Thank you.

    Easiest way to package a Java project is to create an executable jar for it. You probably should google for more information on the 'jar.exe' program (sry for window bias)
    If you have external dependencies you should put those in separate jars and include them in the classpath in the jar manifest file.
    The only other thing to worry about is getting java installed on other people's machines. In general it is best if possible to have them download java themselves as they will get the latest and greatest from this website. If that's not possible you may want to look into getting sun's permission to distribute Java with your app.

  • [Urgent] using javafx object in java project

    Suppose I here created a very simple java project and the main file is like below,
    public class test {
        public static void main(String[] args){
                System.out.println("Hello World!");
    }and in this particular java project, I need to use another javafx object which is defined as (the javafx and java file are in the same package),
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Circle;
    var stage: Stage = Stage {
        title: "Declaring Is Easy!"
        scene: Scene {
            width: 300
            height: 250
            content: [
                Circle {
                    centerX: 150  centerY: 120 radius: 80
                    fill: Color.MAROON
                    stroke: Color.INDIANRED
                    strokeWidth: 10.0
                }, //Circle
                Rectangle {
                    x: 25, y: 80 width: 250, height: 80
                    arcWidth: 20 arcHeight: 20
                    fill: Color.web("#6699ff")
                    stroke: Color.web("#003399")
              strokeWidth: 5.0
                } //Rectangle
            ] //Content
        } //Scene
    } //StageSo how could I achieve this?
    Regards.

    Thanks for your reply.
    But would you please elaborate on this sentence: create the fx class using Class.forName("....").newInstance()?
    Indeed I implemented an interface which was extended by the javafx class, and in the main java file I need to write following codes to use this object,
    Context context = FXLocal.getContext();
            FXClassType instance = context.findClass("packageName.JavaFXClass");
            ObjectValue obj = (ObjectValue)instance.newInstance();
            JavaInterface ji = (JavaInterface)obj.asObject();The problem that I encountered right now is, the exception was thrown at context.findClass("javatest.MyChart");, since it's not able for the compiler to find the JavaFXClass.class.
    I checked the folder build\classes\packageName and noticed that both my main JavaClass and JavaInterface have been compiled with .class file, while the JavaFXClass was not, which means the file JavaFXClass.class doesn't exist.
    What's the solution?

  • Open Forte for java project in Sun java studio enterprise

    Hi Everyone, I am new to Java development. I have a java application developed in Forte for java 4 and I need to open and compile it in Sun java studio enterprise. Could anybody tell me how to do that? Thank you very much.

    The recent versions of the IDE (starting with NetBeans 4.1 and JSE 8) are based on a more-robust project system that is ant based. Projects from Forte for Java 4, unfortunately, cannot be directly opened in JSE8, NB4.1 and later.
    If you do have access to the original source code, pl. try the following in the latest version of JSE or NetBeans:
    - Create a fresh project in jse using File | New Project. (For a java standalone app, you would choose General | Java Application from the dialog).
    - Add the existing files to the empty project. You can do so by right-clicking on the project, selecting properties and adding the existing source directories under 'Source Packages' in 'Sources' category.
    Or from the new project dialog, you could select 'General | Java Project with existing sources' option.

  • How to Compile java project on command prompt

    Hello Friends,
    I have created one java project in eclipse. It has 3 packages, 4 external jars and one Link source (meaning it uses other java package that is not in the same project folder)
    It runs perfectly using eclipse.
    Now I want to compile my project and want to run that project.
    I tried using "javac -classpath........." but it didn't work for me. Here is the command I used:
    I am running this command under my main project folder
    javac -classpath ./../../../lib/tools/lib/blur/blur_formats-1.0.jar;./../lib/commons-codec/commons-codec-1.3.jar;./../lib/commons-httpclient/commons-httpclient-3.1.jar;./../lib/commons-logging/commons-logging-1.1.1.jar;./../lib/org.json/org.json.jar;./../lib/smack/3_0_4/smack.jar;./../../../device/branches/viper/Service/blur/common/push/src* ./src/com.proj.hnm.push.StartService.java*
    1) /device/branches/viper/Service/blur/common/push/src - is a different package I am referring (not in my current project folder) - it has java files in com.pushsync package
    2) ./src/com.proj.hnm.push.StartService.java is my main class, com.proj.hnm package also contains another 2 package, and those other packages also have .java files
    Please tell me how do I run my java project?
    Thanks

    Hi
    Since it works fine in Eclipse you should install the [Fat Jar eclipse plugin|http://fjep.sourceforge.net/] which will pack everything thats in your eclipse project into a single jar file. Then you can run: java -jar myProject.jar and it should work.

  • Project / Package structure..

    Hi
    I am currently prototyping some relatively simple BC4J / Struts / JSP applications in JDev.
    I have followed the toystore demo which seems to have a nice clear and logical project / package structure for working with the MVC architecture.
    However, i have found it very difficult to actually recreate this template when building my own prototypes using the built in wizards.
    Example :
    I have a Model.jpr separated into packages for BO / VO / services.
    I want to create my Struts components (action classes and xml config) in a Controller.jpr and my presentation JSPs in a View.jpr
    When using the web-tier wizards (JDev9.03) for a "complete struts based application" i can see no clear way of separating out the components ? It will package up the action classes into a package that i had no choice in creating / naming !?
    I realise that if i use the subset wizards i have more control over where components are created (i.e. create an empty struts-xml, then add individual action classes etc. ) but it seems a shame that we can't do this within the complete application wizard.
    Also,is there a way to create a new package without creating a "empty" business components package ? I have found myself creating the folder structure from windows explorer with a dummy java file in the relevant directory, then importing and editing the class to ensure compliance with my project design ?
    How do you guys achieve these goals ?
    Thanks in advance
    Matt

    Bump.

  • UML modeling by reverse-engineering a JAVA project

    I can't seem to get over a basic hurdle to get started with UML modeling. I open an existing JAVA project. I then start a new project and choose "UML" and "-Platform model by reverse-engineering a JAVA project". Next I give the UML project a name and try to open my existing JAVA project. But the wizard does not show any project!
    Appreciate your help.
    Phil

    UML in JSE8 can reverse engineer all 4 built-in types of Java project defined in IDE. To prove that, I just downloaded apache ant source 1.6.5 from http://ant.apache.org/srcdownload.cgi and successfully reverse engineered it with JSE8.
    If you have a project with existing ant script , it's extremely easy, you absolutely don't need to hand-create a java project from scratch to specify source, library dependency etc. Just follow the wizard "create a Java project with existing ant script" to specify your Java project location, the ant script location, and * don't forget * to specify the source location. Any project without source folder specified is not considered a valid candidate for Reverse Engineer, and you won't see it listed under the project chooser in UML wizard when trying to associate the current UML project with a Java project. Please right click to bring up your source project properties to verify if you have source package folder correctly spelled out.
    It IS a supported feature, do let us know if you still have troubles to RE your project.

  • Running eclipse java project on command prompt

    Hi all,
    I have one simple java project and that is very well running in eclipse. I have added some external JARs to that project. It performs this job- it creates connection to server, and listens to the signals from server.
    My question is - how do I run that java project on command prompt?*
    I want to run that using ANT or simply I want to make a JAR file so I can execute JAR on command prompt. I created JAR, but it doesn't contain external jar which I added to the project. So I was not able to run that project.
    Can you please tell me any of the method - using ANT or by making JAR?
    Also can you be little bit more explanatory in reply?
    Thanks

    I want to make a JAR file so I can execute JAR on command prompt.This is very likely a good way to proceed. It is explained in great detail in Sun's Tutorial in the section on [Packaging Programs in JAR Files|http://java.sun.com/docs/books/tutorial/deployment/jar/index.html].
    I created JAR, but it doesn't contain external jar which I added to the project. So I was not able to run that project.Yes - the jar file you create has to know about the classes and other resources in that external jar. Otherwise, at runtime, the program will not be able to get at the stuff it needs. Usually you don't include that other jar (or its contents) in the jar file you are creating. Instead you provide your jar file with a manifest that describes the other jar's location. Details are also in the tutorial.
    One thing to note is that Sun's tutorial provides a lot of explanatory, conceptual, material. To that end it keeps the context simple and transparent by describing the steps as they would be carried out by someone working at the command line. The Eclipse documentation and forums might provide a more click-this-drag-that "explanation". If you do follow the method in the Tutorial and get stuck, post a description of the actual commands you used and their outcome.

  • Convert Java Project to exe file

    Helloz everyone,
    I have completed a java project. Now I have to convert it in exe file for windows.
    Can u please guide me. I can use any third party tool.
    But I want that it can be installed on any computer whenever double clicked and it make a icon. Whenever user click on that icon then it run the application.
    Thanks in advance.
    ViVeK

    Your jar command appears to be incomplete; it should lookk about like this:
    jar cvmf0 manifest_file MyJar.jar MyPackage/MyClass.class MyPackage/MyClass.gif MyPackage/MyClass.txt MyPackage/MyClass.html
    The 'm' in the command represents the manifest file. The 'f' represents the jarfile name. These can be reversed in order, but must be reversed respectively - that is, if the 'f' comes before the 'm', then the MyJar.jar needs to come before the manifest_file.
    The contents of the manifest needs - in the simplest cases - to look like this:
    Line 1. Main-Class: MyPackage.MyClass
    Line 2.
    Note please the Line x. do not appear; however the line 2 must exist and must be empty. IOW, a carrage return must exist at the end of line 1.
    Note too that the MyPackage part is optional. It's there if you have a specifically named package.
    Note lastly that you may not have .gif, .txt, etc files to add to your jarfile.

  • Regarding the java project

    Hi
    How to develop a java project in NWDS
    Thanks
    Hazrath

    After creating the DC,
    U can see the java perspective with the dc which u have created.
    In tht, u need to created proj and class names by using src/packag
    right click src/packag->new->proj,class etc...
    U can get this package at the bottom of JavaDc explorer..
    GS

  • Working on first Java project in Ecplise and need some help

    I am working on a Java project. I am working a programme to show sets of requirements to a software engineer. At the end the programme will show all consistent requirements with no conflicts between them.
    I am working on the first section. This invloves creating a class with a HashSet to insert the requirements in to the class. I am using this code at the moment
    import java.util.HashSet;
    import java.util.Set;
    public class requirements {
         public void HashSet() {
              Set<String> requirements = new HashSet<String>();
              //Declare some string items
              String item_1 = "r1";
              String item_2 = "r2";
              String item_3 = "r3";
              boolean result;
              //Add the items to the Set
              result = requirements.add(item_1);
              System.out.println(item_1 + ": " + result);
              result = requirements.add(item_2);
              System.out.println(item_2 + ": " + result);
              result = requirements.add(item_3);
              System.out.println(item_3 + ": " + result);
              //Now we try to add item_1 again
              result = requirements.add(item_1);
              System.out.println(item_1 + ": " + result);
              //Adding null
              result = requirements.add(null);
              System.out.println("null: " + result);
              //Adding null again
              result = requirements.add(null);
              System.out.println("null: " + result);
         public static void main(String[] args) {
              new requirements().HashSet();
    the class is called requirements and I get these errors
    Return type of the method is missing
    Syntax error on token class, delete this token
    Syntax error on token misplaced construct
    Syntax error insert Enum body to complete EnumheaderName
    Syntax Error insert Enum body to complete enum decleration
    The public type requirements must be defined in its own file.
    The next stage would be to send the Hashset to another class to perform operation on the set. The other class is called specification. Can anyone help me to resolve the errors and pass the set to the other class.
    Thanks

    muj wrote:
    I am working on a Java project. I am working a programme to show sets of requirements to a software engineer. At the end the programme will show all consistent requirements with no conflicts between them.
    I am working on the first section. This invloves creating a class with a HashSet to insert the requirements in to the class. I am using this code at the moment
    import java.util.HashSet;
    import java.util.Set;
    public class requirements {
         public void HashSet() {
              Set<String> requirements = new HashSet<String>();
              //Declare some string items
              String item_1 = "r1";
              String item_2 = "r2";
              String item_3 = "r3";
              boolean result;
              //Add the items to the Set
              result = requirements.add(item_1);
              System.out.println(item_1 + ": " + result);
              result = requirements.add(item_2);
              System.out.println(item_2 + ": " + result);
              result = requirements.add(item_3);
              System.out.println(item_3 + ": " + result);
              //Now we try to add item_1 again
              result = requirements.add(item_1);
              System.out.println(item_1 + ": " + result);
              //Adding null
              result = requirements.add(null);
              System.out.println("null: " + result);
              //Adding null again
              result = requirements.add(null);
              System.out.println("null: " + result);
         public static void main(String[] args) {
              new requirements().HashSet();
    the class is called requirements and I get these errors
    Return type of the method is missing
    Syntax error on token class, delete this token
    Syntax error on token misplaced construct
    Syntax error insert Enum body to complete EnumheaderName
    Syntax Error insert Enum body to complete enum decleration
    The public type requirements must be defined in its own file.
    The next stage would be to send the Hashset to another class to perform operation on the set. The other class is called specification. Can anyone help me to resolve the errors and pass the set to the other class.
    ThanksReading your code, it looks wrong... but it turns out that a lot of it was because you did not use CODE brackets like this:
    {+code}
    System.out.println("hello");
    {code+}
    becomes
       System.out.println("hello");It also seems that you code works as it is.
    though I recommend putting classes inside a package.
    Syntax error insert Enum body to complete EnumheaderNameWhere is this even in your code? Did you post the code you had a problem with?

  • How to use BO SDK in local java project?

    Hi,
    I am trying to connect BO system using below mentioned code
    public void main(String args[]) throws SDKException {
         try
              System.out.println("main");
              /ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();/
              IEnterpriseSession boEnterpriseSession = CrystalEnterprise.getSessionMgr().logon( "Administrator","","BOSAP","secEnterprise");
              IInfoStore boInfoStore =(IInfoStore) boEnterpriseSession.getService("InfoStore");
              ChangePWD(boEnterpriseSession, boInfoStore);
         }catch(Exception e)
              System.out.println("Exceptions in main");
              System.out.println(e);
    This code was taken from below mentioned thread:
    Force all users to change their Enterprise passwords with a batch operation
    I have created standalone java project and running as JAVA application in eclipce. I am getting class def not found error for these BO SDK jar files. I have added
    cecore.jar
    celib.jar and
    cesession.jar files as external lib to java project
    I am using following imports
    import com.crystaldecisions.sdk.framework.CrystalEnterprise;
    import com.crystaldecisions.sdk.framework.IEnterpriseSession;
    import com.crystaldecisions.sdk.exception.SDKException;
    import com.crystaldecisions.sdk.occa.infostore.*;
    import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
    import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
    import com.crystaldecisions.sdk.plugin.desktop.user.IUser;
    Does any one know solution to fix class def not found error?
    Thanks
    Nitesh Shelar

    I did some mistake few dependent jars were missing in project build path. After adding those missing BO jar files. Now its giving server connection error. Which I am trying to resolve.
    Thanks for your help.
    Nitesh Shelar

  • I m not able to create xml file in Java Project

    hi all,
    I have created one java project just to try with Ant Builder. I have created one class inside it. and now i m creating an XML file inside that project.
    But as soon as i try to create the File -> New -> File and give the .xml extention of the file this gives error into the project.
    Will you suggest me the solution for that?
    Thanks in advance.

    Assuming that you are facing this problem in NDS, here is the solution.
    Go to Windows--> Preferences --> WorkBench -->File Associations
    In the File Types list select *.xml
    This will display the default associated XML editor as
    XML Editor(default) in the bottom list box.
    Click on add button near the bottom list box and select Text Editor, click Ok.You will see one more entry in the list box as "Text Editor".
    Select this entry and click on the default button.
    Click Ok and close the preferences dialogue.
    Now create a new xml file.You wont see the error this time.
    Please note that this will treat all simple xml files you will create as TEXT Files and always open with Text Editor.You can override this behaviour with right click on the file and select appropriate editor from the "Open With" context menu.
    The error you are talking about is because the XML editor tries to check well-formedness and basic syntax rules for the file that you newly created, actually is a noce feature of the IDE.
    Rgds,
    Amol

  • [ot] A UML tool for a new Java project

    I am working on the new Java project and need a UML tool to get it start. I am wondering whether anyone one can recommend such tool or not. It can be either stand alone or as an Eclipse plug-in. It shall be able to handle at least 50 classes.
    Thanks.

    Is it any good? I haven't tried it but we're
    evaluating UML tools here and it's on my list to play
    with.
    PS.If you mean SDE....
    I have only used the personal edition at home, and the other versions have more functionality available
    My impressions, FWIW, are
    - easier to use than rational rose (I find this one which I have to use at work to be a pain), although, paradoxically enough, they are not that dissimilar in appearance
    - I was able to create some reasonably complex models without any problems
    - easy to install and start using - no great learning curve
    - I tried importing a model I had exported from rose and that did not work very well at all.
    - this applies to version 2.2

  • Best Practices for Defining NDS Java Projects...

    We are doing a Proof of Concept on using NDS to develop non-SAP Java applications.  We are attempting to determine if we can replace our current Java development tools with NDS/WAS.
    We are struggling with SAP's terminology and "plumbing" for setting up/defining Java projects.  For example, what is and when do you define Tracks, Software Components, Development Components, etc.  All of these terms are totally foreign to us and do not relate to our current Java environment (at least not that we can see).  We are also struggling with how the DTR and activities tie in to those components.
    If any one has defined best practices for setting up Java projects or has struggled with and overcome these same issues, please provide us with some guidance.  This is a very frustrating and time-consuming issue for us.
    Thank you!!

    Hi Peggy,
    In Component Model we divide software projects into small components.Components can use other components in well defined manner.
    A development object is a part of a component that can be changed or developed in some way; it provides the component with a certain part of its functionality. A development object may be a Java class, a Web Dynpro view, a table definition, a JSP page, and so on. Development objects are always stored as “sources” in a repository.
    A development component can be defined as a frame shared by a number of objects, which are part of the software.
    Software components combine components (DCs) to larger units for delivery and deployment.
    A track comprises configurations and runtime systems required for developing software component versions.It ensures stable states of deliverables used by subsequent tracks.
    The Design Time Repository is for versioning source code management. Distributed development of software in teams. Transport and replication of sources.
    You can also find lot of support in SDN for the above concepts with tutorials.
    Refer this Link for a overview on Java development Infrastructure(JDI)
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/java/java development infrastructure jdi overview.pdf
    To understand further
    Working with Net Weaver Development Infrastructure :
    http://help.sap.com/saphelp_nw04/helpdata/en/03/f6bc3d42f46c33e10000000a11405a/content.htm
    In the above link you can find all the concepts clearly explained.You can also find the required tutorials for development.
    Regards,
    Vijith

Maybe you are looking for