简体   繁体   中英

How to add non-jar files to classpath in Maven project?

I have a bigger project with multiple modules, all organized by Maven and Spring.

Now I got a "closed source" JAR and two additional files (basically sth. like 2 text files with some information needed for the classes in the JAR) that I want to add to my project.

The manual that came with the JAR and the two files only says "Add the JAR as a lib" and "Add the 2 files to your classpath". I (or my IDE) already managed to add the JAR, but how and where can I add the other 2 files?

Thanks in advance, kaolick

EDIT:

As it seems one of my colleagues already added the JAR and the two files to the repository. I just didn't know about it because he called in sick this week and didn't tell me before. :-/

You should place the files in src/main/resources folder then they will be on the classpath. As for the jar you should add it to pom as a dependency, eg

<dependency>
        <groupId>test</groupId>
        <artifactId>myjar</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/myjar.jar</systemPath>
</dependency>

You can upload the jar file to your local repository and then reference it like a usual library within your maven configuration. You can upload the file from the command line:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
    -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

See the documentation for more details.

As far as I know there's no specific way to add resource files to a project in Netbeans but it's quite legal to do it simply by copying the files into src/main/resources directory with your favourite file manager. Netbeans will recognize new files in the project straightaway and update the view.

I had to add the 2 *.dat files to the src/main/resources directory and the following lines to the pom.xml

<resources>
    <resource>
        <directory>src/main/resources</directory>
            <includes>
                <include>*.dat</include>
            </includes>
        </resource>
    </resources>
</resources>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM