Coder Social home page Coder Social logo

jt's Introduction

logo

JT

a java tool for the command line


jt is a java tool for the command line. Only works with the Java8 stdlib.

Install

You can either build it from source with go build, or install it with

go install github.com/tsatke/jt@latest

Usage

After installing, the jt command should work. Everything in jt is done with class paths, rather than qualified names (java/lang/Object rather than java.lang.Object). In the future, this tool might support the qualified names as input, but for now, it just saves a lot of headaches if we just use the paths.

Verbose output

If you want more output (or think something might be wrong), you can check the debug output by adding the -v flag.

Listing classes in a jar file

Assuming you have a jar file with 5 classes in it (no matter where exactly, just inside the jar file), the following works.

$ jt classes 'myjar.jar'
com/mypackage/Class1
com/mypackage/Class2
com/mypackage/Class3
com/mypackage/Class4
com/mypackage/Class5

Supported project formats

At the moment, jt supports Maven and Eclipse project formats. That is, for Maven, it uses the pom.xml and for Eclipse the .classpath file to get a classpath. On that classpath, jt will search for classes. Currently, it will always consider the JAVA_HOME variable and use that as the standard library on any classpath, regardless what the Maven or Eclipse project have configured. If JAVA_HOME is not set, you will not be able to get information about classes that are located in the standard library.

Viewing the classpath

jt can display the classpath of a project. The standard library is always on top of other entries on the classpath.

$ jt classpath
/path/to/my/project/src/main/java
/path/to/java-home/lib/rt.jar
...
/path/to/java-home/lib/charsets.jar
/path/to/maven-repo/junit/junit/4.11/junit-4.11.jar
/path/to/maven-repo/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar

Finding classes

You can use jt to find classes on the classpath of the project that you are currently in.

$ jt find 'App'
Project results:
com/mypackage/App
com/mypackage/App$Builder
Classpath results:
com/thirdparty/AppConfiguration

but

$ jt find 'App' | cat
com/mypackage/App
com/mypackage/App$Builder
com/thirdparty/AppConfiguration

if you're not on a terminal, jt will not print the headers, so you can use grep, xargs and your other favorite tools as you're used to.

In addition, if you know that a specific class is in your project, and you don't need to search a (potentially) large classpath, you can pass the --no-classpath option. This will keep jt from even building a classpath, and save you a lot of time, especially in Maven projects.

Viewing superclasses

You can view the superclasses of a given class on the classpath. Interfaces are not implemented yet.

$ jt superclass 'com/mypackage/io/SpecialInputStream'
com/mypackage/io/SpecialInputStream
com/mypackage/io/AbstractInputStream
java/io/InputStream
java/lang/Object

Viewing subclasses

You can view the direct subclasses of a given class on the classpath. The results can be filtered by a regex pattern, which will speed up searches by a lot depending on the regex pattern.

$ jt subclass 'java/lang/Object'
... (all classes from the stdlib that extend java.lang.Object)
com/mypackage/App
com/mypackage/App$Builder

With a filter, the search effectively skips all the standard library classes, and the search will complete a lot faster.

$ jt subclass 'java/lang/Object' 'com/mypackage/.*'
com/mypackage/App
com/mypackage/App$Builder

With the --invert option, you can also invert the pattern, meaning that all classes that DO NOT match the pattern are checked.

The search is performed on multiple goroutines concurrently. The number of goroutines used is equal to runtime.NumCPU().

Icons made by Freepik from www.flaticon.com

jt's People

Contributors

tsatke avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.