Eclipse资源文件夹与git& Maven的 [英] Eclipse resources folder with git & Maven

查看:166
本文介绍了Eclipse资源文件夹与git& Maven的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git / Maven(如果这与它有关系)在Eclipse上进行项目。我需要添加一个库文件夹,我需要的一些文件将被存储。这是我项目的树结构。





我尝试将文件加载到文件夹lib和lib2下,但没有成功。我的一些尝试是

  System.out.println(PATH+ this.getClass()。getResource(lib ).getPath()); 
System.setProperty(org.hyperic.sigar.path,this.getClass()。getResource(lib2 / file.xxx));

所有这些都给我一个NullPointerException。

我知道有一个已经在那里的一些答案,我想我已经尝试过了,最好的,这只是不行。



编辑: br>
在Kraal建议之后,我改变了我的项目,现在看起来像这样:


但是我仍然得到NullPointerException on

  System.setProperty(org.hyperic.sigar.path,this.getClass()。getResource(Sigar_lib / libsigar -amd64-linux.so)的getPath())。 


解决方案

这与git无关,项目结构。的确,它不遵循 Maven标准目录布局




  • 您的java类应该在 src / main / java

  • 您的资源文件应为src / main / resources中的



所以你有两个选择:




  • 更正您的设置,然后重试。

  • 在您的pom中配置Maven,以查看 lib / lib2 的资源。



在这两种情况下,您都可以在正确的位置查找资源。即 file.xxx 将位于 file.xxx 而不是 src / main / resources / file.xxx (一旦定义了一个资源目录,您可以搜索该目录中的资源)



根据您的意见,您应该真的阅读这篇文章解释如何在Eclipse中使用Maven 。当您打算在Maven项目上工作时,请在Eclipse中创建一个 Maven项目,而不是Java项目。


I have a git/Maven (if this has something to do with it) project on Eclipse. I need to add a library folder where some files that i need will be stored. This is the tree structure of my project.

I try to load the files under folders lib and lib2, but with no success. Some of my attempts were

System.out.println("PATH"+this.getClass().getResource("lib").getPath());
System.setProperty("org.hyperic.sigar.path",this.getClass().getResource("lib2/file.xxx"));

All of them gets me a NullPointerException.
I know that there are a bunch of answers already out there, I think I tried them all, ok most, and this just doesn't work.

EDIT:
After Kraal suggestions I changed my project and now it looks like this:
But i am still getting NullPointerException on

System.setProperty("org.hyperic.sigar.path",this.getClass().getResource("Sigar_lib/libsigar-amd64-linux.so").getPath());

解决方案

This is not related at all to git but to your project's structure. Indeed it does not follow the Maven standard directory layout.

  • Your java classes should be in src/main/java
  • Your resource files should be in src/main/resources

So you have two choices:

  • Correct your setup then retry.
  • Configure Maven in your pom in order to look in lib / lib2 for resources.

In both cases, you will then to look for resources at the right place. I.e. file.xxx will be located in file.xxx and not src/main/resources/file.xxx (once you define a resources directory, you can search for resources in this directory)

According to your comments, you should really read this post explaining how to use Maven within Eclipse. When you plan to work on a Maven project, create a Maven project in Eclipse, not a Java project.

这篇关于Eclipse资源文件夹与git& Maven的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