“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

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

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

How do I tell Spring Boot which main class to use for the executable jar?

Add your start class in your pom: <properties> <!– The main class to start by executing java -jar –> <start-class>com.mycorp.starter.HelloWorldApplication</start-class> </properties> or <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.mycorp.starter.HelloWorldApplication</mainClass> </configuration> </plugin> </plugins> </build>

How to include SQLite database in executable Jar?

What library are you using for SQLite? I did a search based on the connection URI you indicated and found this one. In the documentation it says: 2009 May 19th: sqlite-jdbc-3.6.14.1 released. This version supports “jdbc:sqlite::resource:” syntax to access read-only DB files contained in JAR archives, or external resources specified via URL, local files address … Read more