1

I want to make a fat JAR that contains the project classes and jdbc jar file. I saw this code to added to xml file before </project> tag.

 <target name="-post-jar">
 <property name="store.jar.name" value="AllInOneJar"/>
 <property name="store.dir" value="dist"/>
 <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
5 <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
 <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
 <zipgroupfileset dir="dist" includes="*.jar"/>
 <zipgroupfileset dir="dist/lib" includes="*.jar"/>
9 <manifest>
 <attribute name="Main-Class" value="${main.class}"/>
 </manifest>
 </jar>
 <zip destfile="${store.jar}">
 <zipfileset src="${store.dir}/temp_final.jar"
 excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
 </zip>
 <delete file="${store.dir}/temp_final.jar"/>
 </target>

When i Paste it I get this error : Malformed POM unrecognised tag 'target' How to solve it in netbeans please.

This is the whole POM

<?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>com.mycompany</groupId>
    <artifactId>lib_Management</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.27</version>
        </dependency>
<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>9.4.0.jre11</version>
</dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.8.4</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>assemble-all</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Charbel
  • 11
  • 3
  • try doing Select Project > Clean ... from the Menu. – gretal Nov 29 '21 at 08:18
  • 1
    That looks like something that goes in an Ant build.xml file, not something that goes in a maven pom. See the question I'm about to mark as a duplicate of this one for an example of how to do this using maven. – Federico klez Culloca Nov 29 '21 at 08:46
  • Does this answer your question? [Building a fat jar using maven](https://stackoverflow.com/questions/16222748/building-a-fat-jar-using-maven) – Federico klez Culloca Nov 29 '21 at 08:46
  • @FedericoklezCulloca I added the code listed in the question answer of building a fat jar using maven. I added it before but nothing happened automatically. How to proceed ? – Charbel Nov 29 '21 at 09:04
  • Automatically? You still need to build the package. Did you run `mvn package`? Did you check whether the `target` directory contains the fat jar? If it's still not working please update your question (without removing what's already there) with your updated pom. – Federico klez Culloca Nov 29 '21 at 09:08
  • @FedericoKlezCulloca You mean I should keep the code in my question and add the code posted in the question you attached in your previous comment? I add them. both to build. xml ? – Charbel Nov 29 '21 at 09:14
  • I mean please show your current pom after the one you already posted, at the bottom of your question. – Federico klez Culloca Nov 29 '21 at 09:15
  • @FedericoklezCulloca I added the build tag mentioned in the question you attached. Should I keep the target tag which is mentioned in my question ? Is there any editings should I do ? – Charbel Nov 29 '21 at 09:22
  • The pom looks fine. Did you run `mvn package` and check the `target` directory? – Federico klez Culloca Nov 29 '21 at 09:28
  • @FedericoklezCulloca Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/3.8.4/maven-assembly-plugin-3.8.4.pom The POM for org.apache.maven.plugins:maven-assembly-plugin:jar:3.8.4 is missing, no dependency information available Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/3.8.4/maven-assembly-plugin-3.8.4.jar – Charbel Nov 29 '21 at 09:31
  • That version doesn't exist (where did you get 3.8.4 from?). Latest is 3.3.0. – Federico klez Culloca Nov 29 '21 at 09:33
  • @FedericoklezCulloca Okay I edited the version to 3.3.0 the build success. Thank you very much. I really appreciate it. Now can I use Launch4J to make these 2 jars .exe ? – Charbel Nov 29 '21 at 09:38
  • @Charbel that's a different question entirely, and I honestly don't know the answer to that. You should research that (thoroughly) on your own, then research some more and if you come up empty handed research even further. Then, and just then, you should create another question. – Federico klez Culloca Nov 29 '21 at 09:40

0 Answers0