How to add a folder via Maven to build path

Asked

Viewed 810 times

4

I have an application using Jhipster, to make queries I added querydsl, configured in Maven to generate Q classes, these classes are being generated in the path: target/generated-sources

Except that this folder is not in my Buildpath so the project is "broken" in eclipse, I know that via eclipse I can go in this folder and add to the classpath of the application, but I wonder if it has how to add via Maven, so it would be transparent to other developers.

Thanks in advance.

  • One way I discovered was to execute the mvn eclipse:eclipse command

1 answer

2


The Goal eclipse:eclipse is able to generate a valid configuration for Eclipse based on your pom.xml. Basically what it does is overwrite the file .classpath of your project.

The problem with that is that every time you change the pom.xml need to run the command again and the compilation and execution performed within Eclipse generally does not respect all Maven settings, since they are executed separately.

Integrating Maven into Eclipse is preferably done using the M2E plugin, which is installed in Eclipse and comes in "Eclipse for Java EE". This plugin configures recognizes changes in Maven and can make the necessary updates in Eclipse. It also allows you to run auto-generation code when you save your classes, plus other facilities.

If M2E does not add the generated classes to the classpath automatically, it is because its pom.xml using the build-helper-plugin to add the directory where classes are generated. See examples of use in documentation.

Remember that the Eclipse classpath and Maven classpath are different things. Be careful not to fall into the trap of changing the Eclipse project manually and find that everything is fine. In a Maven project, the Eclipse classpath is just something that should be derived from the Maven configuration and may not faithfully reproduce the classpath when you run Maven per command line.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.