this.getclass().getcanonicalname() to get the full class name.
note that a package / class name ("a.b.c") is different from the path of the .class files (a/b/c.class), and that using the package name / class name to derive a path is typically bad practice. sets of class files / packages can be in multiple different class paths, which can be directories or jar files.
this.getclass().getname() to get
packagename.classname and use
this.getclass().getsimplename() to get only class name
the fully-qualified name is opbtained as follows:
string fqn = yourclass.class.getname();
but you need to read a classpath resource. so use
inputstream in = yourclass.getresourceasstream("resource.txt");
there is a class,
class, that can do this:
class c = class.forname("myclass"); // if you want to specify a class
class c = this.getclass(); // if you want to use the current class
system.out.println("package: "+c.getpackage()+"\nclass: "+c.getsimplename()+"\nfull identifier: "+c.getname());
c represented the class
myclass in the package
mypackage, the above code would print:
full identifier: mypackage.myclass
you can take this information and modify it for whatever you need, or go check the api for more information.
- How to get current class name including package name in Java?
- Two different .jar with same Package name and same Class name. How to get the one?
- How to get the class name for Java SWT/JFace UI component which is currently highlighted by mouse cursor?
- How to get the full class name of the of an Java file in Eclipse?
- how to get full path of the current file including the src file in java
- How do you get the fully qualified class name in Eclipse?
- How to get the current time in your timezone in Java
- How to get the current project path from eclipse using java
- Eclipse, Java project - How do I add a source folder where the folder name is part of the package name?
- How to use jdt java model to get the line number of a field in a java class
- How to get an IType from a class name in Eclipse JDT
- How to change Java class name using Eclipse JDT API?
- How would I get rid of the old class name in my console whenever I run my code?
- How to rename entire java package name in Eclipse so that its all occurences gets renamed?
- How to trace stepDefinition class file from Package Name provided in Runner class in existing BDD Cucumber framework
- How to get a class name of a method by using Eclipse JDT ASTParser?
- How to get current Git branch name in Eclipse run configurations
- How to get Eclipse Compiler for Java batch package 4.5.2+
- How to name a java package in eclipse that complies with maven conventions but doesn't have main.java in the name?
- Eclipse provides Java API browsing but how can one search Java API for a class name or member name?
- Java to Excel: How to get value from main class to excel class in column B?
- How do I get the gradle eclipse plugin to build a classpath including my additional java test task dependencies
- How I can get current container and package for my custom eclipse wizard plugin?
- How to get path of java files including /src/
- How to fix issue when I import Android project to Eclipse I get package name instead project name?
- How to get selected file name and its package path in eclipse plugin
- How to change package name of Android Project in Eclipse?
- How to change a package name in Eclipse?
- How to locate the Path of the current project directory in Java (IDE)?
- Class file name must end with .class exception in Java Search
More Query from same tag
- Trouble deleting files or package in Eclipse
- Implement "search" feature in an eclipse plugin
- Eclipse RCP Content Assist not working with auto activated characters
- Exception using apache derby
- Eclipse breakpoints being hit even when choosing "Run" rather than "Debug"
- Free plugin similar to myeclipse
- JPA entities in external JAR
- eclipse--checked out previous commit to look around, now want to go back
- how to solve eclipse perspective error?
- Eclipse 2019-09 R Cannot Install Tomcat 9
- my android application stopped unexpectedly in android emulator
- github for windows not showing my changes made in eclipse
- eclipse, maven, Add Dependency is not working
- Logging in Java in 2015 - what does a properly configured environment look like?
- How to add images to a JFrame project
- Invocation Target Exception, Dont know what to do
- Error when creating a new Vaadin project in eclipse
- Read a file in java from a linked folder in eclipse
- How to resolve requirement: Import-Package:
- What can cause this Java behaviour?
- Eclipse - use hyperlink ability without step-into-section
- Gradle and Eclipse- "..:DependentProject" not supported in settings.gradle?
- Eclipse RCP 3.X to 4 -- classic CSS
- Configuration JUnit 4 in Spring + eclipse
- cannot establish server client connection - error 10061 in c winsock
- Build path error when creating android project in Eclipse
- Eclipse Android two buttons
- Error: R cannot be resolved
- How to include system dependencies in war built using maven