3

I am trying to prevent dependency checking in java compiler, I use command line compilation,is there any way to tell javac compiler not to check dependency while compiling a java file ?

7
  • 4
    dependency checking? like "dependency" when a class depends in other one? how would it compile then? Commented Jan 29, 2013 at 13:56
  • 3
    Delete all dependencies ... :D Commented Jan 29, 2013 at 13:56
  • why would you wish to do this? Commented Jan 29, 2013 at 13:56
  • What are you trying to do? Commented Jan 29, 2013 at 13:59
  • 2
    What you need is a bit of project abstraction & good design, of course you can build a library with common utilities and then provide system-specific implementations in the platform dependent modules. But compile without dependency checking? that's nonsense. Commented Jan 29, 2013 at 15:11

3 Answers 3

5

... is there any way to tell javac compiler not to check dependencies while compiling a java file ?

The simple answer is No.

Suppose you have some class A that wants to call some method m defined by class B. In order to successfully compile A, the compiler needs to know that B is a real class, that it defines the method m, that it has the expected number and type of arguments, what checked exceptions it throws, and what type of value it returns. Without this information about B, the compiler cannot compile A.

And this propagates to the project level. If a class in project P depends on a class in project Q, the compiler must have that class (at least) in order to compile the class in P.

In short, no such compiler option exists, and it is hard to see how it could be implemented it it did.

Sign up to request clarification or add additional context in comments.

1 Comment

i am stupid ...i read the heading of this question and believed that this can be done in java !!...but common sense prevails ;)
2

If you're two projects are dependent on each other then they are really one project and must be built together. If the relationship is a one-way relationship then you will still need to build the dependent project first and then have the results of the project on the classpath when building the second project.

Most IDEs have capabilities to manage this. In Eclipse you can mark that one project depends on another project and the dependent project's output files will be added to the classpath of the other. Typically all dependencies are built and packaged as jars and those jar files are placed onto the classpath when compiling parent projects.

Building code without having access to the dependencies is very difficult and not recommended. In some cases it can be possible. Eclipse has built their own incremental Java compiler so that they do not have to recompile the entire project each time a single file is modified. You can read more about it here but in order to use such a compiler you will likely have to do a lot of work.

UPDATE to reflect your new edit:

In order to build a common library that common library must not depend on any classes in your platform-specific sections. As Peter Rader has mentioned the typical way of doing that is by using interfaces. For example, your common library can have an EventListener interface which receives events. In your platform specific libraries you can implement that interface and process the events according to the specific platform. Since your common library only depends on the EventListener class and not the specific implementations it does not need those specific classes when it compiles.

3 Comments

See the docs on java for the details on setting the classpath with the -cp option - docs.oracle.com/javase/6/docs/technotes/tools/windows/…
Yes, using interface We can achieve the requirement, but I am searching for compilation without dependency checking, Any way thank you for your help
Why are searching for a thing that does not exist? What reason do you have to need "compilation without dependency checking". I am sure you won't need it!
0

If you have dependencies, they will always be checked and give warnings, but your classes will be compiled anyway.

Often frameworks offer an api.jar that contains interfaces and enums.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.