I'm working on a project with many modules. I would like to have a single command to build each module and generate Eclipse configuration files, but when I run mvn eclipse:eclipse on the parent pom, Eclipse does not see the dependencies and gives me this error: 'module2' is missing required Java project: 'module1'. When I run the same command in the folder for the module instead of the parent folder it works fine.
The project is set up like this, where module2 depends on module 1.
.
|-- module1
| `-- pom.xml
|-- module2
| `-- pom.xml
`-- pom.xml
Here's a comparison of the .project and .classpath for when I run mvn eclipse:eclipse in the parent folder vs the module folder:
$ diff module_project parent_project
5c5,10
< <projects/>
---
> <projects>
> <project>module1</project>
> </projects>
$ diff module_classpath parent_classpath
15c15
< <classpathentry kind="var" path="M2_REPO/path/to/module1/module1-0.1.jar"/>
---
> <classpathentry kind="src" path="/module1"/>
How do I get this working without running the command on each folder individually?
By the way, here's the version numbers that I am using. Eclipse and maven were both installed using apt-get on Ubuntu 13.10.
Eclipse:
Version: 3.8.1
Build id: debbuild
Maven:
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.11.0-15-generic", arch: "amd64", family: "unix"
If you run the command eclipse:eclipse from the parent folder, you need to open both of your projects 'module1' & 'module2' in the same workspace in order for it to work.
In the first case :
<classpathentry kind="var" path="M2_REPO/path/to/module1/module1-0.1.jar"/>
if you want to run your project 'module2' from eclipse it will look for its dependency 'module1' in the repository, that's mean any change you made in 'module1' won't be available for project module2 until you install it in the repository.
In the second case :
<classpathentry kind="src" path="/module1"/>
any change you made to project module1 will be immediately available for project module2, because the two projects are linked directly in the same workspace.
Related
I am using gradle builds for our build process and need eclipse for our development environment. Gradle expects the hibernate.cfg and .hbm files in a folder main/resources inside of the src folder. But eclipse expects it directly inside of src folder.
Gradle
- src
- main
- resources
hibernate.cfg
package/path/.hbm files
Eclipse
- src
hiberante.cfg
package/path/.hbm files
To get it working on eclipse I have modified the .cfg file to have mappings with the folder prefixed. But when I do a gradle build, the below hack fails and I get a 'org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found : main/resources/com/mnox/database/hibernate/pojos/v2/Booking.hbm.xml :`
<mapping resource="main/resources/com/mnox/database/
EDIT 1
I tried the following, did not work for gradle.
To fix the issues I did the folllowing
I moved all the .hbm files from src/main/resources/package/path to src/package/path.
I retained the .cfg file in src/main/resources
In the .cfg file I ensured that the path was package/path/Booking.hbm.xml
Both Gradle and Eclipse now work.
EDIT 2
apply plugin: 'java'
repositories {
jcenter()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
testCompile 'junit:junit:4.12'
//compile files('src/com/mnox/database/hibernate/pojos/v2')
}
jar {
baseName='databasepojos'
from ('src/com/mnox/database/hibernate/pojos/v2/*.xml')
// from ('build/classes/main')
}
sourceSets {
main {
java {
srcDir 'src'
//includes = 'src/com/mnox/database/hibernate/pojos/v2/**'
//includes = ["**/*.java"]
}
}
}
allprojects {
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
FileTree hbmfilesFrom = fileTree(dir: 'src/com/mnox/database/hibernate/pojos/v2/*.hbm.xml')
task copyHBMXMLFiles(type: Copy) {
from hbmfilesFrom
into 'build/main/resources/com/mnox/database/hibernate/pojos/v2'
}
EDIT 3
My .classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="build"/>
</classpath>
Assuming that your application and/or tests are referring to hibernate.cfg via the classpath all you need to do is make sure that src/main/resources is a classpath folder in both gradle and eclipse.
In gradle that's simple as this is the default
I'm not sure how you are generating your eclipse project but src should NOT be on the classpath. It should be src/main/resources plus the compiled classes directory.
I advise against manually creating an eclipse project for your gradle project
Do you know there's the buildship eclipse plugin?
Alternatively, do you know that you can generate .classpath and .project using the gradle plugin?
I have a servlet/jsp web project which runs fine on eclipse and is exported as war fine (once I clean it that is). I mavenized the project deleting all of the dependencies from the WEB-INF\lib folder except a homebrew jar (the output of another project in the workspace). When I run the package maven goal I get messages for missing classes from this jar:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
#..... NOTICE THIS COMES FROM A CUSTOM JAR
[ERROR] /C:/path/DataServlet.java:[3,30] package xxx.java.helpers does not exist
Now this has been asked before and the most rigorous solution appears to be to create a local repo: Can I add jars to maven 2 build classpath without installing them? (NB: I am at maven 3).
I would like to avoid this - so is there any way maven will just stuff this jar to WEB-INF\lib in the war ?
Solutions that use some maven plugin to cp the contents of the WEB-INF\lib in the war are welcome - although I just have this feeling that there should be a solution that takes into account the "special" nature of this folder.
Observations:
Alt+F5 removes this line:
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
which corresponds to the "Web App libraries" in the Java Build Path. So not only maven refuses to take into account the WEB-INF\lib - it also breaks the build path of eclipse completely.
Related:
Maven: How to include jars in Eclipse, which are not available in repository?
Uses the maven eclipse plugin : update my classpath with an Eclipse User Library via the maven eclipse plugin - not compatible with m2e
How does the m2e eclipse plugin interact with eclipse? - apparently m2e checks the pom then calls the eclipse builders (hence the .classpath is read)
Eclipse maven-enabled web app references workspace projects, but those are not deployed when running Tomcat server
Deploying a Maven project with dependencies to Tomcat or Jboss running within Eclipse
Did you add this jar from WEB-INF\lib as a dependency like this:
<dependency>
<groupId>someGroupId</groupId>
<artifactId>someArtifactId</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/homebrew jar</systemPath>
</dependency>
I have created this Java project using struts, hibernate in Eclipse Helios,
Now I want to integrate this project with Maven how to do it?
I have installed Maven In Eclipse already.
Tutorials, blogs, websites that I have found so far are explaining integration of some project into Maven outside Eclipse and then importing it in Eclipse or crreation of New project with Maven.None of them so far addressing my Problem.
As I mentioned I have created a project in Eclipse already Now I just want to integrate it with Maven, how to do it?
In eclipse you can easily convert a java project in a maven one right clicking on project -> configure -> convert to maven project.
While an IDE "importer" can sometimes be handy, it is not required to turn a project in Eclipse into a maven project. Basically all you just need is to add a pom.xml file and follow maven's conventions - or configure it.
By using the maven-eclipse-plugin it is actually possible have a maven itself generate the necessary files to integrate your maven project with eclipse:
Start from the command line
Go to your project's root
Create a new pom.xml file from a simple template or initiate a new project folder structure (including a pom) using mvn archetype:generate
Type mvn eclipse:eclipse.
Then maven has generated the necessary files to integrate with eclipse.
That said, maven by convention expects a certain folder structure of your Java project. It looks like this:
my-app
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- com
| `-- mycompany
| `-- app
| `-- App.java
`-- test
`-- java
`-- com
`-- mycompany
`-- app
`-- AppTest.java
So unless you already have this structure, you need to move your source code to main/java (and unit test code to test/java).
Further if your project has dependencies to other projects; then you need to express these dependencies in Maven's pom.xml file. If your dependency projects are stored in the Maven Central this is particularly easy. To express a dependency to e.g. Apache Commons - you would add this to your pom.xml:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
...
</dependencies>
...
</project>
After these initial attempts to integrate your project with maven, you can try to build with mvn compile from either the command line - or using the m2eclipse plugin for Eclipse.
I use maven and eclipse (with m2eclipse) for Java projects. I usually start with
$ mvn archetype:create \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.whatever.app \
-DartifactId=wonderapp
$ mvn eclipse:eclipse
and then import the project into eclipse. The build path in eclipse now contains an "Excluded: **" pattern for the src/main/resource path. If I put for example the log4j.properties file in src/main/resources, it will not be copied to the output path and hence log4j won't work properly.
(source: skitch.com)
After I ran mvn eclipse:eclipse, the .classpath file in the root directory contains this line:
<classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
After importing in eclipse, it has changed to:
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
I end up having to manually remove the "**" pattern. Is there any way so that I don't have to do this?
I use maven and eclipse (with m2eclipse) for Java projects. I usually start with (...) and then import the project into eclipse.
Why do you use mvn eclipse:eclipse with m2eclipse? Just create your project and then Import... > Existing Maven Project.
I've been doing just simple archetype projects until now, and always after dependencies definition and saving pom.xml, immediately after that the Maven Dependencies library was full of libraries. But now I declared:
parent(pom packaging, scm, repository management)
parent(pom packaging, shared dependencies)
actual project (jar packaging, few more dependencies)
actual project (jar packaging, few more dependencies)
I created them from the upper one by "Create module" ... Problem is, that I can't make it automatically fill the Maven Dependencies library
In .classpath file there is this line <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> as in other "working" projects, but there is nothing on the classpath. Any suggestions please ?
Can you run mvn dependency:tree on the command line for the child project and confirm that you see the expected dependencies. If you don't, then there is something wrong with your poms (that you will have to post to get more help).