Parser for tnsnames.ora files
Library oraconf-<version>.jar
enables working with files in Oracle configuration format as described by documentation. This project is a fork of oraconf.
Supported features:
- Parsing tnsnames.ora files.
- Query a parsed file to retrieve a specific entry.
- Manipulating the parsed entries.
- Constructing new entries.
- Serializing parsed/new entries in a unified format that can be saved back to a file.
- Export to JSON format (including command line).
- No dependency on third-party libraries.
Getting the library using Maven
Add this dependency to your pom.xml
to reference the library:
<dependency>
<groupId>com.github.a-langer</groupId>
<artifactId>oraconf</artifactId>
<version>0.0.1</version>
</dependency>
Usage
Print all entries in a test.ora tnsnames file:
import java.io.FileNotFoundException;
import java.io.IOException;
import com.github.alanger.oraconf.ConfigurationParameter;
import com.github.alanger.oraconf.ConfigurationFile;
import com.github.alanger.oraconf.Parser;
import com.github.alanger.oraconf.ParameterFile;
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
ConfigurationFile cFile = new Parser(new ParameterFile("test.ora")).parse();
for(ConfigurationParameter cp : cFile.getParameters()) {
System.out.println( cp.toString() );
}
}
}
Parse a tnsnames file and find a specific entry by parameter printing it to stdout:
cFile = new Parser(cFile).parse();
System.out.println(cFile.findParameter(new Parameter("Area52")).toString());
Parse a tnsnames file and find a specific entry by name printing it to stdout:
cFile = new Parser(cFile).parse();
System.out.println(cFile.findParameter("Area52").toString());
Parse a tnsnames file and find a specific entry by name printing it to stdout as JSON:
cFile = new Parser(cFile).parse();
System.out.println(cFile.findParameter("Area52").toJson());
Export to JSON from command line using oraconf-*.jar:
java -jar ./oraconf-*.jar /etc/tns_admin/tnsnames.ora > tnsnames.json
Related resources
- oraconf - Original project by 'mulander' on bitbucket.
- orafile - Java for dealing with Oracle SQL*Net .ora files.
- oracle.net.nl.NLParamParser - Class from oracle jdbc driver (see example).
- TNSNamesReader - Example of one java class for parsing .ora files.