Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a non-jar dependency to my maven project

I'd like to add an XML file to my project's dependencies. I've been pretty successful in doing this but unfortunately I've found that my XML file is not added to the classpath (which kind of makes sense as it is not a jar file).

The reason I want to have the XML file in my classpath is so that I could load it as a resource.

What is the recommended way of doing this, if it is at all recommended?

Thanks

like image 562
aeneid Avatar asked Jun 02 '13 08:06

aeneid


People also ask

How do we add a dependency to your Maven project?

Add a Java Maven Dependency to the Utility Project Right-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.

How do I manually add dependencies?

Click the dependency you want to add to your application. You can use Ctrl+click to select multiple non adjacent dependencies, or Shift+click to select multiple adjacent dependencies. Drop the dependencies to the Manual Dependencies folder of the application. Save the application.

How do I create a missing dependency in Maven?

You can find this in Window > Preferences > Maven > User Settings , and then point Global Settings to your external maven settings. xml . Then i removed the broken projects and re-added them, and the Maven Dependencies library appeared again.


2 Answers

Yes, put it in the resource folder. By default that's src/main/resources. If you put a file in there, it'll become available in your classpath.

Alternatively, you could modify your pom to say your folder where the xml file is in is a resource folder. But, I consider this a bad practice if your xml file is under your src/main/java directory.

like image 24
Daniel Kaplan Avatar answered Oct 06 '22 01:10

Daniel Kaplan


This solution works for me. I am using a WMQ table channel file from a Nexus repository.

        <dependency>
            <groupId>wmq</groupId>
            <artifactId>wmq-channel-tab-file</artifactId>
            <version>1.0.0</version>
            <type>tab</type>
        </dependency>

... 

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>wmq</groupId>
                                    <artifactId>wmq-channel-tab-file</artifactId>
                                    <version>1.0.0</version>
                                    <type>tab</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory>
                                    <destFileName>wmq-channel-tab-file.tab</destFileName>
                                </artifactItem>
                            </artifactItems>
                            <!-- other configurations here -->
                        </configuration>
                    </execution>
                </executions>
            </plugin>
like image 179
user2754985 Avatar answered Oct 06 '22 00:10

user2754985