IntelliJ can't find installed packages - java

I've just installed IntelliJ and imported a Maven / Spring Boot project. I've set up my run configuration as "application", but when I try to run it, it fails and complains of not being able to resolve dependencies. When I check my local Maven repository, those dependencies are installed:
/Users/user/Projects/myapplication/src/test/java/com/something
/SomethingServiceTest.java:23:29
java: package org.junit.jupiter.api does not exist
local maven repo:
$ ll ~/.m2/repository/org/junit/jupiter/
total 0
drwxr-xr-x 6 user Users 192B 21 Aug 2020 ./
drwxr-xr-x 6 user Users 192B 2 Sep 2020 ../
drwxr-xr-x 3 user Users 96B 21 Aug 2020 junit-jupiter/
drwxr-xr-x 3 user Users 96B 21 Aug 2020 junit-jupiter-api/
drwxr-xr-x 3 user Users 96B 21 Aug 2020 junit-jupiter-engine/
drwxr-xr-x 3 user Users 96B 21 Aug 2020 junit-jupiter-params/

IntelliJ and the pom.xml are probably not in-sync.
Right click on the pom.xml and Maven -> Reload Project

I've been the same problems. Sometimes I try to remove or change the name of the ~/.m2/repository directory.
After that, I make
mvn clean compile and install
Try this.

Related

Unable to run mvn release:prepare from IntelliJ using bundled Maven

I have a Maven project in IntelliJ working with the bundled version of Maven however when I come to do a release:prepare release:perform directly from within the IDE I get the following error.
Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project XXXXXX: Maven execution failed, exit code: '126'
Within IntelliJ I am using a project specific JDK (JDK 8) which is different to my machine JDK (JDK 11). I also am using the bundled Maven 3 with IntelliJ 2020.1 but have no Maven installed on my machine outside of the IDE.
I don't use JDK 8 or Maven anywhere other than this one project so would like to not have to install the extra tools globally if I can get away with running then from within this one project in the IDE. Is that possible? I'm building a Jenkins plugin for context if that matters?
Question: What is exit code 126?
Question: In order to perform a release:prepare release:perform do I need to to install the bundled project specific tools on my machine as opposed to keeping them within my project in IntelliJ?
Edit: Running with -x or --debug yields this error:
[INFO] Executing: /bin/sh -c cd /home/XXX/Development/XXXXX-plugin && /home/XXXX/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/201.7223.91/plugins/maven/lib/maven3/bin/mvn -s /tmp/release-settings2724175258197430802.xml clean install --no-plugin-updates -P jenkins
/bin/sh: 1: /home/XXXX/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/201.7223.91/plugins/maven/lib/maven3/bin/mvn: Permission denied
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
It appears to be this bug: https://youtrack.jetbrains.com/issue/IDEA-139236
Which is duplicated by: https://youtrack.jetbrains.com/issue/IDEA-157229 that contains the following workaround:
Using a newly generated plugin project using the
maven-archytype-plugin, when I tried running the default integration
test, it failed due to the following error:
/bin/sh: /Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3/bin/mvn: Permission denied
When checking the /Applications/IntelliJ IDEA
14.app/Contents/plugins/maven/lib/maven3/bin/:
evil-jim-klo:lib2 jklo$ cd "/Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3/bin/"
evil-jim-klo:bin jklo$ ls -l
total 88
-rw-r--r--# 1 jklo admin 183 Dec 21 04:08 m2.conf
-rw-r--r--# 1 jklo admin 5063 Dec 21 04:08 mvn
-rw-r--r--# 1 jklo admin 5985 Dec 21 04:08 mvn.bat
-rw-r--r--# 1 jklo admin 5253 Dec 21 04:08 mvnDebug
-rw-r--r--# 1 jklo admin 6167 Dec 21 04:08 mvnDebug.bat
-rw-r--r--# 1 jklo admin 5539 Dec 21 04:08 mvnyjp
Note none of the files are set to executable. The expectation is that
all maven binaries should be executable by default upon installation
or application update.
I corrected the problem by performing:
chmod a+x *
chmod a-x m2.conf
to produce the following permissions:
evil-jim-klo:bin jklo$ ls -l
total 88
-rw-r--r--# 1 jklo admin 183 Dec 21 04:08 m2.conf
-rwxr-xr-x# 1 jklo admin 5063 Dec 21 04:08 mvn
-rwxr-xr-x# 1 jklo admin 5985 Dec 21 04:08 mvn.bat
-rwxr-xr-x# 1 jklo admin 5253 Dec 21 04:08 mvnDebug
-rwxr-xr-x# 1 jklo admin 6167 Dec 21 04:08 mvnDebug.bat
-rwxr-xr-x# 1 jklo admin 5539 Dec 21 04:08 mvnyjp
You should use a local install of maven on your machine. You need to tell IntelliJ to use that version of maven in Preferences > Build, Execution, Deployment > Build Tools > Maven > "Maven home directory"

