1

I have a problem, when I set up my pom.xml, my application still wouldn't run, saying it could not find or load main Class. I have setup my pom.xml as stated here

My pom.xml:

<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>com.example</groupId>
    <artifactId>EditPropertiesFile</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.example.EditPropertiesFile.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/commons-configuration/commons-configuration -->
        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
            <version>1.6</version>
        </dependency>
    </dependencies>

</project>

I use command mvn clean compile assembly:single to package the application and then run it with java -jar outputedJar.jar

This is what MANIFEST.MF which is inside that jar, says:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: xxxx
Build-Jdk: 1.8.0_121
Main-Class: com.example.EditPropertiesFile.Main

However, when I run, i get next error:

Error: Could not find or load main class com.example.EditPropertiesFile.Main

I don't know what else I can try, as I have tried various answers all over SO and they all seem to fix some other issues.

EDIT: output when running command:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EditPropertiesFile 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ EditPropertiesFile ---
[INFO] Deleting D:\Users\xxxx\Documents\Java_workspace\EditPropertiesFile\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ EditPropertiesFile ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Users\xxxx\Documents\Java_workspace\EditPropertiesFile\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ EditPropertiesFile ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-assembly-plugin:2.4:single (default-cli) @ EditPropertiesFile ---
[WARNING] Cannot include project artifact: com.example:EditPropertiesFile:jar:1.0; it doesn't have an associated file or directory.
[INFO] Building jar: D:\Users\xxxx\Documents\Java_workspace\EditPropertiesFile\target\EditPropertiesFile-1.0-jar-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.525 s
[INFO] Finished at: 2017-08-16T21:17:56+02:00
[INFO] Final Memory: 13M/225M
[INFO] ------------------------------------------------------------------------

Inside the jar file there is no file Main.java

Structure of my project:

project structure

Miha Jamsek
  • 1,193
  • 2
  • 17
  • 33

2 Answers2

0

Check/Extract jar file and look for the Main class is added in the jar file or not, Also, check the package structure.

Also, can you add the Output logs coming from mvn during the execution of mvn command you mentioned.

[update] Looks like your directory structure may be an issue, so check if thats correct or not. For instance in this case if baseProjectDir is your directory where you have pom.xml (baseProjectDir\pom.xml) then your Main.java should be residing in below directory relative to baseProjectdir: baseProjectDir\src\main\java\com\example\EditPropertiesFile\Main.java

Sharman25
  • 69
  • 4
  • I edited the question now. The Main.java is not in my outputted jar. – Miha Jamsek Aug 16 '17 at 19:22
  • I am not sure that directory structure is the problem. I edited question to give project structure picture at the end – Miha Jamsek Aug 17 '17 at 16:03
  • if you are using mvn from command line then you may need to make sure the directory structure conforms to mvn default. May be you can try the structure I mentioned once if no already done. – Sharman25 Aug 18 '17 at 15:27
  • i had directly com/example/EditProp.. instead of main/java/com/.. - Thanks for help! – Miha Jamsek Aug 18 '17 at 15:45
0

If the main class is EditPropertiesFile remove .Main

also,add to pom.xml :

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
    <execution>
        <phase>package</phase>
        <goals>
            <goal>shade</goal>
        </goals>
        <configuration>
            <transformers>
                <transformer
                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                    <mainClass>com.example.EditPropertiesFile.Main</mainClass>
                </transformer>
            </transformers>
        </configuration>
    </execution>
</executions>

  • no, com.example.EditPropertiesFile is package with main class Main.java in it. I already have all that in my pom file (Except for final name, which is not the problem) – Miha Jamsek Aug 16 '17 at 19:36