Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile the project VS each single java file

 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, everyone.

I've been overwhelmed with my assignment recently and with the great help in this forum I am almost finished. Thank you all again. But now I come across a big problem and hope to hear your advices.

My Data class is a Facade to the LockManager class.

If I compile the whole project, it works well. But when I compile either of the two java files, the compiler will complain about not finding the other class. Do I have to ensure that every single java file in my project can be compiled sucessfully? If so, it seems I have to change the parameter in the LockManager's lock method,using the parameter "Object client" instead of "Data client". However, in this lock method, I use client.read() to throw RecordNotFoundException. So, even if I change the parameter, the LockManager class still need the Data class to compile. Then what should I do?

By the way, I think I have four uncertain questions before uploading my assignment. But they belong to different topics, should I have to post four new ones or a single one?

Thanks in advance!
Regards, Ailsa Cape
[ September 17, 2005: Message edited by: Ailsa Cape ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ailsa, in answer to your second question I can say that it is usually better to keep unrelated questions in separate topic threads. It makes reading and responding to the questions less confusing for all. You can always link the threads if necessary using the "url" button.
-Barry
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ailsa, in answer to your first question (you see it's already becoming confusing for me ):

I found that if I used the -classpath option to javac, then the compiler compiled both classes for me when I asked only for the first to be compiled. If I do not use the -classpath option I get the behaviour you have described.

-Barry

[ September 17, 2005: Message edited by: Barry Gaunt ]
 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Barry

Thank you a lot!

I tried your approach and didn't receive the expected result. Maybe I didn't understand your mean correctly. The Data and LockManager java source files are both in my working directory and in this directory I launched the following command line, javac -classpath . Data.java
, however the compiler still complained about not finding the LockManager class.

After I wrote all the needed java files, I created a new empty project in the JCreator software and then add all these files into it, so I found the question. When I want to compile Data.java or LockManager.java separately, the compiler will not compile it because it can't find the other class. But if I compile the whole project, it will complete sucessfully and my program will run smoothly. I don't know whether the examiner would compile each single java file to testify that every file can be compiled properly when he/she receives my source code.

Thanks in advance!
Regards, Ailsa Cape
[ September 17, 2005: Message edited by: Ailsa Cape ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you have not specified your classpath correctly. The -classpath . in my example was exactly that - an example. For your own package directory structure you would have to replace the point (.) with a list of directories where your classes can be found.

Are your classes in a package?

-Barry
[ September 17, 2005: Message edited by: Barry Gaunt ]
 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Barry

Yes, my Data and LockManager java source files are both in the package of suncertify.db. so, can I use the command line as "javac -classpath suncertify.db.Data.java" ?

Thanks in advance!
Regards, Ailsa Cape
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Don't worry we'll get there in the end
[ September 17, 2005: Message edited by: Barry Gaunt ]
 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Barry

Thank you for your patience! Your approach works well.

I find when I use the command line "javac -classpath . suncertify\db\Data.java", other java files which are relevant to Data.java file are all compiled automatically such as LockManager.java,RecordNotFoundException.java etc.
So I think the compiler's working manner is still to compile a "small" project rather than a single java file. Does the examiner use the same means to check my source files? In other words, as long as I ensure the whole project can compile correctly, I am needless to concern whether each single java file can be compiled or not. Can I write two java files like LockManager and Data which reference each other?

Thanks in advance!
Regards,Ailsa Cape
[ September 17, 2005: Message edited by: Ailsa Cape ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ailsa, I will try to answer some of your questions:

Does the examiner use the same means to check my source files?
I cannot answer that question. Sorry, I do not know.

In other words, as long as I ensure the whole project can compile correctly...

As far as I know, you are not allowed to require that your submitted project depends on a third party tool to build (make, ant, maven, Eclipse, NetBeans, ...). So you must ensure that it compiles from the command line using javac and other tools in the jdk's bin directory. Possibly you can provide scripts for the platforms you support. Don't forget you can use wildcards in some of the commands.

Provide documentation for the build procedure.


... I am needless to concern whether each single java file can be compiled or not?
Can I write two java files like LockManager and Data which reference each other?


Yes, you cannot avoid such dependencies. Make sure that the dependencies can be resolved by the compiler as we did in the compilation "exercise"

-Barry
 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Barry

Thank you again.
Your answers are very helpful. I now understand as long as I ensure every my source files can be compiled from the command line using javac tools, I will be safe enough.

Best Regards, Ailsa Cape
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic