My project refers to the generated pom.properties file that Maven generates in:
META-INF/maven/${groupId}/${artifactId}
Which is included (in a Jar) as a dependency in another project. When I build / package the main project with Maven outside of Eclipse, the dependency Jar is built as expected (containing the pom.properties file) and all is well.
However, when I build / run the same (parent) project within Eclipse, it's not there. What am I missing?
Using Eclipse, a Jar library of the dependency is there (in the lib folder), containing everything except the Maven generated files. So in my case:
META-INF/
META-INF/persistence.xml
META-INF/MANIFEST.MF
~~~ snip ~~~
The dependency project exists in the same workspace and I have "Workspace Resolution" enabled.
Looking at the build target folder in Eclipse (\target\classes), I can see all the files that Eclipse uses for the Jar, so I can only assume that Eclipse treats it as a "regular" Java project (despite the parent project listing it as a Maven dependency in the POM) - so Maven doesn't get involved in the packaging.
How can I get Eclipse to treat the project dependency as a Maven project / so that the generated pom.properties will be included in the Jar used by the parent project?
Update
For the parent (War) project, the following structure is generated whenever I use Eclipse to build the project (using "Build Project" or "Build Automatically" not "Maven build"):
target\m2e-wtp\web-resources\META-INF\maven\${groupId}\${artifactId}\pom.properties
This is referenced in the Eclipse deployment assembly:
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
So that when the War is deployed to Tomcat, the META-INF\maven... structure exists at the root of the archive.
The dependency / Jar project obviously has the same "Deployment Assembly" facility in Eclipse, so I just need to figure out what creates the m2e-wtp folder on build and apply it to that project too.
Actually, I don't think you can with the default Eclipse Jar-Export.
The best you can do if you want to do it from within Eclipse is to have a Maven Build run configuration which doesn't do much differently than using Maven outside Eclipse. But at least you have a button in Eclipse to click do generate the jar, if that's the main reason. But the normal Eclipse functionality to produce a jar (File > Export...) ignores all Maven settings.
Workspace Resolution only works for compiling and running code, but not for other Maven functionality.
Related
I have 2 workspaces in which I am trying to use an ANT build to build an ear file. The one workspace uses 3 different projects to build the ear. I needed to create a single workspace to create the same ear. I migrated all of the source code, properties files, etc. to build this ear. The compile is breaking on this line:
<artifact:pom id="parent-pom" file="./mvn/parent/pom.xml" >
<profile id="${deploy.name}" />
</artifact:pom>
I have the pom file in the folder in the project.
The error is:
Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:pom
This build file has the artifact added at the top of the file:
<project name="Ant XML Library for Deploying" default="usage" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
The 2 workspaces are using the same compute and same Eclipse environment. I searched the other projects for the jar, maven-ant-tasks.jar but it is not any of the projects in the workspace that is correctly building the ear file.
The only jar files that are in a lib folder in one of the projects are these:
ant-contrib.jar
cm-anttasks.jar
jsch-0.1.41.jar
log4j-1.2.8.jar
I tried adding these to the workspace that is not working but it does not work.
Any ideas as to what I need to add to the workspace?
Thanks.
I added maven-ant-tasks.jar to my project and it now recognizes the commands.
However, my initial workspace did not need this jar included into the project. It recognized the commands.
I want to convert a Java/Dynamic web project to a Maven project. I use Eclipse IDE to develop Java applications.
One of the straight forward options available to me is to use 'Convert to Maven project' in Eclipse. But there are situations where I cannot use that option since the Maven plugin doesn't work in some networks like my Work environment.
So I want to know a Maven command (on Command Line) that would help me convert my Eclipse-built Java Web App to a Maven project.
Thank you in advance, Happy learning.
The Eclipse feature "Convert to Maven Project" works on projects that already have an appropriate POM. A project that was initially created by Eclipse doesn't have that POM.
So what you must do, is simply create a POM with packaging type WAR, then put it into the root of the project.
You also have to take care of the source directories. The Maven standard way is to have all sources under these four directories:
src/main/java
src/main/resources
src/test/java
src/test/resources
Eclipse simply stores everything under src. So you either change your file and directory structure, or you change the appropriate <build> parameters in the POM. I suggest the former.
The "Convert to Maven Project" feature does more than adding the Maven nature to the Eclipse build settings. It also creates and configures the Eclipse project meta files (the files .project and .classpath and the folder .settings). Therefore I suggest to delete them first in your project directory, so Eclipse can start on a clean project.
Afterwards you simply can convert your project with the above mentioned feature. It should create the meta files, and - as it is a web project (packaging type WAR) - it also should add the appropriate natures that let Eclipse show the project as a web project.
I am working with Eclipse Luna.
I have a dynamic web project into my workspace: project-web. This project depends on another project into my workspace: project-lib.
So I get this scenario: project-web[:war] ---depends on--> project-lib[:jar]
I have checked "Resolve dependences from workspace projects" option into Properties -> Maven for the web project.
When I run "mvn clean package" for project-web Maven creates war file into the target directory but I have
an issue. If I explode the war file, I find an empty folder called "project-lib" into the WEB-INF/lib directory.
Since the library is empty I get some java exceptions on Tomcat startup.
How to create the war for project-web correctly?
Thanks in advance.
Enrico
I have 3 different projects that use some global stuff
So i created a 4th project that is called "Shared Project"
Now, If i add this project to each of the other project's class path (via eclipse - > java build path - projects - > add "Shared Project"
I can debug with the shared stuff and its working well. But when i export the project into a WAR the files from the dependent project are missing
What I would like to do is - when i export a project to war it will add the shared project as a jar as well.
Is it possible?
Right-click on the spring web project, and select Properties, and select Deployment assembly. Here you can add projects . Later when you export as war, dependancy classes will be jared in to lib folder
I setup a Google App Engine project in Eclipse. I added a root level folder to contain libraries for my project. I added all of these libraries to the build path for my project. The code compiles without any errors. When I run the project, I get startup errors NoClassDef errors. When I add these libraries manually to the war directory's lib folder, these errors disappear.
Why isn't Eclipse deploying the libraries on my build path for me? Do I need to have a build script in place for Eclipse to run? A build script that will copy my libraries to the war dir's lib folder?
For standard Java EE project libraries have to be under {web-app}/WEB-INF/lib folder. GAE requires them to be there too to upload to the engine with your code.
Alternatively you can use Maven to define your dependencies and deploy to GAE
UPDATE: GAE project follows standard Java EE project structure to build and deploy a war file. The convention is that your lib folder is in {web-app}/WEB-INF/lib. Google plugin automatically generates such a structure (example from plugins docs):
MyTestProject
src/
log4j.properties
META-INF/
jdoconfig.xml
com/
mytestproject/
MyTestProjectServlet.java
war/
index.html
WEB-INF/
appengine-web.xml
web.xml
logging.properties
classes/
lib/
...App Engine JARs...
The plugin does allow to change location for your "war" directory, but not the location of your libraries since it should follow the Java EE standard.
You can add the libraries to your war/lib directly, and then right click on the libraries to add them to your build path.
Not sure why it doesn't deploy libs on your build path, but I have been working with Eclipse for years and have always done it the way I described. Then I just deploy through eclipse and don't use a build script.
If the library which was not added to lib folder is being developed in the same workspace, I would suggest to enable the "Utility Module" facet in project properties of the library project. Sometimes Eclipse doesn't copy a jar into WEB-INF/lib folder even if the Deployment Assembly and everything else was configured properly.