0

You are my last hope. I wrote little bot for telegram. And it's works perfect but i cant build it as an executable jar file. Each time i try to execute jar file at my server i get error:

Error: Could not find or load main class com.praetorian19.MainIni

I understood that i mentioned class path in wrong way. I try mention it in different ways but it's doesn't matter. Error is the same. Please look my MVN project xml and several screenshots from Idea project structure. I think i have an error in pom or in structure.

I try to wrote classpath in many ways. But result the same I try to build jar at both platforms - Win/Lin, the same

Screenshot from Idea: Project structure

Pom:

<modelVersion>4.0.0</modelVersion>
    <groupId>praetorian19</groupId>
    <artifactId>praetorian19</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.telegram/telegrambots -->
        <dependency>
            <groupId>org.telegram</groupId>
            <artifactId>telegrambots</artifactId>
            <version>4.4.0.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.12.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.12.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-jcl -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-jcl</artifactId>
            <version>2.12.1</version>
        </dependency>

    </dependencies>


    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>
                                        com.praetorian19.MainInit
                                    </mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

Error: Could not find or load main class com.praetorian19.MainInit while i try to execute jar at server

Also i try

praetorian19.MainInit

But result the same

friendlyBug
  • 518
  • 5
  • 12
  • The screenshot shows that your class is in the root package. So why did you configure the main class with the name `com.praetorian19.MainInit`? – JB Nizet Aug 24 '19 at 12:58
  • i try also without it. But result the same – NullPointer Aug 24 '19 at 13:27
  • Post the output of `jar tvf `. Post the exact command you execute to run the jar file. Post the exact and complete stack trace you get. – JB Nizet Aug 24 '19 at 13:38
  • C:\Users\metal>java -jar E:\YandexDisk\Code\praetorian19bot\target\praetorian19-1.0-jar-with-dependencies.jar Error: Could not find or load main class praetorian19.MainInit ------------------------------------ C:\Users\metal>java -jar tvf E:\YandexDisk\Code\praetorian19bot\target\praetorian19-1.0-jar-with-dependencies.jar Error: Unable to access jarfile tvf – NullPointer Aug 24 '19 at 15:55
  • You're still using praetorian19.MainInit as your main class. But your main class is not in the package praetorian19. It's in the root package. So its name is just MainInit. And the command I asked you to execute is `jar tvf `. Not `java -jar tvf `. – JB Nizet Aug 24 '19 at 16:16
  • Hi! Biilion thanks to you. Noew it's works. Just changed way to MinInit :) – NullPointer Aug 25 '19 at 01:14

1 Answers1

0

The problem is you have defined the main class as com.praetorian19.MainInit in maven-assembly-plugin, which mean the MainInit class supposed to be in the package com.praetorian19.

However when looking into IDEA project structure, your MainInit class in default package, thus it gives error Could not find or load main class com.praetorian19.MainIni, when executing the jar.

To solve this, create a package com.praetorian19 and move your MainInit class into that package with the package declaration as package com.praetorian19;

friendlyBug
  • 518
  • 5
  • 12