0

I can't seem to solve this issue. Running com.benmyers.Main in IntelliJ with a Maven dependency works fine, and I receive no errors. When I use the Install tool in the Maven window to create an executable JAR file in the target directory, I receive the following error when attempting to run

java -jar "C:\Users\...\target\AncientGreekTranslator-1.0-SNAPSHOT.jar"

in Command Prompt:

Exception in thread "main" java.lang.NoClassDefFoundError: com/formdev/flatlaf/FlatDarculaLaf
        at com.benmyers.Main.main(Main.java:23)
Caused by: java.lang.ClassNotFoundException: com.formdev.flatlaf.FlatDarculaLaf
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 1 more

I believe there is an issue with the Maven plugin in pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>benlmyers.ancientGreekTranslator</groupId>
    <artifactId>AncientGreekTranslator</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.formdev</groupId>
            <artifactId>flatlaf</artifactId>
            <version>0.43</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

I have tried the following:

  1. Adding <scope>provided</scope> to the dependency in pom.xml (from this answer), which causes no visible change when running the JAR in Command Prompt, and

  2. using <artifactId>maven-plugins</artifactId> instead of <artifactId>maven-jar-plugin</artifactId> among other artifactIds. Basically, I tried the answers from this question and this other question but had no success.

I've received a comment requesting for my Main.java:

public class Main {

    private static GreekDictionaryInterpreter dictionaryInterpreter;
    private static Translator translator;

    private static MainForm mainForm;

    public static void main(String[] args) {

        dictionaryInterpreter = new GreekDictionaryInterpreter(new ArrayList<Flag>());
        translator = new GreekTranslator(dictionaryInterpreter.getDictionary(), new ArrayList<Flag>());

        FlatDarculaLaf.install(); // <- Line that causes exception

        //LookAndFeelManager.setLookAndFeel();

        MainForm.main(dictionaryInterpreter, translator);
    }
}

There are other answers for this, and I've searched through several and none of them have proven to be successful in my case. Any help would be greatly appreciated.

7
  • can you share your main.java class. if not just try stackoverflow.com/a/25011152/2137378. There are different types of reasons that can result noclassdeffounderror, but I have usually face it when there is a problem in loading Static block of my classes. Double check if there is any buggy or exception likely line in the Static part of your Main.java. Good luck Commented Nov 17, 2020 at 6:05
  • Can you extract the AncientGreekTranslator-1.0-SNAPSHOT.jar and check if the com.formdev jar really exist inside? Commented Nov 17, 2020 at 6:08
  • Thank you for the suggestion, @tgdavies . Sadly, the line <artifactId>maven-assembly-plugin</artifactId> in that solution gives me the compiler error "Plugin maven-assembly-plugin not found". Commented Nov 17, 2020 at 6:12
  • I have edited my question to include Main.java, @epcpu . Commented Nov 17, 2020 at 6:14
  • @ThangavelLoganathan When I extract the JAR and look inside \com, all I see is two directories: benmyers and intellij. I can imagine that it is supposed to be in there? Commented Nov 17, 2020 at 6:15

1 Answer 1

-1

In IDEA, you should add the dependency to your project Artifacts File -> Project Structure -> Artifacts add someone you want to Output Layout And then pack it.

Sign up to request clarification or add additional context in comments.

3 Comments

The OP is not having a problem in IDEA, it's the jar produced via maven which is the problem.
Commonly, idea will not package third party dependence into jar, Manual add dependence to jar is required, I've had the same problem When I use Idea from Eclipse
Thank you for your answer, @YuHaoZhu . I went to Project Structure > Artifacts, but I don't see how this can help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.