0

I'm pretty new to Maven and watched some Youtube videos about it, so I have done some steps of them for example to chose the <mainClass>. However it still shows:

no main manifest attribute, in...

if i want to start the file with java -jar.

I can show you my plugin's paragraph:

<plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.testpackage.testclass</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>repackage</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • 1
    Take a look at https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute – Terkwood Aug 22 '21 at 17:42
  • Re "`com.testpackage.testclass`": Java class names start with uppercase by convention. – Gerold Broser Aug 22 '21 at 18:08
  • Related: [Maven Assembly Plugin is not setting the MainClass manifest setting](https://stackoverflow.com/questions/7785456/maven-assembly-plugin-is-not-setting-the-mainclass-manifest-setting). (Just to add: Java naming conventions suggest to use classes with upper-case first letters - so instead of `testclass` it would be `Testclass` - or maybe `TestClass`.) – andrewJames Aug 22 '21 at 18:17
  • got it, thanks guys – brainoverflow Aug 22 '21 at 19:14
  • @brainoverflow And how did you get it? Please create an answer (and accept it – after a while with not so many rep points yet) so that future readers/seekers benefit from here as you did too. – Gerold Broser Aug 23 '21 at 15:59

1 Answers1

0

I have added a new plugin paragraph so then i worked:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>zaehler.test</mainClass>
                    </manifest>
                </archive>

            </configuration>
        </plugin>