Not working for packages in a jar file?
See original GitHub issueRunning this library directly in let’s say IntelliJ IDEA works as expected, but when running the same code from a jar file, the Exception below is thrown.
Exception in thread "[thread_name]" java.lang.NoClassDefFoundError: io/github/lukehutch/fastclasspathscanner/FastClasspathScanner
at vendor.objects.CommandLinksContainer.<init>(CommandLinksContainer.java:41)
at app.BotCommandsLinker$1.<init>(BotCommandsLinker.java:14)
at app.BotCommandsLinker.createLinksContainer(BotCommandsLinker.java:14)
at vendor.abstracts.CommandsLinker.getContainer(CommandsLinker.java:20)
at vendor.objects.CommandsRepository.getContainer(CommandsRepository.java:21)
at app.CommandRouter.run(CommandRouter.java:147)
Caused by: java.lang.ClassNotFoundException: io.github.lukehutch.fastclasspathscanner.FastClasspathScanner
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
Here is the code that runs this issue in a jar file :
ScanResult results = new FastClasspathScanner(linksPackage).strictWhitelist().scan();
List<String> classNames = results.getNamesOfAllClasses();
List<Class<?>> linkableClasses = results.classNamesToClassRefs(classNames);
ArrayList<Link> links = new ArrayList<>();
linkableClasses.forEach(linkableClass -> {
if(LinkableCommand.class.isAssignableFrom(linkableClass)){
links.add(new Link((Class<LinkableCommand>)linkableClass));
}
});
The .verbose()
does output alot of data in “local mode” (not in a jar file) but no information is thrown (except this error stack) when running from the jar file.
P.S. : I know that I may not be using the scanner at its full potential (I’m searching for all the classes and then filtering those with the interface LinkableCommand
while the scanner seems to have ways to do that automatically) but I couldn’t get it working.
If you want to to send the .verbose()
log of the working conditions (again, when not in a jar file), just let me know!
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
jar package not detected - Stack Overflow
jar file without using Maven or Gradle. I tried following the instructions on another post, with the following code: package jparser; import ...
Read more >Frustrated Beginner - How to import a jar file, package does ...
I understand that the net.java.games part corresponds to a folder structure, so I created that folder structure under the root of my classpath...
Read more >Can't import jar file - Katalon Studio
jar created by @kazurayam works just fine, but mine, AhojClass.jar not working at all, and Katalon Studio don't see neither package nor class ......
Read more >How to run a Jar file | TechTarget - TheServerSide.com
Run the JAR file on the command line or terminal window if a double-clicking fails. If you do not have Java installed, and...
Read more >JAR Files Not Opening on Windows 10: 7 Solutions to Use
How do I fix jar files not opening on Windows 10? · 1. Reinstall or update Java Runtime Environment · 2. Use an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@V-ed no problem at all! I’d rather know about every little thing like this in case it’s a bug in FCS. Glad you found the cause!
Well, I feel kinda dumb now.
I rechecked the artifact created by IntelliJ IDEA and the build process wasn’t including your FastClasspathScanner library into the jar file.
As you thought, it was indeed a packaging error!
Thanks alot for the quick answer and sorry for making an issue which wasn’t cause by your library but rather my lack of knowledge on IntelliJ’s artifact building process! Your library is really useful!