Why is my jar so big?

I've got a relatively simple jar-with-dependencies being built with Maven that is way larger than it seems like it should be. It's around 20MB, and in order to figure out what's taking up so much space, I've done the following:
First, I ran mvn dependency:tree. Then I checked in my .m2 cache for the size of each of the jars in the dependency tree. If I add up all of those sizes, it comes to about 8MB. How can I figure out where the other 12MB are coming from?
One thing I noticed in looking through my .m2 was that for many of the dependencies, they'll have something like this:
total 5224
-rw-r--r-- 1 user 289B Jul 25 2016 _remote.repositories
-rw-r--r-- 1 user 1.7M Jul 25 2016 commons-compress-1.12-javadoc.jar
-rw-r--r-- 1 user 407B Jul 25 2016 commons-compress-1.12-javadoc.jar.lastUpdated
-rw-r--r-- 1 user 40B Jul 25 2016 commons-compress-1.12-javadoc.jar.sha1
-rw-r--r-- 1 user 427K Jul 25 2016 commons-compress-1.12-sources.jar
-rw-r--r-- 1 user 407B Jul 25 2016 commons-compress-1.12-sources.jar.lastUpdated
-rw-r--r-- 1 user 40B Jul 25 2016 commons-compress-1.12-sources.jar.sha1
-rw-r--r-- 1 user 432K Jul 22 2016 commons-compress-1.12.jar
-rw-r--r-- 1 user 407B Jul 22 2016 commons-compress-1.12.jar.lastUpdated
-rw-r--r-- 1 user 40B Jul 22 2016 commons-compress-1.12.jar.sha1
-rw-r--r-- 1 user 13K Jul 22 2016 commons-compress-1.12.pom
-rw-r--r-- 1 user 407B Jul 22 2016 commons-compress-1.12.pom.lastUpdated
-rw-r--r-- 1 user 40B Jul 22 2016 commons-compress-1.12.pom.sha1
What are the -sources and -javadoc jars? Are those included in my uber jar? Because if every one of my dependencies uses the -javadoc jar instead of the standard one, that gets me a lot closer to 20MB.
Run
jar tvvf <your_simple-jar-with-dependencies.jar>
Or, open it with any zip compatible archiver and examine the contents to determine what is being included. Alternatively, run maven with -X for more extensive runtime information.

Fixed Rest Endpoints

