Weird deployement on Tomcat with Eclipse - java

I have been working on a Java (Java 8) web application in Eclipse, using maven for one year. I created this webapp and use Maven v 3.5 since the beginning of my project. I usually deploy my web application on a tomcat 8.5 server ('Run as => run on server').
I have always managed my dependencies with my pom.xml, preventing with doing weird things using hte build path configuration menu from Eclipse.
The issue started yesterday : I add a dependency from other java/maven project I have madeand installed simply before, and add this lines on my pom.xml :
<dependency>
<groupId>tlnPdf</groupId>
<artifactId>tlnPdf</artifactId>
<version>1.0</version>
</dependency>
As my eclipse does sometimes when I add a new dependancy from other project, I had an issue when deploying the webapp, some message (sorry but I can't remember it) about the pom.properties from my other project. In this case, and as I always did, I just have to close my webapp project, launch a mvn eclipse:clean from a command prompt and then reopen my project; and the issue disappear.
Eclipse doesn't show issue on the classes that import classes from the new dependancy included.
Also I have a listener on a class at the starting of my webapp, declared on my web.xml :
<listener>
<listener-class>com.package.InitTomcat</listener-class>
</listener>
This listener is funcional and I have not modified it lastly.
But yesterday, a new issue appear; when I wanted to deploy my webapp on my server, I had a lot of warning like this :
org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [...] to the cache because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache. And then, an error telling me that the InitTomcat class does not exist :
java.lang.ClassNotFoundException: com.package.InitTomcat
So, firstly I thought that the cache warning was causing the issue. I did what this this stackoverflow post explain, and the warnings disappeared; but not the error.
Outside from eclipse, in a command prompt, I try to compile my project and getting my app.war file using mvn clean install. The compilation did not show any error, and the war is correct. I deployed manually my war on tomcat and no issue appeared.
Thus, I look on the two deployed directory (one from eclipse, the other manually by my app.war) and I saw something curious on the tree of repository deployed :
On the good deployed webapp (from app.war), I have something like that:
|*some directories and files
|*META-INF
|*WEB-INF
|*classes
|com (etc...)
|*lib
|web.xml
And in the deployed webapp from eclipse :
*some directories and files
*META-INF
*WEB-INF
|*classes
|*.settings (why the hell does this directory are here ?)
|*bin
|*.settings
|*src
|*target
|*classes
|*com ect... (my .class files are here !!)
|*generated-sources
|*m2e-wtp
|*maven-archiver
|*maven-status
|*myapp (this directory have the same content as the "good web app deployed")
|*test-classes
|*WebContent
|*temp
|*webContent
|pom.xml
|.project
|*src
|*target
|*temp
|*WebContent
|*...
|*lib
|web.xml
The "good" webapp as a size of 275Mb, the other is 865Mb
I suspect that the issue occur when eclipse deploy my web-app and which explain that it could not find the InitTomcat class since it seems to be at the wrong place. But I have no idea why it decided to do this now.
I tries to delete the project from eclipse, cleaning eclipse, etc... but no result. I have tried with 3 different versions of tomcat : 8.5.14, 8.2.23 and 9.0.2, always with the same behaviour
As I was depressed, I download the last version of eclipse, and import my webapp project into it with maven; but it has the same result.
Finally, my question is simple : does anyone has an idea of what it is happening, and how to solve it ? Thanks in advance !

I finally saw where my problem was: looking on properties > "deployment Assembly" of my project, the deploy pathes were weird. I dont know when did he change, nor why, but I did the following to reinitiate "cleanly" them:
Delete the project (but not the sources) in eclipse
Manually delete .settings directory, .classpath and .project files
Import as a maven project in eclipse
These do the tricks. The issue is that before, I had not deleted the properties files from eclipse and the bag configuration was reload when importing the project.

Related

IntelliJ can't find Java class [duplicate]

Platform: IntelliJ Community Edition 10.0.3
SDK: jdk1.6.0_21
OS: Windows 7
So I have a strange situation with IntelliJ that has me completely stumped. I setup a Maven project and add log4j as a dependency in the pom.xml file. The IDEA inspections run fine and my unit tests all compile and run.
I then added hunnysoft's jmime library to my local maven repository using the mvn install:install-file as follows.
mvn install:install-file -Dfile=jmime.jar -DgroupId=jmime \
-DartifactId=jmime -Dversion=3.1.1e -Dpackaging=jar
Maven installed the jar file just fine into my local repository.
I then went into IntelliJ's Settings => Maven => Repository Services and Updated my local repository (so that IntelliJ would reindex the repository contents).
Finally, I added the following dependency to my pom.xml file (just above the log4j dependency).
<dependency>
<groupId>jmime</groupId>
<artifactId>jmime</artifactId>
<version>3.1.1e</version>
</dependency>
I now create a new class as follows:
package com.stackoverflow.question;
import org.apache.log4j.Logger;
import com.hunnysoft.jmime.ByteString;
import com.hunnysoft.jmime.Field;
import com.hunnysoft.jmime.FieldBody;
public class StackOverflowQuestion {
public Field create(String name, String text) {
Logger.getLogger(getClass()).debug("create entered");
FieldBody body = new FieldBody();
body.setText(new ByteString(text));
Field field = new Field();
field.setFieldName(name);
field.setFieldBody(body);
return field;
}
}
Now for the weirdness. IntelliJ's intention mechanism picks up and recognizes the Logger import in the maven pom file just fine. However, for all of the hunnysoft imports it reports: "Cannot resolve symbol 'ByteString/Field/FieldBody'", BUT Build => Compile 'StackOverflowQuestion.java' compiles everything correctly and the unit test I created for this class runs fine (though the intentions mark the call to create() as a problem area too).
So somewhere, somehow IntelliJ is ignoring the jmime.jar file for the intention subsystem. I'm confused because the log4j dependency works fine and everything compiles and runs fine. F12 ("Go To Declaration") works on the Logger import, but breaks on all the jmime imports.
Oh, one other thing, if I go to the 'Packages' view in the "Projects" window the "com.hunnysoft.jmime" package appears and I can see ALL of the classes I imported in the code snippet above under "Libraries". Removing the above dependency from the pom.xml file causes this package to disappear and the compilation breaks.
It appears that the inspection's classpath is broken, but there does not seem to be a setting for this anywhere in the Settings => Intentions | Compiler areas (not that I expected any such settings, I believe the IDEA should already know the correct classpath based on the pom file and JDK).
As a final experiment I created a brand new standard J2SE application project (without using maven) and added the jmime.jar file directly to the project as one of its libraries. I run into exactly the same problems as described above in this new project.
Here is the MANIFEST.MF from the jmime jar file.
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.5.4
Created-By: 10.0-b23 (Sun Microsystems Inc.)
Name: com/hunnysoft/jmime/
Sealed: true
Specification-Title: Hunny JMIME
Specification-Version: 3.1.1
Specification-Vendor: Hunny Software, Inc.
Implementation-Title: com.hunnysoft.jmime
Implementation-Version: 3.1.1E
Implementation-Vendor: Hunny Software, Inc.
I don't see anything unusual in this jar file.
My best guess is that perhaps the problem might be a missing dependency issue. But AFAIK jmime is supposed to be self contained (JarAnalyzer doesn't come up with anything, but I'm not sure it would if a dependency jar is missing).
So, anyone have any IDEAs?
First of all you should try File | Invalidate Caches and if it doesn't help, delete IDEA system directory. Then re-import the Maven project and see if it helps.
In some weird cases compiled classes may report wrong info and confuse IDEA. Verify that the classes from this jar report correct names using javap.
The following trick resolved this issue for me:
Right click on the code editor
Hover on Maven and expand
Click on Reimport
My idea version is 12.0.4
None of the solutions above worked for me. What did was removing the main.iml file manually and it suddenly worked.
This was mentioned in another answer to this same question here, but this alone fixes this for me. I do all my builds in a separate terminal, outside of IntelliJ. So the cache's need to have the proper permissions set for the IntelliJ app to read them.
Run it from the project's root folder.
$ mvn -U idea:idea
For Gradle users:
You may need to synchronize your project with your build.gradle file.
You can right-click on your gradle file under the Project pane to do this, but that didn't seem to do anything for me (I suspect a bug in my version). You'll know if this happens because it wont' kick off any IntelliJ tasks that you will be waiting on. Instead, open up the Gradle Tool pane, then click the synchronize (refresh) button. This worked for me where invalidating the cache and restarting did not.
My own circumstance: I was using a Scala project with Gradle and had to do this.
One extra step, when I did File -> Invalidate Caches and restarted the IDE, open a project. It popped up a toastbox on the top-right asking me whether to enable auto-import and that solved the problem.
Inconsistent/duplicate module names in project structure was causing this issue for me.
Go to File -> Project Strucutre -> Modules
In Click on modules which have red underline
Got to "Dependencies" tab
Make sure the dependencies which are red actually exist in dependency list. If not, rename them to match existing dependency names
This can happen when IntelliJ doesn't shut down properly and thus cannot properly save renamed module names.
Another thing to check: Be sure that dependencies are not duplicated. In my case I found that a module exhibiting this behavior was misconfigured as follows: it had a dependency on another module, and it had a dependency on a jar produced by that other module. This meant for every symbol referenced in duplicate, and was ambiguous.
Has a fixed been published? Appears issue originally affected v11/12 due to a "Compiler overhaul" back in 2013. With discussion on related issues in Jira up to end of 2014.
http://youtrack.jetbrains.com/issue/IDEA-98425
Also on Jira IDEA-98425 was marked fixed but unverified (on v12.0.3). None of the following work-around helped resolve this "Unable to Resolve Symbol" issue with Version 13.1.1 on Windows
a. Delete .IdealIC13 folder (Then, File \ Invalidate Caches / Restart)
b. From Maven Projects window,
b.1 mvn -U idea:idea –〉Executing this maven goal suppose to reload the dependencies. This works prev, but since last FRI, executing this maven goal failed as it tried to recompile the project (Of course it fails as "Unable to resolve Symbols", that's what I am trying to fix by running this command in the first place) mvn -version — shows maven version referenced 3.2.5 and that it's working
b.2 Simply right click project, and Reimport
b.3 File \ Invalidate Caches / Restart
c. Tried both Enable & Disable this setting: File -> Settings -> Maven -> Importing -> "Use maven3 to import project"
d. Settings \ Maven \ Multiproject build fail policy = Fail at end (instead of Default)
Nothing works. What's happenning to IntelliJ support on Maven.
https://youtrack.jetbrains.com/issue/IDEA-99302
From JetBeans release history, https://www.jetbrains.com/company/history.jsp
IntelliJ v14 NOV 2014
IntelliJ v13 DEC 2013
I'd assume v12 fixed (although unverified) would be incorporated in subsequent releases. Any one having similar problems with which IntelliJ version? Please share your experience. IntelliJ maven support seems broken.
Press "shift" two times > "Reimport All Maven projects" always works for me.
None of the other answeres worked for me. My imports were not being resolved because IntelliJ pointed to wrong .m2 file.
IntelliJ Version: IntelliJ Idea 2018.1.5
My location for the .m2 directory was pointed to the wrong path. All I did to fix it was re-point IntelliJ to the right .m2 directory and update it.
First, go to: File->Settings->Build, Execution, Deployment->Build Tools->Maven
I had to change the User settings file: and the Local repository: to the correct location of my .m2 directory.
After this go to: File->Settings->Build, Execution, Deployment->Build Tools->Maven->Repositories
and click the Update button.
I'm jealous of all of you who resolved through File / Invalidate caches. I just spent hours trying everything on this question and a few others from around the web.
The magic menu item didn't do it for me so I invalidated the caches myself by nuking %USERPROFILE%\AppData\Local\JetBrains\IntelliJIdea2020.3\caches
Once I did this and restarted IntelliJ (2020.3), the indexes were rebuilt and my errors went away.
My Project Structure:
src -> main -> scala -> mypackages
What worked:
Right click on the scala folder, and click "Mark Directory as Sources Root".
I had problem with Maven Importer JDK - somehow it switched itself to JDK 11, but Maven Project reload worked only with JDK 8.
Update 2022
IntelliJ 2022.1 has an interactive, step-by-step process File -> Repair IDE. It leads you through 5 steps in sequence to try and resolve this problem for the current project before invalidating the caches for all projects. From the IDEA documentation:
Refresh Project Indexes
Rescan Project Indexes
Reopen Project
Drop Shared Indexes
Reindex Project
Invalidate Caches and Restart
Steps 1- 3 fixed it for my project.
In v2022.3 and the new UI, this setting is now in File -> Cache Recovery -> Repair IDE. You can also select an individual step from there.
If your maven project is a multi-module project, check if some of the modules are ignored by intellij.
Click on View -> Tool Windows -> Maven Projects, and check if some modules are ignored(Ignored modules are in grey, e.g. gs-multi-module in the following image).
Right click on the ignored module and choose Unignore Projects.
Then wait for intellij to finish indexing, after which it will work.
For Gradle projects:
Exit IntelliJ IDEA
Delete the <problematic-project-root>/.idea directory
Delete the <problematic-project-root>/.gradle directory
Delete all .iml files in <problematic-project-root>
windows command prompt: DEL /S /Q *.iml
linux: find . | grep -e .iml$ | xargs rm
Re-import the project into IntelliJ IDEA with Gradle
In IntelliJ IDEA 2020.3, select:
File > Invalidate Caches / Restart... > Invalidate and Restart
When prompted with Download pre-built shared indexes:
don't import the shared indexes: close the dialog or choose More actions > Don't show again
Yes, sounds like you have to create libraries containing the JARs you need and add them as a dependency in your module.
For another alternative.
I got this problem also when I used JDK7_07. I tried all answers here (except deleting IDEA System Directory). But, I still got the problem. So what I did it is:
Install newest JDK (it was JDK7_45), and set the Intellij's JDK to the new one, and it works.
Re-importing the project worked for me.
Right Click on Project -> Maven ->Reimport
when I did File -> Invalidate Caches and restarted the IDE,open a project. It showed a dialogue on the top-right "Maven changes detected" and gave an option to import and enable auto-import. Even after importing the project here, I had the same issue. The above step solved the problem.
Suggested solutions did not work. I had to unignore several projects, by right clicking on the pom => maven => unignore project.
Then after a
mvn clean install -T 6 -DskipTests
in the console, IntelliJ was happy again. No idea how the projects became ignored...
Sometimes, I just open project structure, and click project, then choose a SDK version.
In my case, I am trying to open a spring boot project from IntellijIdea got the same issue like unable to import all spring related files.
Then I did:
File -> Close Project -> Import Project -> Import from external model -> Choose Gradle -> Next -> Select the project from file location -> Finish
Now everything working fine as expected.
I have seen many answers here but I finally found this solution. It may use for someone like me.
I just had this issue and it would just not go away. I eventually wiped out the IntelliJ config directory in ~ and rebuilt my IntelliJ project from scratch. (This only took about 15 minutes in the end, compared to spending an hour trying to work out problems with cached files, etc.)
Note that my guess is that the initial problem was caused by something like javathings.blogspot.com/2009/11/too-many-open-files-in-intellij-idea.html (NB: as of 2018, that link is dead, but archive.org has a copy of the page from around when this answer was first written -ed.) or a disk space/memory issue causing Java to crash. IntelliJ seemed to just get corrupted.
After invalidating my cache and restarting; and confirming my maven settings were okay, I was still seeing "Cannot resolve symbol" for a module that I definitely had set as a dependency. Turns out I had it set to the wrong scope.
You can check by right clicking on your module and selecting Open Module Settings. Click the dependency tab and verify that the scope for your un-resolvable dependency is set to Compile.
Open "Settings"
Search for "Maven"
Click on "Ignored Files" under "Maven"
Uncheck the pom.xml files contains the missing dependencies
Click "OK"
Click File -> Invalidate Caches/Restart...
Click "Invalidate and Restart"
mvn idea:idea worked for me. Found it here. Spent more than an hour, hope it helps someone
In my case, my project was using Lombok and I was missing the Lombok Plugin in IntelliJ. After installing it everything worked fine.
I tried
File -> Invalidate and Restart
which did not worked for me.
Solution that really worked :
Project Structure -> Modules -> select target folder -> Right click generated-sources and select sources -> Apply -> ok

Failed make using IntelliJ, JBoss due to multiple configuration issues including Pom.xml

Introduction
I have inherited a project that I am able to build using the maven command mvn clean install -DskipTests. However, I am not able to make using the inteliJ button. I am able to deploy the project using Remote debugging but I am not able to hotswap new code in/out due to make not working.
Errors during make
When I run make I get a series of errors such as:
Older Maven Version
I have been told to use an older version of maven, specifically 3.0.3 .
I have gone to the settings for the current project and manually set maven 3.0.3 as the default.
Question 1) Is there a chance this does not apply to the sub directories? Should I change my system path variable and set the old maven as the system default?
Red Highlighting in POM.XML
I am seeing that InteliJ is highlighting a pom.xml in one of the sub-modules for errors. This code has been committed by colleagues so it is strange that there would be errors.
and
and
Question 2) Could Maven be the issue here? Or could there legitimately be an error in the POM.xml?
Maven > Reimport does not solve the issue
Additionally, running Maven > re-import does not solve the issue.
Updating Indices
I tried selecting the proposed option to Update Maven Indices. This has brought up the following dialogs and is downloading in the background from both the maven servers but also a private artifactory.
The indices were taking too long to update so I invalidated the cache/restarted and will try again as proposed # Intelli J IDEA takes forever to update indices .
Summary of Questions
Question 1) Is there a chance this does not apply to the sub directories? Should I change my system path variable and set the old maven as the system default?
Question 2) Could Maven be the issue here? Or could there legitimately be an error in the POM.xml?
Update
Indices finished downloading after some time.
I removed some of the problematic entries in the pom.xml and the project now is not red-underlying the various packages that they do not exist.
I am starting to believe the pom.xmlwas problematic. However, if someone downloads the dependencies/indices, then the problem no longer appears.
Update - Remove Module
I talked with a colleague and he said the specific modules are no longer used (even if they do include faulty pom.xml files). I was told to right click the module and select "remove module". This pretty much stopped the problem.
I talked with a colleague and he said the specific modules are no longer used (even if they do include faulty pom.xml files). I was told to right click the module and select "remove module". This pretty much stopped the problem.

Why am I receiving this 404 Error in my Maven Dynamic Web Module?

I'm brand-new to Jersey/JAX-RS/RESTful Web Services/etc. and I'm having difficulty with a Jersey archetype called jersey-quickstart-webapp. I'm attempting to use it with Eclipse, Maven, and Tomcat v7 or v8 (I've tried both).
First I got a JSP error:
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path.
I resolved that error with this SO question regarding the error. Apparently Maven wasn't treating my project as a Dynamic Web Application.
Then I got a warning about:
Build path specifies execution environment JavaSE-1.7. There are no JREs installed in the workspace that are strictly compatible with this environment. I resolved the second issue with another SO question on the matter. I was originally using JavaSE-1.8.
Finally, I had one last error:
Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result.Again, I checked SO on the matter and excluded the associated raw classpath entry from the set of potential publish/export dependencies.
However, I am still given a 404 on my project and I cannot figure out why. I'm using a pom.xml file for this project. The tutorial I'm following is telling me that the correct URL to be using here is http://localhost:8080/messenger/.
This is not an answer (will be deleted)
Edit: Turned into community wiki. It's not a solution.
Try and add this jetty plugin to the app. Inside the <build><plugins> in the pom.xml file
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.6.v20141205</version>
</plugin>
Then Right click on project, Maven -> Build; in the dialog on the goals type jetty:run and try to run the build. This should start an embedded jetty server. Once the console says "Jetty Server started", you should be able to access http://localhost:8080/webapi/myresource. Just want to see if it is a problem with the app.
Fast Temporary solution:
Change webapi to webresources in the url: http://localhost:8080/webapi/myresource
Permanent solution:
Change the file web.xml
<url-pattern>/webresources/*</url-pattern>
to
<url-pattern>/webapi/*</url-pattern>

Configuration Error: deployment source '(projectname): war exploded' is not valid

I have a project that runs Spring and I am using IntelliJ as the compiler. I started building the project in Ubuntu but I was having problems viewing my database edits so I switched to Windows and lost my Ubuntu partition (due to some other unrelated error). I am trying to reset up my project in Windows but I can't get it to compile properly.
I have tried redownloading IntelliJ, restarting my computer, clean installing maven, and searching everywhere for a solution. I found a link on IntelliJ's website but they never actually address a solution to the problem ( http://devnet.jetbrains.com/thread/436515 ). I started to try the unfinished advice to "remove all artifacts selected for deployment from the list and then add them again" but I cannot figure out how to add them again once deleted.
Additionally, I keep seeing the error "Configuration Error: deployment source '(projectname): war exploded' is not valid"
Any advice or tips to what I could try or am doing wrong would be great.
Thanks!
This will happen when you remove an artifact that is already set in the configuration. You can see the artifact is red in the configuration:
To solve it, just removed the missing one and add another valid artifact.
Edit Configurations - deployment add your artifacts.
Maybe you can try the following process.
1.Open Project Structure add an artifact (web application:exploded) from modules, select your module, add it:
2.Build Artifacts [(top menu) - build - build artifacts - build]
3.Edit Configurations - deployment add your artifacts
I fixed the issue for me.
I do not know why, but for some reason my .war file got corrupted. I went to Project Structure > Artifacts, deleted my old artifact (which IntelliJ already highlighted red) and added it again.
One of the reason it may happen is, you have restructured your project packages. In that case you have to re-adjust your run configuration in the intelliJ. Edit Configuration > Deployment (On your server) > Delete the existing one and add newly build war again.
Long time ago, i faced similar issue. I made a Spring MVC webapp using IntelliJ on Ubuntu(Running on a VM).
Later on when i tried to run it on Windows IntelliJ, it went bonkers... so to fix that...
I deleted all IntelliJ configuration files, *.iml target WARs
and then it worked fine.
For those who restructured and/or moved a lot of files; a rebuild will fix this error
Build Artifacts (Top menu - Build - Build Artifacts):

Failed to read module

I am working on a GWT 2.4/Maven/Spring project that uses a JAR from another project. I have added a GWT module file (.gwt.xml) to the referenced JAR to make its classes translatable by GWT. Things worked fine for a while, then all of a sudden (i.e. after one of the many code changes) I am now getting this error in Eclipse:
Failed to read module XML file
sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream#68e72c
(org.codehaus.mojo:gwt-maven-plugin:2.4.0:compile:default:prepare-package)
pom.xml /PivotReportsWeb line 118 Maven Build Problem
PivotReportsWeb is the name of my GWT application. The error refers to execution inside the gwt-maven-plugin declaration in my pom.xml. However, Maven happily builds the project from command line with no errors or warnings whatsoever.
Forcing Maven to update project dependencies didn't work, nor did any of the many other tricks I've tried.
Any thoughts, anybody?
UPDATE
As it turned out, it was a Windows permissions issue! I noticed that I could no longer delete the referenced project's target folder or modify my user permissions on it (even though I am a local admin). So I rebooted and -- VOILA! Everything works again.
Reminds me of a geeky slogan I saw once on a friend's T-shirt: REBOOT IS SEXY

Categories