Avatar billede fredand Forsker
20. juni 2013 - 13:00 Der er 2 kommentarer og
1 løsning

How to overshadow a class in Java?

Hello!

I need to create a test-version of an application.
What I need to do is to create an executable jar with the application but one class needs to be replaced with a testversion of it.

Btw I can not use (I guess what is the plugin pattern) when you provide several classes in the jar that implements a interface and you load the class at runtime for the interface from a
config file. I can not use this pattern since I'm not allowed to provide the original class in the jar.

I tried to create a maven project that depends from the original project. In the new project I created the testversion of the class. But both classes ended up in the jar when I run maven assembly:assembly. And at runtime the orignal class was loaded.
(I thought that the second version would replace the file from the dependency)

Do you guys got any idea of a pattern to apply to fix this?

Best regards
Fredrik
Avatar billede arne_v Ekspert
20. juni 2013 - 15:25 #1
If the classes have the same name and you update the jar file with the new class then it should work.

I don't know how to do it in Maven, but you can do it via ant or command line.
Avatar billede fredand Forsker
22. juni 2013 - 16:16 #2
Hello Arne!

That seems to be the only way to solve it.

Please leave a answer.

Best regards
Fredrik
Avatar billede arne_v Ekspert
23. juni 2013 - 01:32 #3
svar
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester



IT-JOB

Cognizant Technology Solutions Denmark ApS

Data Architect

ILLUM A/S

IT Manager

Frode Laursen A/S

IT Supporter

Københavns Erhvervsakademi

IT-supporter elev