Maven compilation error
-
Χρησιμοποιώντας το παρεχόμενο pom.xml (με μικρές αλλαγές), δημιούργησα μια AtlernateTimeTeller.class. Μετά από "mvn install" μου λέει ότι δεν μπορεί να βρει το πακέτο που εμπεριέχεται η κλάσση που μας δόθηκε (TimeTeller), ενώ το eclipse δεν έχει τέτοια θέματα. Μήπως κάποιος το έχει συναντήσει (και λύσει βεβαίως) αυτό το πρόβλημα. Ευχαριστώ!
-
Πρέπει στο
pom.xml
να βάλεις το αντίστοιχο κομμάτι στοdependency
καιrepository
. Το screenshot φαίνεται να μην κατεβάζει την βιβλιοθήκη.Σου στέλνω το
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>gr.hua.dit.oop2.hello</groupId> <artifactId>java-maven-skeleton</artifactId> <version>1.0-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>11</java.version> </properties> <repositories> <repository> <id>gitlab-maven</id> <url>https://gitlab.com/api/v4/projects/41008035/packages/maven</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> </dependency> <dependency> <groupId>gr.hua.dit.oop2</groupId> <artifactId>calendar</artifactId> <version>1.0.0</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.31</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.7.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>3.20.2</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <release>${java.version}</release> <parameters>true</parameters> <showDeprecation>true</showDeprecation> <failOnWarning>true</failOnWarning> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.2.0</version> <configuration> <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>gr.hua.dit.oop2.hello.Main</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
-
Αυτό είναι το δικό σας pom.xml με τις δικές μου αλλαγές. Ακόμα το ίδιο error βγάζει...
<?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>gr.hua.dit.oop2.grp38131</groupId> <artifactId>CalendarX</artifactId> <version>1.0</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>17</java.version> </properties> <repositories> <repository> <id>gitlab-maven</id> <url>https://gitlab.com/api/v4/projects/41008035/packages/maven</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-nop</artifactId> <version>1.7.36</version> </dependency> <dependency> <groupId>org.mnode.ical4j</groupId> <artifactId>ical4j</artifactId> <version>4.0.0-rc1</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> </dependency> <dependency> <groupId>gr.hua.dit.oop2</groupId> <artifactId>calendar</artifactId> <version>1.0.0</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-nop</artifactId> <version>1.7.31</version> <scope>runtime</scope> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.7.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>3.20.2</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <release>${java.version}</release> <parameters>true</parameters> <showDeprecation>true</showDeprecation> <failOnWarning>true</failOnWarning> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.2.0</version> <configuration> <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>calendar.CalendarX</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
-
Μου δουλεύει αυτό που έστειλες.
Θα σου πρότεινα να κάνει ένα
mvn clean
και μετάmvn package
.Αν δεν δουλέψει ίσως φταίνε οι εκδόσεις της
java
καιmaven
. Το eclipse, αν θυμάμαι καλά, δεν χρησιμοποιεί την έκδοση τουmaven
που έχεις εγκατεστημένη αλλά δική του.[nix-shell:~/lectures/oop2/code/java-maven-skeleton]$ java --version openjdk 19.0.2 2023-01-17 OpenJDK Runtime Environment Zulu19.32+13-CA (build 19.0.2+7) OpenJDK 64-Bit Server VM Zulu19.32+13-CA (build 19.0.2+7, mixed mode, sharing) [nix-shell:~/lectures/oop2/code/java-maven-skeleton]$ mvn --version Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546) Maven home: /nix/store/v1jhjkawixadcnbhzr751lxxri5frrmd-apache-maven-3.9.5/maven Java version: 19.0.2, vendor: Azul Systems, Inc., runtime: /nix/store/0b0fs7lg3ynm69xwln56468gg2xrph9h-zulu19.32.13-ca-jdk-19.0.2/zulu-19.jdk/Contents/Home Default locale: en_GR, platform encoding: UTF-8 OS name: "mac os x", version: "13.6", arch: "aarch64", family: "mac" [nix-shell:~/lectures/oop2/code/java-maven-skeleton]$ mvn package [INFO] Scanning for projects... [INFO] [INFO] -----------------< gr.hua.dit.oop2.grp38131:CalendarX >----------------- [INFO] Building CalendarX 1.0 [INFO] from pom.xml [INFO] --------------------------------[ jar ]--------------------------------- Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/slf4j/slf4j-nop/1.7.36/slf4j-nop-1.7.36.pom Downloading from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-nop/1.7.36/slf4j-nop-1.7.36.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-nop/1.7.36/slf4j-nop-1.7.36.pom (790 B at 3.1 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/mnode/ical4j/ical4j/4.0.0-rc1/ical4j-4.0.0-rc1.pom Downloading from central: https://repo.maven.apache.org/maven2/org/mnode/ical4j/ical4j/4.0.0-rc1/ical4j-4.0.0-rc1.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/mnode/ical4j/ical4j/4.0.0-rc1/ical4j-4.0.0-rc1.pom (3.8 kB at 97 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.pom Downloading from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.pom (2.7 kB at 66 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/slf4j/slf4j-parent/2.0.7/slf4j-parent-2.0.7.pom Downloading from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-parent/2.0.7/slf4j-parent-2.0.7.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-parent/2.0.7/slf4j-parent-2.0.7.pom (17 kB at 380 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/commons-codec/commons-codec/1.15/commons-codec-1.15.pom Downloading from central: https://repo.maven.apache.org/maven2/commons-codec/commons-codec/1.15/commons-codec-1.15.pom Downloaded from central: https://repo.maven.apache.org/maven2/commons-codec/commons-codec/1.15/commons-codec-1.15.pom (15 kB at 351 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.pom Downloading from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.pom (24 kB at 541 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/threeten/threeten-extra/1.7.0/threeten-extra-1.7.0.pom Downloading from central: https://repo.maven.apache.org/maven2/org/threeten/threeten-extra/1.7.0/threeten-extra-1.7.0.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/threeten/threeten-extra/1.7.0/threeten-extra-1.7.0.pom (36 kB at 809 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/commons-validator/commons-validator/1.7/commons-validator-1.7.pom Downloading from central: https://repo.maven.apache.org/maven2/commons-validator/commons-validator/1.7/commons-validator-1.7.pom Downloaded from central: https://repo.maven.apache.org/maven2/commons-validator/commons-validator/1.7/commons-validator-1.7.pom (14 kB at 313 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/apache/commons/commons-parent/51/commons-parent-51.pom Downloading from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/51/commons-parent-51.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/51/commons-parent-51.pom (78 kB at 1.3 MB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4.pom Downloading from central: https://repo.maven.apache.org/maven2/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4.pom Downloaded from central: https://repo.maven.apache.org/maven2/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4.pom (18 kB at 400 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/commons-digester/commons-digester/2.1/commons-digester-2.1.pom Downloading from central: https://repo.maven.apache.org/maven2/commons-digester/commons-digester/2.1/commons-digester-2.1.pom Downloaded from central: https://repo.maven.apache.org/maven2/commons-digester/commons-digester/2.1/commons-digester-2.1.pom (10 kB at 311 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/apache/commons/commons-parent/17/commons-parent-17.pom Downloading from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/17/commons-parent-17.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/17/commons-parent-17.pom (31 kB at 709 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.pom Downloading from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.pom (3.8 kB at 113 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/slf4j/slf4j-parent/1.7.25/slf4j-parent-1.7.25.pom Downloading from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-parent/1.7.25/slf4j-parent-1.7.25.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-parent/1.7.25/slf4j-parent-1.7.25.pom (14 kB at 322 kB/s) Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/slf4j/slf4j-nop/1.7.36/slf4j-nop-1.7.36.jar Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/mnode/ical4j/ical4j/4.0.0-rc1/ical4j-4.0.0-rc1.jar Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/commons-codec/commons-codec/1.15/commons-codec-1.15.jar Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.jar Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/org/threeten/threeten-extra/1.7.0/threeten-extra-1.7.0.jar Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/commons-validator/commons-validator/1.7/commons-validator-1.7.jar Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4.jar Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/41008035/packages/maven/commons-digester/commons-digester/2.1/commons-digester-2.1.jar Downloading from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-nop/1.7.36/slf4j-nop-1.7.36.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-nop/1.7.36/slf4j-nop-1.7.36.jar (3.9 kB at 116 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/mnode/ical4j/ical4j/4.0.0-rc1/ical4j-4.0.0-rc1.jar Downloading from central: https://repo.maven.apache.org/maven2/commons-codec/commons-codec/1.15/commons-codec-1.15.jar Downloading from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.jar Downloading from central: https://repo.maven.apache.org/maven2/org/threeten/threeten-extra/1.7.0/threeten-extra-1.7.0.jar Downloading from central: https://repo.maven.apache.org/maven2/commons-validator/commons-validator/1.7/commons-validator-1.7.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/threeten/threeten-extra/1.7.0/threeten-extra-1.7.0.jar (252 kB at 3.0 MB/s) Downloading from central: https://repo.maven.apache.org/maven2/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4.jar Downloaded from central: https://repo.maven.apache.org/maven2/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4.jar (247 kB at 1.2 MB/s) Downloading from central: https://repo.maven.apache.org/maven2/commons-digester/commons-digester/2.1/commons-digester-2.1.jar Downloaded from central: https://repo.maven.apache.org/maven2/commons-validator/commons-validator/1.7/commons-validator-1.7.jar (190 kB at 847 kB/s) Downloaded from central: https://repo.maven.apache.org/maven2/commons-digester/commons-digester/2.1/commons-digester-2.1.jar (197 kB at 621 kB/s) Downloaded from central: https://repo.maven.apache.org/maven2/commons-codec/commons-codec/1.15/commons-codec-1.15.jar (354 kB at 1.0 MB/s) Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.jar (752 kB at 1.7 MB/s) Downloaded from central: https://repo.maven.apache.org/maven2/org/mnode/ical4j/ical4j/4.0.0-rc1/ical4j-4.0.0-rc1.jar (1.6 MB at 1.9 MB/s) [INFO] [INFO] --- resources:3.3.1:resources (default-resources) @ CalendarX --- [INFO] Copying 0 resource from src/main/resources to target/classes [INFO] [INFO] --- compiler:3.8.1:compile (default-compile) @ CalendarX --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- resources:3.3.1:testResources (default-testResources) @ CalendarX --- [INFO] skip non existing resourceDirectory /Users/angel/lectures/oop2/code/java-maven-skeleton/src/test/resources [INFO] [INFO] --- compiler:3.8.1:testCompile (default-testCompile) @ CalendarX --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- surefire:2.22.2:test (default-test) @ CalendarX --- [INFO] [INFO] --- jar:3.2.0:jar (default-jar) @ CalendarX --- [INFO] Building jar: /Users/angel/lectures/oop2/code/java-maven-skeleton/target/CalendarX-1.0.jar [INFO] [INFO] --- dependency:3.2.0:copy-dependencies (copy-dependencies) @ CalendarX --- [INFO] Copying slf4j-nop-1.7.36.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/slf4j-nop-1.7.36.jar [INFO] Copying slf4j-api-1.7.36.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/slf4j-api-1.7.36.jar [INFO] Copying ical4j-4.0.0-rc1.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/ical4j-4.0.0-rc1.jar [INFO] Copying commons-codec-1.15.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/commons-codec-1.15.jar [INFO] Copying commons-lang3-3.12.0.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/commons-lang3-3.12.0.jar [INFO] Copying commons-collections4-4.4.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/commons-collections4-4.4.jar [INFO] Copying threeten-extra-1.7.0.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/threeten-extra-1.7.0.jar [INFO] Copying commons-validator-1.7.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/commons-validator-1.7.jar [INFO] Copying commons-beanutils-1.9.4.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/commons-beanutils-1.9.4.jar [INFO] Copying commons-digester-2.1.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/commons-digester-2.1.jar [INFO] Copying commons-logging-1.2.jar to /Users/angel/lectures/oop2/code/java-maven-skeleton/target/lib/commons-logging-1.2.jar [INFO] gr.hua.dit.oop2:calendar:jar:1.0.0 already exists in destination. [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.968 s [INFO] Finished at: 2023-12-09T12:05:10+02:00 [INFO] ------------------------------------------------------------------------
-
Έχουμε και εμείς το ίδιο πρόβλημα αλλά αντί για "cant fine symbol TimeListener" το έχουμε με TimeService την ώρα που κάνουμε compile αλλά στο πρόγραμμα δεν εμφανίζει κάποιο warning ή error.Τό πρόγραμμα τρέχει τέλεια από το terminal αφού το κάνουμε build and clean από το netbeans.Φανταζόμαστε ότι σε εσάς θα δουλεύει κανονικά αλλά μπορούμε κάπως να το κάνουμε τεστ για να είμαστε σίγουροι?
-
@it2022131 μπορείς να πεις πως σου δούλεψε τελικά;
-
χρησιμοποιουμε intellij και εχουμε κανει ολα τα βηματα που προαναφερατε, δεν υπαρχουν errors στα mvn clean install και package (η βιβλιοθηκη κατεβαινει κανονικα), την εντοπιζουμε στα αριστερα του intellij στα lib μεσα στο target ως calendar-1.0.0.jar, ωστοσο εξακολουθει να μην αναγνωριζει τα imports για το timeservice και timeteller. (δοκιμασαμε και την επιλογη του maven reload).
-
@acharal Ήθελα να σας ρωτήσω για ένα θέμα που έχουμε όταν κάνουμε mvn package. Όταν εκτελούμε την εντολή, δημιουργείται το target folder μέσα στο οποίο βρίσκεται το jar. Όταν εκτελούμε το java -jar calendar.jar <option> <filename> μέσα στο target folder λειτουργεί κανονικά, άμα αλλάξουμε Directory το .jar και το τοποθετήσουμε πχ στο Desktop δεν τρέχει και βγάζει το εξής error:
Exception in thread "main" java.lang.NoClassDefFoundError: gr/hua/dit/oop2/calendar/TimeService
at org.example.Calendar.printEventsUntilEndOfDay(Calendar.java:118)
at org.example.CalendarApp.main(CalendarApp.java:67)
Caused by: java.lang.ClassNotFoundException: gr.hua.dit.oop2.calendar.TimeService
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 2 more και το pom.xml το οποίο φτιάξαμε είναι με βάση το java-maven-skeleton απλά με ελάχιστες αλλαγές -
Αυτό είναι και το 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>org.example</groupId> <artifactId>calendar</artifactId> <version>1.0-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>11</java.version> </properties> <repositories> <repository> <id>gitlab-maven</id> <url>https://gitlab.com/api/v4/projects/41008035/packages/maven</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> </dependency> <dependency> <groupId>gr.hua.dit.oop2</groupId> <artifactId>calendar</artifactId> <version>1.0.0</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.31</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.7.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>3.20.2</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> <build> <finalName>calendar</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <release>${java.version}</release> <parameters>true</parameters> <showDeprecation>true</showDeprecation> <failOnWarning>true</failOnWarning> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.2.0</version> <configuration> <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>org.example.CalendarApp</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
-
Είναι φυσιολογικό: Όταν μεταφέρεις το
jar
σε άλλον φάκελο θα χρειαστεί να μεταφέρεις επίσης και τον φάκελοlib
που βρίσκεται μέσα στοtarget
. Εκείνος ο κατάλογος περιέχει ταjar
s των βιβλιοθηκών. Όταν ανοίγει η εφαρμογή ψάχνει να βρει αυτές τις βιβλιοθήκες μέσα σε αυτόν τον φάκελο που είναι στην ίδια θέση με τοjar
της εφαρμογής.Αν θες να μεταφέρεις την εφαρμογή σου ο πιο σωστός τρόπος είναι ένας άλλος που λέγετε fat jar. Με αυτόν τον τρόπο ενσωματώνει ότι χρειάζεται σε ένα μοναδικό "παχουλό"
jar
και μπορείς να μεταφέρεις μόνο αυτό.Κοίτα για παράδειγμα εδώ για το πως να φτιάξεις το
pom.xml
σου ώστε να παράγει τέτοια jars. -
Σας ευχαριστώ πολύ. Το ψάξαμε λίγο και εμείς και βρήκαμε το maven-shade-plugin. Αυτό προσθέτει στο calendar.jar τα jars των βιβλιοθηκών που χρειαζόμαστε και δημιουργεί και ένα original-calendar.jar χωρίς αυτά, που δεν χρειάζεται να χρησιμοποιηθεί. Υπάρχει θέμα να χρησιμοποιήσουμε το maven-shade-plugin και να μην το κάνουμε με maven-assembly-plugin που μας στείλατε;
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.3.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <createDependencyReducedPom>false</createDependencyReducedPom> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>org.example.CalendarApp</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin>```