I have a war file deployed on tomcat ( /var/lib/tomcat7/webapps folder ), say, rest-api-webapp-0.0.1.war
To access the rest endpoint check, exposed in this war, I use curl in the format
curl -X POST -H "Content-Type:application/x-www-form-urlencoded" -d "remarks=Tester" https://localhost:8080/rest-api-webapp-0.0.1/check The problem I face is, whenever I up the patch/major/minor versions of my webapp, I need to change the curl appropriately (say the version is now 0.1.4, then the curl must change as curl -X POST -H "Content-Type:application/x-www-form-urlencoded" -d "remarks=Tester" https://localhost:8080/rest-api-webapp-0.1.4/check. I donot wish to change the way the client calls the endpoint (because it requires the client to upgrade their app, which they resent and see as high maintenance) Can this be avoided by doing something like this
Create a symbolic link as below ln -s rest-api-webapp-0.0.1.war rest-api inside the /var/log/tomcat7/webapps folder so that whennever I up the version, I just change the symlink to point to the new version and the client need not do anything to use the new version of the api. In effect, I need the api endpoint to be fixed and not change as and when I up the versions on the server. For Ex: I need the endpoint to be fixed as https:gva.atr.in/colouring-api/check and whenever I have a major change in the controllers and all that I need to do is just update the symlink and not change the endpoint. If you find that this approach is flawed, please show me the right direction as I have been trying to read about this from the past 2 days, but found very less articles that address my problem.
I read the tomcat documentation and realised that I need to create a symbolic link to the war file and give the symbolic file the war extension. So If this is what you have in your tomcat webapps directory
/var/lib/tomcat7/webapps user1$ ls
drwxr-xr-x 11 user1 wheel 374 Oct 19 21:52 .
drwxr-xr-x 9 user1 admin 306 Oct 19 19:36 ..
drwxr-xr-x 19 user1 wheel 646 Aug 29 20:19 ROOT
drwxr-xr-x 55 user1 wheel 1870 Aug 29 20:19 docs
drwxr-xr-x 4 user1 wheel 136 Oct 19 19:46 rest-api-webapp-0.2.1
-rw-r--r-- 1 user1 wheel 48258097 Oct 19 19:46 rest-api-webapp-0.2.1.war
drwxr-xr-x 7 user1 wheel 238 Aug 29 20:19 host-manager
drwxr-xr-x 8 user1 wheel 272 Aug 29 20:19 manager
Do this,
ln -s rest-api-webapp-0.2.1.war rest-api.war So that the directory looks like this (Wait for sometime for the tomcat engine to deploy the new war)
drwxr-xr-x 11 user1 wheel 374 Oct 19 21:52 .
drwxr-xr-x 9 user1 admin 306 Oct 19 19:36 ..
drwxr-xr-x 19 user1 wheel 646 Aug 29 20:19 ROOT
drwxr-xr-x 4 user1 wheel 136 Oct 19 21:52 rest-api
drwxr-xr-x 4 user1 wheel 136 Oct 19 19:46 rest-api-webapp-0.2.1
-rw-r--r-- 1 user1 wheel 48258097 Oct 19 19:46 rest-api-webapp-0.2.1.war
lrwxr-xr-x 1 user1 wheel 25 Oct 19 21:51 rest-api.war -> rest-api-webapp-0.2.1.war
drwxr-xr-x 7 user1 wheel 238 Aug 29 20:19 host-manager
drwxr-xr-x 8 user1 wheel 272 Aug 29 20:19 manager If needed restart your tomcat and you can use the curl command like this curl -X POST -H "Content-Type:application/x-www-form-urlencoded" -d "remarks=Tester" https://localhost:8080/rest-api/check totally not bothering about the major, minor, patch versions. All that you need to do once you have a new version is unlink rest-apiln -s rest-api-webapp-X.Y.Z.war rest-api.war

How to have IntelliJ automatically overwrite files when exporting jar

In eclipse it does it anyway when exporting jars, and will only give a warning unless you tell it not to. However in IntelliJ, it refuses to delete the file when building a new version, and I have to go through and manually delete the jar myself for IntelliJ to export properly. Is there a way I force IntelliJ to overwrite jars when it exports?
IntelliJ always overrides artifacts. Try it again. Make sure no other process is using the file with:
$ lsof |grep [file name]
I just tried to make a project with artifact generation, no issues whatsoever.
bender:queues_jar demo$ ls -ltra
total 1408
-rw-r--r-- 1 demo staff 718737 Feb 11 21:26 queues.jar
drwxr-xr-x 3 demo staff 102 Feb 11 21:26 ..
drwxr-xr-x 3 demo staff 102 Feb 11 21:26 .
bender:queues_jar demo$ ls -ltra
total 1408
drwxr-xr-x 3 demo staff 102 Feb 11 21:26 ..
-rw-r--r-- 1 demo staff 718737 Feb 11 21:27 queues.jar
drwxr-xr-x 3 demo staff 102 Feb 11 21:27 .

