Compile Java class with missing pieces of code

I am looking for some ideas on how to compile Java code with some other code snippets (method calls). I fully understand that javac will not allow you to compile Java files if you cannot find all the dependencies. But perhaps there is a way around it, something like compiling force.
Knowing the bytecode is not so good, but I think some invoke method is just a complete definition of the class package and method name with parameters. Therefore, if the compiler simply puts this data in the class file and suppose that the process will be available in the running dependency (if not just NoSuchMethodExp).

The only workaround I found was to create empty missing class files with empty methods for the cheat compiler. Works fine, but there should be an easier way:
Any ideas?

+3
source share
5 answers

If you modify the jar, you can extract the class files that you do not modify to another directory and include them in the class path. Thus, they will be available to the compiler.

+1
source

Use interfaces.

Create interfaces that have the methods you need. At runtime, enter (Spring, Guice, etc.) or generate (cglib ...) classes that implement the interface.

+3
source

! , , , ( , ).
- , ?

:

, jar, AOP AspectJ - ( , , , , ;)
btw , Eclipse, :

:)
, , !

+1

. . , Java- , def, . , , , .

If this is not the case, you can define some of these methods as abstract and how to implement their child class.

0
source

What code is missing? This usually happens if you reference libraries that your compiler cannot find. Perhaps you just need to extend the classpath that the compiler is looking for for classes.

If you are really referring to code that is not yet available, you need to implement at least the methods you are talking about. But that sounds weird ... maybe you can clarify the situation.

0
source

Source: https://habr.com/ru/post/1784816/


All Articles