0

I have the current import :

import com.test.test1.ver4.commons.{HelloWorld=> SomeCommon}

then I use the following:

val myCommons=Reader.getClassesForPackage(classOf[SomeCommon].getPackage) //The Reader expects for the Package

I want to change the 'ver4' to by dynamic, allowing to pass any other version as well.

I tried doing the simplest thing - getting the package by writing the following:

val p =Package.getPackage("com.test.test1.ver4.commons.HelloWorld"))

but I keep getting null.

I tried printing all the packages with :

    val p = Package.getPackages()

    for(pac <- p) println(pac.getName())

but it seems that it includes only 'system' packages like:

java.nio
java.security.cert
java.util.zip
java.nio.file

Can someone advise what to do?

Tahnks a lot.

user1386966
  • 3,302
  • 13
  • 43
  • 72

1 Answers1

0

You want Package.getPackage("com.test.test1.ver4.commons"). But note that for it to work you need to have loaded at least one class from this package already. You can use Reflections library to find such classes, see e.g. Can you find all classes in a package using reflection?.

Community
  • 1
  • 1
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487