How can I include resources (css, js) from jar using maven assembly?

user717847

I have a project which contains shared resources for several sub-projects; i.e. as well as Java code, it contains css and javascript.

My child sub-projects are packaged as jars using the maven assembly plugin. For some reason these do not include the css and js resources from the parent library.

So my question is simple: how can I configure the projects so that this happens? I don't want the child projects to be wars; they are dropwizard (/jetty) projects that run as standalone jars.

EDIT - I should make explicit that the resources are included in the parent project's jar; it's only when assembly (on a child project) includes the jar that they somehow go missing.

Parent 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>io.parentproject</groupId>
    <artifactId>parentproject</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        ...
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/webapp</directory>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.java</include>
                    <include>**/*.gwt.xml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgument>-proc:none</compilerArgument>
                    <fork>true</fork>
                </configuration>               
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>
                                true
                            </addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            ...
        </plugins>
    </build>
</project>

Example child 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>io.child</groupId>
    <artifactId>child</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>Child</name>

    <dependencies>
        <dependency>
            <groupId>io.parentproject</groupId>
            <artifactId>parentproject</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        ...
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/webapp</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgument>-proc:none</compilerArgument>
                    <fork>true</fork>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>
                                true
                            </addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>            
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>io.childproject.SomeClass</mainClass>
                        </manifest>
                    </archive>
                    <finalName>${project.artifactId}-${project.version}</finalName>
                    <appendAssemblyId>false</appendAssemblyId>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
             ...
        </plugins>
    </build>

</project>
user717847

I ended up using maven shade instead. It's a little more heavyweight than assembly but it does the job.

Still, if anybody knows how to make assembly do this please add an answer.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I include test classes into Maven jar and execute them?

From Dev

Maven: How can I run/include a class in a jar with the failsafe plugin?

From Dev

How can I include a set of jar's as a single dependency in Maven?

From Dev

How to include package.jar with maven-assembly-plugin

From Dev

How can I embed C# assembly resources in the same assembly?

From Dev

How can I embed C# assembly resources in the same assembly?

From Dev

How Can One Include Resources From Another Module In A Spring Boot Maven Multi Module Project

From Java

How can I create an executable JAR with dependencies using Maven?

From Dev

How do I get Android Studio to include resources in a .jar file?

From Dev

How to add files from webapp directory to jar using Maven Assembly plugin?

From Dev

How can I include css and js file in codeigniter

From Dev

How can I include css and js file in codeigniter

From Dev

How can I include ChromeDriver in a JAR?

From Dev

How can I include css files using node, express, and ejs?

From Dev

How to add resources to jar using maven shade plugin

From Dev

How to add resources to jar using maven shade plugin

From Dev

How to add classpath properties to executable jar using maven assembly

From Dev

How to configure a manifest file of a jar file by using the maven assembly plugin?

From Dev

How to use maven assembly plugin to exclude a package from dependency jar?

From Dev

Maven assembly or shade plugin - How to exclude sources from jar?

From Dev

How to include css and js files from controller using headLink helper

From Dev

Using Maven-assembly to pack single jar

From Dev

I wish to exclude some class files from my jar. I am using maven-assembly-plugin. It still adds the files. I dont get any error

From Dev

How can i call a assembly function from another assembly file?

From Dev

Maven javadoc - how to include centralized resources

From Dev

Apache MAVEN: How can I specify a jar dependency from a non standard repository without a pom in the repo?

From Dev

How can I exclude some packages (within a JAR) from a Maven dependency?

From Dev

How to access to resources from a JAR?

From Dev

How can I include a build number in the JAR file name?

Related Related

  1. 1

    How can I include test classes into Maven jar and execute them?

  2. 2

    Maven: How can I run/include a class in a jar with the failsafe plugin?

  3. 3

    How can I include a set of jar's as a single dependency in Maven?

  4. 4

    How to include package.jar with maven-assembly-plugin

  5. 5

    How can I embed C# assembly resources in the same assembly?

  6. 6

    How can I embed C# assembly resources in the same assembly?

  7. 7

    How Can One Include Resources From Another Module In A Spring Boot Maven Multi Module Project

  8. 8

    How can I create an executable JAR with dependencies using Maven?

  9. 9

    How do I get Android Studio to include resources in a .jar file?

  10. 10

    How to add files from webapp directory to jar using Maven Assembly plugin?

  11. 11

    How can I include css and js file in codeigniter

  12. 12

    How can I include css and js file in codeigniter

  13. 13

    How can I include ChromeDriver in a JAR?

  14. 14

    How can I include css files using node, express, and ejs?

  15. 15

    How to add resources to jar using maven shade plugin

  16. 16

    How to add resources to jar using maven shade plugin

  17. 17

    How to add classpath properties to executable jar using maven assembly

  18. 18

    How to configure a manifest file of a jar file by using the maven assembly plugin?

  19. 19

    How to use maven assembly plugin to exclude a package from dependency jar?

  20. 20

    Maven assembly or shade plugin - How to exclude sources from jar?

  21. 21

    How to include css and js files from controller using headLink helper

  22. 22

    Using Maven-assembly to pack single jar

  23. 23

    I wish to exclude some class files from my jar. I am using maven-assembly-plugin. It still adds the files. I dont get any error

  24. 24

    How can i call a assembly function from another assembly file?

  25. 25

    Maven javadoc - how to include centralized resources

  26. 26

    Apache MAVEN: How can I specify a jar dependency from a non standard repository without a pom in the repo?

  27. 27

    How can I exclude some packages (within a JAR) from a Maven dependency?

  28. 28

    How to access to resources from a JAR?

  29. 29

    How can I include a build number in the JAR file name?

HotTag

Archive