fsjndi is a lightweight implementation of JNDI (Java Naming and Directory Interface) that uses local file storage for object persistence, ideal for development and testing environments. It enables named object storage without relying on an external JNDI service. This project also includes JMS compatibility with ActiveMQ, making it easier to develop and test messaging applications.
- Local JNDI Context: Provides a local, file-based JNDI context, allowing for persistent access to objects.
- Object Serialization: Objects are serialized and saved to files, making their state persistent across executions.
- JMS Compatibility with ActiveMQ: Supports managing JMS objects, such as
ConnectionFactoryandQueue, with ActiveMQ. - Unit Tests: Contains unit tests and is configured for continuous integration using GitHub Actions.
- Java: Version 8 or higher
- Maven: Version 3.6 or higher
- ActiveMQ: Required for JMS functionality (optional for basic usage)
-
Clone the repository:
git clone https://github.com/gregoryguibert/fsjndi.git cd fsjndi -
Build and install dependencies with Maven:
mvn clean install
-
Configure a
jndi.propertiesfile if you want to customize the JNDI configuration for your environment.
To use the local context, create a jndi.properties file at the project root or in the path specified by your application. Example content:
java.naming.factory.initial=fr.sirconflex.utils.fsjndi.SimpleFileContextFactory
java.naming.provider.url=file:/target/jndi-directoryMake sure that the path specified in provider.url exists or is writable.
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Example {
public static void main(String[] args) {
try {
Context context = new InitialContext();
// Bind an object to the JNDI context
context.bind("java:/testString", "Hello, JNDI!");
// Lookup the bound object
String result = (String) context.lookup("java:/testString");
System.out.println("Object found: " + result);
// Close the context
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
}To run tests, use Maven with the command:
mvn testThe tests temporarily create files in the target/test-directory folder to simulate the local context.
The project includes Maven dependencies for ActiveMQ. To test JMS functionalities, configure your ConnectionFactory and Queue objects as shown below:
context.bind("java:/ConnectionFactory", new ActiveMQConnectionFactory("tcp://localhost:61616"));While fsjndi provides essential JNDI functionality, it has the following limitations:
- Partial Implementation of
ContextInterface: TheSimpleNamingContextclass does not implement all methods in thejavax.naming.Contextinterface. Unsupported methods will throwUnsupportedOperationException. This may limit compatibility with applications expecting a fully functionalContextinterface. - Local Storage Only: This implementation uses a local file system to store objects, making it unsuitable for distributed applications where remote JNDI access is required.
- Serialization Requirement: Objects must be serializable to be bound to the context, as they are stored as serialized files.
- Limited Concurrency: This implementation does not handle concurrent access, so race conditions may arise if multiple instances interact with the same storage directory simultaneously.
- Simple Security Model: There is no built-in authentication or access control, which may pose security risks in multi-user environments.
Contributions are welcome! Please submit an issue for bug reports or feature requests, and create a pull request for any contributions.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for more details.