question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working for packages in a jar file?

See original GitHub issue

Running 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:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lukehutchcommented, Apr 29, 2018

@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!

0reactions
V-edcommented, Apr 29, 2018

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found