-1

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
user1424739
  • 11,937
  • 17
  • 63
  • 152
  • Could you show your pom.xml for better helping? Are settings main class on pom? Or try `java -jar your-jar.jar com.package.MainClass` – Dilermando Lima Dec 09 '21 at 16:18
  • You can check the pom file in the repo. I don't expect that I need to make any changes in order to get it running. – user1424739 Dec 09 '21 at 16:28

1 Answers1

-1

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

Dilermando Lima
  • 1,004
  • 8
  • 21
  • Did you try to run it? It doesn't work. It sounds like a main class is needed in the source. I don't understand why the tutorial example is not self-contained. `$ java -jar target/swing-1.0-SNAPSHOT.jar Error: Could not find or load main class package.MainClass.class Caused by: java.lang.ClassNotFoundException: package.MainClass.class` – user1424739 Dec 09 '21 at 17:13