• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

how to call a class in a different namespace?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, everyone.

I'm trying to get started with Groovy unit test. My intention is to create reusable Groovy scripts along with unit test cases. As I'm new to Java space, I guess I'm missing something but I can't seem to figure out how to call a class in a different namespace. I have source code like the following below.

└── src
   └── com
       └── company
           ├── stuff1
           │   └── class1.groovy
           └── stuff2
               └── class2.groovy

And I have a simple code like the following in class1. It should be easy to image that class2 has a function sayHello() that prints "Hello from class2".



When I run groovy class1.groovy, I get the following error.

/my/path/class1.groovy: 3: unable to resolve class com.company.stuff2.class2                                                                                                            
@ line 3, column 1.                                                                                              
  import com.company.stuff2.class2                                                                              
  ^                                                                                                              
                                                                                                                 
1 error                                                                                                          

How do I make sure to execute code in different namespace in Groovy?
 
author & internet detective
Posts: 40746
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Just like in Java, you need to specify the classpath so Java knows where to find the files.
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic