1

Hello everyone and thank you in advance for you help. I'm a student and learning java. For this semester we have a group project were we need to complete a code with already some functions implemented. My main task was to implement an algorithm in the class assign from the directory assignment mainly using functions from class in the directory data model. Every class though in different directorie is in the same package. When calling static fields from data model classes in assign I encounter no problem. However when calling a method here is what I get error ClassDefNotFound. I shall add that I run the program with a .jar file. I tried a LOT of things to solve the problem but unfortunately I haven't solved it yet and I'm starting to run out for time so here I am looking for your help.

I tried to change the pom.xml file from assignment directory by adding in the configuration however it's still not working. Besides I'm confused by which path should I exactly write down. I know it as to be an absolute path but I can't writ my user directory because the project is supposed to work on any computer.

Thanks again for you future help. I've been pulling my hairs out on this one thing for ever so any help solving this would be a life saver !

Zeshion
  • 11
  • 1
  • Post your pom.xml file so we can see if maybe there is something wrong with it, also you get this error when trying to execute the jar or doing something particular? – BugsForBreakfast Dec 02 '19 at 21:20
  • I didn't succeed adding the pictures cause they were to big and it didn't want link so here is my pom.xml https://zupimages.net/viewer.php?id=19/49/7m62.jpg https://zupimages.net/viewer.php?id=19/49/h7w3.jpg and yes I get the mistakes when trying to execute the jar – Zeshion Dec 04 '19 at 11:02
  • Hmm I think what you are missing its the maven plugin in your pom, that makes the jar have its dependencies, Ill post a link to an example and also a pom as an answer – BugsForBreakfast Dec 04 '19 at 13:19

1 Answers1

0

Think you are missing the dependencies when generating the jar. thats why it says that the class isn't defined, try this in your pom.xml

source: Including dependencies in a jar with Maven

<build>
    <plugins>
      <!-- any other plugins -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>
  </build>

Personal pom.xml example (notice at the begining the use of the above plugin and also I defined a manifest, try both ways:

<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>NuevaUtilidadExcel</groupId>
    <artifactId>NuevaUtilidadExcel</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.nuevaUtilidad.vista.InterfazPrincipal</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- this is used for inheritance merges -->
                        <phase>package</phase>
                        <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>unknown-jars-temp-repo</id>
            <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
            <url>file:${project.basedir}/lib</url>
        </repository>
        <repository>
            <id>netbeans</id>
            <name>Netbeans rep</name>
            <url>http://bits.netbeans.org/maven2/</url>
        </repository>

    </repositories>
    <dependencies>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.0</version>
        </dependency>

        <dependency>
            <groupId>com.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>4.0</version>
        </dependency>


        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.9.6</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.9</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>3.0.1</version>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0</version>
        </dependency>

        <dependency>
            <groupId>com.toedter</groupId>
            <artifactId>jcalendar</artifactId>
            <version>1.4</version>
        </dependency>

    </dependencies>
    <name>NuevaUtilidadExcelSVG</name>
</project>
BugsForBreakfast
  • 712
  • 10
  • 30
  • Hey, thanks a lot for your answer and sorry for the delay, I already tried that by looking up on quora and stuff but it didn't work, besides the whole dependency and assembly plugin thing was already in the pom. Any other ideas ? :( I really don't get it because I tried a lot of solutions for people who had the same problem and it worked for them but not for me, maybe I'm probably doing something wrong though ) – Zeshion Dec 10 '19 at 18:25