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 can I create an executable/runnable JAR with dependencies using Maven?

<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>fully.qualified.MainClass</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build> and you run it with mvn clean compile assembly:single Compile goal should be added before assembly:single or otherwise the code on your own project is not included. See more details in comments. Commonly this goal is tied to … Read more

Prevent launching multiple instances of a java application

You could use a FileLock, this also works in environments where multiple users share ports: String userHome = System.getProperty(“user.home”); File file = new File(userHome, “my.lock”); try { FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE); FileLock lock = fc.tryLock(); if (lock == null) { System.out.println(“another instance is running”); } } catch (IOException e) { throw new Error(e); … 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

“Could not find the main class” error when running jar exported by Eclipse

Verify that you can start your application like that: java -cp myjarfile.jar snake.Controller I just read when I double click on it – this sounds like a configuration issue with your operating system. You’re double-clicking the file on a windows explorer window? Try to run it from a console/terminal with the command java -jar myjarfile.jar … Read more

Building a runnable jar with Maven 2

The easiest way to do this would be to create an assembly using the maven-assembly-plugin and the predefined jar-with-dependencies descriptor. You’ll also need to generate a manifest with a main-class entry for this uber jar. The snippet below shows how to configure the assembly plugin to do so: <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> … Read more