[英]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. 我有一个包含多个模块的更大项目,所有模块都由Maven和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. 现在我得到了一个“闭源”JAR和两个额外的文件(基本上是2个文本文件,其中包含JAR中的类所需的一些信息),我想添加到我的项目中。
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". JAR附带的手册和两个文件仅显示“将JAR添加为lib”和“将2个文件添加到类路径”。 I (or my IDE) already managed to add the JAR, but how and where can I add the other 2 files?
我(或我的IDE)已经设法添加JAR,但我如何以及在哪里可以添加其他2个文件?
Thanks in advance, kaolick 在此先感谢,高粱
EDIT: 编辑:
As it seems one of my colleagues already added the JAR and the two files to the repository. 因为我的同事似乎已经将JAR和两个文件添加到了存储库中。 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. 您应该将文件放在src / main / resources文件夹中,然后它们将在类路径中。 As for the jar you should add it to pom as a dependency, eg
至于jar你应该把它作为依赖项添加到pom,例如
<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. 您可以将jar文件上传到本地存储库,然后像maven配置中的常用库一样引用它。 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中的项目中,但仅仅通过使用您喜欢的文件管理器将文件复制到src / main / resources目录是非常合法的。 Netbeans will recognize new files in the project straightaway and update the view.
Netbeans将直接识别项目中的新文件并更新视图。
I had to add the 2 *.dat files to the src/main/resources
directory and the following lines to the pom.xml
我必须将2 * .dat文件添加到
src/main/resources
目录,并将以下行添加到pom.xml
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*.dat</include>
</includes>
</resource>
</resources>
</resources>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.