> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/lexical-elements/packages.md).

# Packages and Imports

In BoxLang, a package is a collection of related components, functions, and variables. Packages help in organizing code into logical units, making it easier to maintain and understand. They also provide a namespace that prevents naming conflicts between different parts of a program.

By default, the package space of a class is the directory path, in dot-notation, from the webroot. For example, the default package of a class located at `models/foo/Bar.bx` would be `models.foo`. This can, however, be defined in the class, separately from the path.

To define a package in BoxLang, you use the `class` keyword and define the package in the attributes of the class. For example:

```boxlang
class package="com.example" {
    // package code here
}
```

This code defines a package named `com.example`. All components and functions defined within this package will be part of the `com.example` namespace.

Importing in BoxLang is done using the `import` keyword. The `import` statement is used to bring a package or a specific class into the current scope. Imported BoxLang and Java classes become class references, which can be used with `new`, `.init()`, or direct functional constructor syntax. For example:

```boxlang
import com.example.*;
```

This statement imports all components from the `com.example` package. If you want to import a specific component, you can do so like this:

```boxlang
import com.example.MyComponent;
```

This statement imports only the `MyComponent` component from the `com.example` package.

```boxlang
import models.User;
import java:java.lang.StringBuilder;

// BoxLang class reference
user = User( "Luis" );

// Java class reference
builder = StringBuilder( "hello" );
```

It's important to note that BoxLang is a dynamic language, and as such, it resolves package and component names at runtime, not at compile time. This means that you can use dynamic strings in your `import` statements, like so:

```boxlang
import "com.example.#componentName#";
```

In this statement, `#componentName#` is a variable that contains the name of the component to import. This feature makes BoxLang very flexible, but it can also lead to runtime errors if the component or package doesn't exist.

Packages and imports in BoxLang provide a way to organize code into logical units and to reuse code across different parts of a program.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/lexical-elements/packages.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