Subclipse can't rename file (OS X)

I can't perform any Subversion operations on my Eclipse project as Subclipse can't rename a file. The error is:
Caused by: org.tigris.subversion.javahl.ClientException: svn: Cannot rename file '/Users/damianharvey/Sites/Odyssey3.5/OdysseyEDIJAXB/src/com/locuslive/edi/edifact/d95b/coreor/.svn/tmp/entries' to '/Users/damianharvey/Sites/Odyssey3.5/OdysseyEDIJAXB/src/com/locuslive/edi/edifact/d95b/coreor/.svn/entries'
at org.tigris.subversion.javahl.JavaHLObjectFactory.throwException(JavaHLObjectFactory.java:777)
at org.tmatesoft.svn.core.javahl.SVNClientImpl.throwException(SVNClientImpl.java:1850)
at org.tmatesoft.svn.core.javahl.SVNClientImpl.cleanup(SVNClientImpl.java:863)
at org.tigris.subversion.svnclientadapter.javahl.AbstractJhlClientAdapter.cleanup(AbstractJhlClientAdapter.java:1958)
... 8 more
Caused by: org.tmatesoft.svn.core.SVNException: svn: Cannot rename file '/Users/damianharvey/Sites/Odyssey3.5/OdysseyEDIJAXB/src/com/locuslive/edi/edifact/d95b/coreor/.svn/tmp/entries' to '/Users/damianharvey/Sites/Odyssey3.5/OdysseyEDIJAXB/src/com/locuslive/edi/edifact/d95b/coreor/.svn/entries'
I'm running OSX Snow Leopard, Eclipse 3.5, Subclipse 1.6.5.
It looks like a permissions problem. If I list the directories in the error I get:
drwxrwxrwx 8 damianharvey staff 272 19 Nov 17:43 .
drwxrwxrwx 16 damianharvey staff 544 21 Sep 14:53 ..
-r--r--r-- 1 damianharvey staff 2030 21 Sep 14:53 all-wcprops
-r--r--r-- 1 damianharvey staff 2313 21 Sep 14:53 entries
drwxrwxrwx 2 damianharvey staff 68 21 Sep 14:53 prop-base
drwxrwxrwx 2 damianharvey staff 68 21 Sep 14:53 props
drwxrwxrwx 15 damianharvey staff 510 21 Sep 14:53 text-base
drwxrwxrwx 6 damianharvey staff 204 19 Nov 17:19 tmp
So I assume that it's the read-only permissions that is preventing this. If I try to chmod this to a very broad 777:
sudo chmod 777 /Users/damianharvey/Sites/Odyssey3.5/OdysseyEDIJAXB/src/com/locuslive/edi/edifact/d95b/coreor/.svn/entries
chmod: Unable to change file mode on /Users/damianharvey/Sites/Odyssey3.5/OdysseyEDIJAXB/src/com/locuslive/edi/edifact/d95b/coreor/.svn/entries: Operation not permitted
Any ideas? Would quite like to commit my code.
Many Thanks.
No worries. Aunty Google found it for me
chflags -R nouchg .
From the comments here:
If you're changing workspaces on OS X
and you import an SVN-based project
into your new workspace, some of your
files may have the uchg flag set.
SubClipse/SVN will not be able to
update this project. You will get an
error:
svn: Cannot rename file
every time you try invoke svn. If you
issue:
chflags -R nouchg .
at the top-level of the project
directory this will clear these flags
and restore SVN function.

Categories