Missing Java Build Path for Maven project - java

So I recently imported a project from Github into Eclipse and converted it to a Maven Project. However, when I try to add Libraries, the "Java Build Path" menu is missing from Properties. What's the issue and how can I fix it?

Generally you don't have to manipulate your build path entry manually when your project has the Maven nature, because that is already whay Maven is intended to do: "Manage your project dependencies" which means grabbing the needed versions, saving them into your local repository then use those downloaded artifacts in your project classpath when you run one of the mvn goals (depending on the dependencies scopes).

Related

How to include JRE library in an eclipse project that was cloned from github

How do I include the JRE?
The java build path does not give me any options, but the eclipse includes it by default for the projects created locally.Notice how the build path has no options, but my test project has it included on creation
Your Project has been cloned as a general project. Either configure it as a maven project by clicking on project. Or Easiest way is to remove project from workspace and import as a maven project again.

Eclipse fix project setup by updating pom?

In an eclipse project, I referenced a class that was currently not in project's build path.
In the context sensitive pop-up that opens by hovering the mouse over the error, "Fix project setup" option has offered me to add a jar to the build path of the project. This jar is in my local maven repository.
However, the "correct" way to fix it is obviously by adding the relevant dependencies to my project's pom, instead of adding this jar to the build path of the project.
So is there a way to configure eclipse, so that it won't offer to add a maven repo jar to the build path, but it will offer to fix the project's pom?
This feature used to exist in m2eclipse (the predecessor of m2e), see e.g.
https://blog.sonatype.com/2010/03/adding-dependencies-using-m2eclipse/ which shows a "Search dependency for XXX" quickfix above the "Fix project setup..." quickfix.
Unfortunately it didn't make it into m2e, see https://www.eclipse.org/lists/m2e-users/msg01130.html
Make sure:
your project is fine outside of eclipse using only maven/pom, mvn
clean install (or similar) in an external shell/console
your eclipse project has maven nature
Eclipse -> Project -> Build Automatically is checked
Refresh your eclipse project
Do something in the pom.xml (save file) should trigger a build

Idea IntelliJ. how creating maven project. what about pom.xml and .iml files

