How to use maven to generate a runnable jar file of jxbrowser tutorial?

122 Views Asked by At

I am trying to generate a jar file from the following tutorial.

https://github.com/TeamDev-IP/JxBrowser-QuickStart/tree/master/Maven/Swing

$ mvn package
$ find -name '*.jar'
./target/swing-1.0-SNAPSHOT.jar

But when I run it, I got the following problem. Could you show me how to make a jar file and let it run for this tutorial repo?

$ java -jar ./target/swing-1.0-SNAPSHOT.jar
no main manifest attribute, in ./target/swing-1.0-SNAPSHOT.jar
1

There are 1 best solutions below

1
Dilermando Lima On

Try add this to your pom.xml



  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <classpathPrefix>lib/</classpathPrefix>
              <!-- set your main_class path -->
              <mainClass>{SET_HERE_YOUR_PATH_MAIN_CLASS}</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build> 

More details in https://www.baeldung.com/executable-jar-with-maven