How to make IntelliJ redeploy and put all necessary files back? - java

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.

Related

How to deploy to Tomcat a multi maven module from Eclipse IDE?

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.

project will treat maven dependency as a folder instead of a jar file and on run time gives ClassNotFoundError

In my maven project, I have this dependency which is my own project that is installed in my local maven (through cmd mvn install):
<dependency>
<groupId>com.myproject</groupId>
<artifactId>api-core</artifactId>
<version>1.0.0</version>
</dependency>
However when I start the tomcat server, I will get ClassDefNotFoundError on the classes within this project.
I tried to add the jar to the deployment assembly through the project's properties, however when I add this jar file, it is taken as a folder and will always be placed into the Deploy path of "WEB-INF/lib/core.api.1.0.0.jar" which is then a folder inside the lib, therefore tomcat isn't able to locate the jar file. I also noticed in the Web Deployment Assembly, the Maven Dependencies are deployed to WEB-INF/lib. Apparently my own jar file is not considered Maven Dependencies when it is being deployed. When I further look into the Maven Dependencies from Eclipse, the jar file is packed inside as "core" folder and it is not treated as a jar file. Therefore on run time, the web app has trouble locating the jar file and is giving me complain.
Further investigation shows that in Eclipse, I have the core project imported, and Eclipse is "smart" to recognize that project is the one generating the dependency, and therefore automatically convert the jar to the folder. If I remove the core project, the maven dependencies will then successfully added as a jar file, and then the deployment to tomcat issue not problem at all!
So, my question is, is it a way to keep the dependency in folder structure, while I can still have to core project imported to my workspace?
Yes, there is one: Show up the contextual menu of the web project, go to the Maven tab and uncheck the Resolve dependencies from workspace projects option: In this way, Eclipse will not interfere in Maven's dependency resolution chain.

Generate war file from existing maven project

I have downloaded a project from git. Its a web project using maven. I have eclipse in my machine and also maven is there. Now I want to create a war file from this project for deploying in Tomcat.
Any idea how I can do it. Command line will be a prefer option. I searched in Google but in most of the places it is asking to create a new Maven project or I am missing something.
Thank you
Just add <packaging>war</packaging> to your pom.xml, and run mvn package from the root of your project (i.e. where the pom.xml resides). If everything will be successful, you'll get a war file in the target directory. See: http://maven.apache.org/pom.html#Maven_Coordinates

Eclipse maven-enabled web app references workspace projects, but those are not deployed when running Tomcat server

I have a web application (Eclipse's Dynamic Web App) which uses Maven (m2e-wtp) for the build and dependencies management. This web app's POM references a few other projects in my workspace, which happen to be eclipse plugins built with maven as well (built using Tycho), and also other third party libraries which come from Maven's repository.
Everything works fine when I run maven from the CLI. All dependencies are included in the WEB-INF/lib directory just as expected.
The problem is when I attempt to run the project using Eclipse. I run the app in a configured Tomcat server inside Eclipse, but the referenced projects in my workspace are not added to the deployed war.
I tried adding them to the Deployment Assembly (under project preferences), and that works perfectly, but those settings get wiped out by m2e every time the maven configurations are updated. I read in a few places that we should not manually add entries there since all dependencies should be managed by m2e...
The question is: How to make Eclipse add the workspace project dependencies to the WEB-INF/lib of my web app when I run it from Eclipse?
I'm using Eclipse J2EE 4.3.1 (Kepler SR1).
I also tried right-clicking the project and selecting Export -> WAR file, but the exported WAR file doesn't include the referenced workspace projects either. I'm assuming the issue is affecting both cases.
This is extremely annoying ans is slowing me down quite a bit.. at this time I have to re-add the projects to the Deployment Assembly page several times a day to keep it going...
UPDATE: The workspace projects I added as dependencies in the POM appear in the list of Referenced Projects, under the project's properties. But when I expand the Maven Dependencies in the Project Explorer, the workspace project dependencies are missing from the list! Only the ones in the Maven repository show up. They local ones seem to be silently ignored...
I had similar problem because I created the project outside eclipse, and them imported it. What worked for me was to add the right project facet: Project context menu -> properties -> Project Facets -> Dynamic Web Module (choose right version). I was using Eclipse ADT (version 4.2.0), but, to avoid having multiple installations, I use the same eclipse for Android and other kind of apps.

How to have tomcat use folder with extension .jar as jar files?

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

Categories