I have a multi module Maven project with a common module which is a dependency of 2 others modules. One of this module generate a war which is integrated in the other one by overlay.
The final war is generated by Maven clean install command without problem. All the structure in target is OK.
But if I install a Tomcat 8 server in servers view (with 'takes Tomcat control installation' mode) and deploy the project, it's a nightmare...
I have tests resources in WEB-INF/classes, the common module (jar) is not deployed in WEB-INF/lib, the war which should be integrated during the build by overlay appears in WEB-INF/lib.
Is there a way to have a clean deployment without adding a Tomcat plugin in Maven configuration ?
For information, it is Neon version.
Deployment assembly are configured with src/main/* only (plus Maven dependencies).
We don't understand why Eclipse doesn't deploy the final application generated in target/xxx directory.
Ok, I found the problem.
Eclipse doesn't care about Deployment Assembly.
It mix Deployment Assembly AND Java Build Path.
When you import a maven project, the configuration of your project can be bad for an unknown reason.
Check the sources folders declared in Java Build Path and check specialy the output directory of each source folder.
For src/test/resources, it set a default output (not target/test-classes). So all tests resources were copied into target/classes.
And I don't know why he deployed to Tomcat this directory.
In Deployment Assembly, it just set these directories :
- src/main/java -> WEB-INF/classes
- src/main/webapp -> /
- /target/m2e-wtp/web-resources -> /
- Maven dependencies -> WEB-INF/lib
- link to others modules
Now all work perfectly.
Related
I have an eclipse workspace (for work) that has an ear project that I use to "export"/deploy an ear file to a JBoss server.
However, they recently asked me to create an ant script that can build the workspace and create the ear, and I have done this successfully. The problem arises when I try to run my program with this ear that was built using the ant script; for deploying I'm simply copying the resulting ear file and pasting it into the JBoss/standalone/deployments folder and running the application.
The JBoss AS starts fine, but then I get a few exceptions that halt my application that I do not get when I do a build and deploy through eclipse. The two ear files are identical when viewing the two ear files using 7zip, however I see in the eclipse workspace, in the ear project, theres a .settings folder that has 4 files, one of them being org.eclipse.wst.common.component and I'm guessing this (if not all 4 files) is necessary when deploying somehow.
Does ecplise use this .settings folder and the files inside when deploying an ear? What happens during this process? and how can I replicate it in an ant script so that my application runs identically from either ant or eclipse builds?
EDIT
let me just add that none of the files in the .settings folder get packaged up in the ear file, so I'm guessing they're somehow used when eclipse does a build/deploy, but it doesnt get placed in the final ear product
thank you
Eclipse uses the data in org.eclipse.wst.common.component to figure out the dependencies needed for deployment. The file corresponds to the settings found in Eclipse when Right-clicking on an EAR project > Properties > Deployment Assembly.
E.g. if your EAR project has a dependency on a WAR project then Eclipse knows to include the WAR when deploying because of the Deployment Assembly settings which get stored in org.eclipse.wst.common.component
When building the EAR using Ant you need to add these dependencies manually (without relying on Eclipse metadata)
IntelliJ has local Tomcat Run configuration and it's building project using internal build tool. I deleted all files from target directory. Now when I try to run IntelliJ configuration for web application it results in 404 Not Found error because IntelliJ did not put back all this files. How to make IntelliJ compile and deploy files?
In intellij there is such concept as Artifact, it reflects maven's pom artifact. So you can configure your project to produce specific file - it can be zip, war, jar, etc..
Go to project structure -> artifacts. There you can create or see your existing artifacts.
After you will see that paths are fine, and output layout is ok, you can rebuild artifact:
Build -> Build artifact.
Then artifact should be created in folder as artifact was configured.
You should list instructions to make your project and deploy it in the application server before launch configuration section and deploy section of your run configuration.
When using a Eclipse 3.7 Indigo for Java EE Developers, there is something called Deployment Assembly . I could find on google and understood that it is similar to the J2EE Module dependencies where in we could select the jar and which goes and sits in the EAR folder or in WEB-INF/lib in case of WAR. Now the doubt I have is,
I have a JavaProject Dependencies. I have added all the dependent Jars via classpath variable. Now the Dependencies Project is added as dependency to my Web Project TestWebProject. The compilation of the Web Project is correct but during runtime I get an error because some jar was not found. I could fix this my include jar in Deployment Assembly of Dependencies Project, which is a standalone project.
The question is that, why I had to fix the jar in deployment assembly since ,first, its a standalone project and second is if I would not have this deployment assembly , how could this be fixed?
I could find on google and understood that it is similar to the J2EE Module dependencies
It was called "J2EE Module Dependencies" until with Eclipse 3.5. After that version, it was renamed to "Deployment Assembly". But it's effectively the same in case of Java EE web projects.
The question is that, why I had to fix the jar in deployment assembly since its a standalone project
Because this way Eclipse will autobuild a JAR file of the project and put in /WEB-INF/lib of the web project's deployment. If you don't do that, the JAR isn't available during webapp's runtime, but only during compiletime and Eclipse expects that you've already built and placed it anywhere else in runtime classpath, e.g. server's own /lib.
if I would not have this deployment assembly , how could this be fixed?
Manually build/export the JAR and drop in webapp's own /WEB-INF/lib or server's own /lib. The "Deployment Assembly" configuration is however more easy and the recommended way.
See also:
Business Logic Layerin Servlet and JSP
When assembling a WAR, Eclipse cannot tell just by looking at your build path dependencies whether they are something that should be bundled in WAR's WEB-INF/lib directory or if they are something that you expect to be available on your server classpath. Extra metadata is needed to differentiate among those cases.
If you look in your problems view, you should see numerous warnings that look like this:
"Classpath entry [something] will not be exported or published..."
Right click on these and select "Quick Fix". You will see a dialog with available fixes. One of them is going to say something like "Mark the associated classpath entry as publish/export dependency...". Use that option.
The above will make a slight alteration to your Java project's .classpath file to tag the dependencies for inclusion in the assembly. You can test without running by exporting a WAR file and checking the contents of WEB-INF/lib folder.
Build path - place your jar's here directly, it will be available for code runtime and compile time.
Deployment assembly - eclipse expects the projects under this path to be bundled and deployed as .jar in web-inf/lib folder. So that it is available for both compile time and run time. If the project is not deployed in deployment assembly then the code is available only for compile time, eclipse won't bundle it and at run-time dependent projects are unavailable to the code.
I have in Eclipse web application project that depends from other projects.
When I run debug on embedded Tomcat in lib folder that Eclipse copied not jars, but folders with names like:
dependent_lib1.jar
dependent_lib2.jar
dependent_lib3.jar
....................
So web application don't start because didn't found some files. When I manually deleted all these folders and manually copy jar files - all works.
Does it possible ask Eclipse (or maven - this is maven project) to copy jars or ask Tomcat use folders like jars?
Thanks.
Here is how I think it should be done with maven:
If the other projects are also maven projects, export them as maven artifacts in your local repository. A nice article is Maven Deploy Plugin - If they are not maven projects you should manually generate the jar files and add them to the repository, some information can be found at Best way to create a maven artifact from existing jar
Add the exported artifacts as dependencies to your project. A lot of details can be found at Introduction to the Dependency Mechanism
Hope this helps.
Eclipse cannot do it as its just an IDE, you would need use A BUILD SCRIPT using ANT(Copy tag should do it) and run it before you start your server.
Check this for more details:
http://www.javabeat.net/tips/103-writing-simple-ant-build-script.html
I have a project that has 5 modules (I'm using maven)
In my module A I have 2 source folders: src/main/java and arc/main/resources
In my folder src/main/java I have a simple App.java (console app) that when I try to Run As -> Application in Eclipse doesn't find anything in my resources folder.
It doesn't find my log4.properties (which is in src/main/resources/log4j.properties) and it doesn't find a resources file app_es_ES.properties (wich is in src/main/resources/app_es_ES.properties)
How can I set my app to find in the resources folder my properties files? Could it be a problem with maven? Should I run my app in a different way?
You have to configure your eclipse project to match your maven configuration. This can be accomplished by either using the
maven eclipse plugin - mvn eclipse:eclipse to generate the eclipse project artifacts. Then import the generated project into the workspace.
m2eclipse eclipse plugin - much nicer (IMHO) as it integrates your maven and eclipse workspace. Thus your pom is used to manage your dependencies and eclipse .project and .classpath is kept in sync with maven.