i just started with java, and created a project.
its maven project (i hadn't use maven yet)
so my project have two modules A and B.
and B depends on A, and A depends on some from remote maven repo. and B also depends on some remote repo.
its works fine in Idea IntelliJ and build jars fine.
but afaik .iml files are Idea IntelliJ specific. and pom.xml is maven specific.
and when i inspect files why all depedecy of project is written in .iml files and .idea dir instead of pom.xml(s)
if you want to see the real world source then here it is but its alpha project for learning java deeply.
and when i try to build project on travis-ci.org it unable to resolve dependencies of project
Meghraj,
I have forked your WebTrimmer repo here : https://github.com/ajorpheus/WebTrimmer and fixed a couple of issues which were preventing a successful build:
The travisci fails because you have three jars in the lib folder which are not available to the CI since it's doing a maven build. The fix was to remove those three jars and introduce corresponding maven dependencies as in this commit.
While adding the maven dependencies an exclusion was needed as noted here : The following artifacts could not be resolved: javax.jms:jms:jar:1.1
The WebTrimmerUI depends on the classes in it's sibling module WebTrimmerEngine, therefore a corresponding dependency is needed.
I have converted the project into a pure maven project which is IDE-agnostic. With the above changes, I can build the project from command line and expect that the travisci should be able to as well.
Regarding the question about why the dependencies are duplicated in .iml --- That's not the reason the CI job fails. The dependencies in that file are a snapshot of the dependencies in the pom.xml. This snapshot is updated when the maven project is re-imported manually by the user, or automatically if the maven project is set to 'Auto-Import'.
As Peter Lawrey mentioned in his comment above, if you add a jar to the project, maven does not know about it and it will be present only in the .iml file.
In general, to search and add a maven dependency, the following has always worked for me: https://stackoverflow.com/a/10178586/325742
Hope this helps !
You need to add dependencies to the pom yourself. The .iml files are for storing project specific settings for whatever project you are currently working on.
Having the pom files allows your maven builds to be IDE independent where as the .iml files require you to have IntelliJ.
You can exclude the .iml files from and version control you are using. You can also open an existing maven project directly via IntelliJ by opening its pom.xml and IntelliJ can auto import everything specified in the pom file and will generate new .iml files.

In eclipse, maven dependencies are overriding project dependencies

I have a "master project" that uses several "modules". The modules are in the pom.xml, but I also have the code for the modules as projects in Eclipse. I defined the modules as project dependencies both in "Properties|Project References" and in "Properties|Java Build Path". I also made sure all of the Eclipse projects are at the top of "Order and Export" in Java Build Path.
The master project is not recognizing changes to the modules within eclipse. When I press F3 to see the code, it opens java source from my .m2 directory. It's obviously ignoring my Eclipse projects. Am I missing some setting? What should I do?
You don't need to add the dependent projects into the Project references (at least when using m2eclipse-plugin), just add them as dependencies on your masters' pom.xml. I haven't had the need to touch the Build path since I've started using Maven in Eclipse.
Make sure you have enabled the Workspace resolution of the plugin by right clicking on project root -> Maven -> Enable Workspace Resolution. If it says "Disable Workspace Resolution", it is already enabled. You may also need to run "Update project configuration" under the same menu.
This way when you run your master-project from within Eclipse, any changes made to the other projects will be "visible" to the master (and you can actually use hot swap during runtime even on the other projects).
If you're using Maven, you pretty much want to commit to Maven. Even if you do configure Eclipse with Eclipse-specific dependencies, anytime you update your project configuration using Maven, it will do a complete rewrite of your configuration.
I strongly recommend converting any of your other project build dependencies into Maven-enabled projects that can be used as Maven dependencies.
In your specific case (through using the Maven modules), this means ensuring that each of your modules are imported into Eclipse as m2e-enabled projects. m2e will then automatically wire in the dependencies between modules and other dependent projects.
Im scratching my head as to why you would need your modules defined as dependencies on your top level project. Are you trying to avoid having to define the (cross) dependencies at a module level? In any case, as per other suggestions, first of all put your dependencies in the correct places in your POM, then either run
mvn eclipse:clean eclipse:eclipse
to update your Eclipse settings, or better still, make sure m2eclipse is installed and import your maven projects directly into the IDE.

Getting m2eclipse to match maven's classpath

I've got project with a few sub modules.
mvn clean install
works absolutely fine. But in Eclipse with the parent project open none of the maven dependencies are available and so all my Java source files are full of indicated compilation errors (they're not listed in the build path for the project). If I open one of the sub modules as a project there are no indicated compilation problems.
I've tried running
mvn clean install eclipse:clean eclipse:m2eclipsemvn clean install eclipse:clean eclipse:m2eclipse
and choosing project / update maven dependencies. Refreshing, closing and opening the project and Eclipse, etc.
Any ideas? Thanks in advance.
Getting m2eclipse to match maven's classpath
Just use Import... > Existing Maven Projects and import your multi-modules Maven project, that's all.
But in Eclipse with the parent project open none of the maven dependencies are available and so all my Java source files are full of indicated compilation errors (they're not listed in the build path for the project).
A parent project (i.e. with a pom packaging) is not a Java project, it's just there as a facility to make editing the parent pom.xml from the IDE possible (and that's already nice, importing nested projects inside Eclipse was initially not even possible).
If I open one of the sub modules as a project there are no indicated compilation problems.
That's how you are supposed to do things.
I've tried running (...)
You are not supposed to use the Maven Eclipse Plugin when using m2eclipse and this is not supported. Either use one or the other. If you decide to use m2eclipse, use Import... > Existing Maven Projects as suggested.

Categories