eclipse中的Maven java项目没有看到同一个包中的类 [英] Maven java project in eclipse doesn't see classes in same package

查看:177
本文介绍了eclipse中的Maven java项目没有看到同一个包中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我刚刚开始使用maven来尝试构建一个多模块项目。



使用eclipse向导创建一个新的简单J2EE原型的maven项目由于eclipse中的错误而失败,因此当查找原型时,它将忽略代理设置(https://bugs.eclipse .org / bugs / show_bug.cgi?id = 348893)



解决方案是在命令行上创建我的项目,然后将生成的文件结构复制到simple maven '项目在我的工作区内 - 导入项目也失败!



然而,我的真正问题是以下



我点击项目文件夹并创建一个新的java类,它把类放在错误的地方,根据它应该在maven架构中(我选择错误的选项)。所以我移动它。



所以现在我创建一个第二个类,第一个类作为一个成员。两个类显然都在同一个包命名空间内。但是我看不到第二个成员类的任何方法。



我猜我在我的POM或我的结构中做错了



但我不知道什么,不知道你可能需要帮助我解决什么信息。



现在我已经恢复在eclipse中创建我的子模块作为单独的包,使用ANT和各种eclipse工具指向所需的库等,然后当我完成测试后,我将该项目转换为 maven'项目。完成此操作后,我的父POM和POM都会在eclipse内验证OK。但是再次,如果我决定扩展功能,并添加到一个新的类到我的模块,类文件最终在错误的地方,我看不到我的其他类(或从他们这个新的类)。 >

请帮忙。我喜欢Maven的想法,并使用它来控制我的依赖,按照事情的方式,我要去ANT,也许学习IVY进行依赖控制(虽然我有点不知所措,我们应该坚持ANT / IVY,忘记maven,但要保持未来的maven目录结构。 ?



编辑



所以我可能错过了一些东西...我刚刚再次尝试创建一个简单的maven在eclipse项目中,这一次我没有选择原型。
我把新的'module'放在父文件夹的下面。这不是我一直在做的,我创建了一个与我父母相同级别的外部模块。我从父母的有效POM(我的测试模块)注意到它有一个部分和其他标签。我可以通过将其添加到我的个人模块POM中来解决我的问题吗?

解决方案

查看你的.classpath。
验证源文件夹和目标是eclipse预期的位置。



一个例子:

 <?xml version =1.0encoding =UTF-8?> 
< classpath>
< classpathentry kind =srcoutput =target / classespath =src / main / java/>
< classpathentry kind =srcoutput =target / test-classespath =src / test / java/>
< classpathentry kind =conpath =org.eclipse.jdt.launching.JRE_CONTAINER/>
< classpathentry kind =conpath =org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER/>
< classpathentry kind =outputpath =target / classes/>
< / classpath>


I've just started using maven for trying to build a multi module project.

Everything would be fine other than 2 small problems.

Using the eclipse wizard to create a new maven project of 'simple J2EE' archetype fails due to a bug in eclipse whereby when looking for archetypes it ignores the proxy setting (https://bugs.eclipse.org/bugs/show_bug.cgi?id=348893)

solution is to create my project on the command line and then copy the resulting file structure into a 'simple maven' project inside my workspace - the import project fails also!

My real issue however is the following

When I click on the project folder and 'create a new java class' it puts the class in the wrong place, according to where it should be in the maven architecture (am I selecting the wrong option?). So I move it.

so now I create a second class, that has the first class as a member. Both classes are obviously inside the same package namespace. But I can't see any of the methods of the member class from my second.

I'm guessing I'm doing something wrong in my POM or in my structure.

But I don't know what and don't know what info you may need to help me resolve it.

For now I have reverted to creating my sub module as a separate package in eclipse, using ANT and the various eclipse tools to point to the required libraries etc. then when I've done testing I convert the project into a 'maven' project. My parent POM and child POM all validate OK from within eclipse after I have done this. But again if I decide to extend the functionality and add in a new class to my module the class file ends up in the wrong place and I can't see my other classes from it (or this new class from them).

Please help. I like the idea of Maven and using it to control my dependencies, by the way things are going I'm going to head over to ANT, and maybe learn IVY for dependency control (although I'm a bit muffed to have gone to all the struggle of getting maven to function only to throw it out!)

Should I stick to ANT / IVY and forget maven, but keep up the maven directory structure for the future?

Edit.

So I may have missed something... I just tried again creating a simple maven project in eclipse, this time I didn't select an archetype. I has put my new 'module' underneath the parent folder. This isn't what I have been doing, I've created a numer of external modules at the same level as my parent. I notice from the effective POM in the parent (with my test module) it has a section and and other tags. Will I solve my problem by adding this into my individual module POM's ?

解决方案

Look at your .classpath. Verify that the source folders and targets are where eclipse expects them.

An example:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java"/>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

这篇关于eclipse中的Maven java项目没有看到同一个包中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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