Strange behavior of Class.getResource() and ClassLoader.getResource() in executable jar

I thought this question was already asked and answered! What is the difference between Class.getResource() and ClassLoader.getResource()? getClass().getResource() searches relative to the .class file while getClass().getClassLoader().getResource() searches relative to the classpath root. If there’s an SSCCE here, I don’t understand why it doesn’t 1) Show the directory organization in the .jar, and… 2) Take package …

Read more

Create multiple runnable Jars (with dependencies included) from a single Maven project [duplicate]

You can do it. You’ll need a separate execution for each artifact that you’re building (i.e., give each its own id but you can leave the phase as default), and you’ll need to specify the finalName and archive/manifest/mainClass for each. <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>build-a</id> <configuration> <archive> <manifest> <mainClass>foobar.Aclass</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> …

Read more

Distributing my Python scripts as JAR files with Jython?

The best current techniques for distributing your Python files in a jar are detailed in this article on Jython’s wiki: http://wiki.python.org/jython/JythonFaq/DistributingJythonScripts For your case, I think you would want to take the jython.jar file that you get when you install Jython and zip the Jython Lib directory into it, then zip your .py files in, …

Read more

How to create a fat JAR with Gradle Kotlin script?

Here is a version that does not use a plugin, more like the Groovy version. import org.gradle.jvm.tasks.Jar val fatJar = task(“fatJar”, type = Jar::class) { baseName = “${project.name}-fat” manifest { attributes[“Implementation-Title”] = “Gradle Jar File Example” attributes[“Implementation-Version”] = version attributes[“Main-Class”] = “com.mkyong.DateUtils” } from(configurations.runtime.map({ if (it.isDirectory) it else zipTree(it) })) with(tasks[“jar”] as CopySpec) } tasks …

Read more