We have a maven project works fine in a internet enabled environment, now we need make it work in a local environment by IntelliJ IDEA Community Edition .
we have try following actions:
in setting->build->maven:
check the box "work offline"
download all needed jars into a local folder
in settings.xml set local Repository, such as
C:\FCA\Repository
4.build the project, it seems that some packages can be find in pom.xml(no error message in pom.xml), but can't be find in java code , and build failed. You can refer to attached picture for details
How can we get it done locally? thanks a lot!
Under "Settings -> Build, Execution, Deployment -> Maven" you can find options:
Maven home directory
User settings file
Local repository
There you have to provide path to your local maven installation (by default IntelliJ has it's own Maven provided). It should automatically read your settings.xml file and set local repository. If not please also provide those two and it will work fine with your local libs.
First of all, run mvn dependency:go-offline. Then you can build in offline mode as long as you don't change any of the dependencies.
If you do this to work inside a company with several developers, think about setting up a Nexus/Artifactory for you company.
Related
I am using Maven in my project, and for some reasons, some additional jars should be added manually (I have followed the step like Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project).
The package can be imported successfully. However, the compilation error happens, which indicates the package does not exist and cannot find the symbol of the used object.
I have tried the following tips but it remain unchanged:
Invalid caches / restarts
reimport
delete .idea file and .iml file
The scenario is quit similar to this one : https://intellij-support.jetbrains.com/hc/en-us/community/posts/206821195--beginner-question-including-external-jar-compile-error.
Please see the following sample images. It may run successfully but cannot be compiled well.
The reason is that when you add a library manually via IntelliJ, only IntelliJ knows about them and when you compile your code using Maven, it can't be find by Maven because Maven only searches for dependencies you defined in pom.xml.
You should install your libraries in your (at least) local maven repository and add them as a normal dependency in your pom.xml. Then you don't need to add them manually in IntelliJ.
You should follow the steps mentioned at Guide to installing 3rd party JARs
Update:
Also you should note that if you're working as a team, you should install this on the local maven repository of all developers (which is not practical). The best solution is to install a Maven repository (e.g. Nexus, Artifactory or Archiva) in a server on your local network and upload your private jar files on those servers. Then all developers can define the address of the local Maven repository server in their local Maven settings and use artifacts/libraries from that servers. Plus it works as a local cache/proxy to fetch any Maven artifacts and prevents unnecessary calls to public maven repositories.
I am working on a project where there is quite a lot of dependencies loaded. I am using a specific settings.xml file which is pointing specific direction for the m2 repository. It set in eclipse preferences for maven to use this settings file and also as a environment variable to use this settings file.
Now, the scenario that I am no sure what happens is:
there was a change in the code that requires an update of the dependencies
you are using the Maven -> Update project... option from project context menu in eclipse, or using the Maven build with the Update snapshots option checked
Dependencies are downloaded and in eclipse you can see that the code is building again.
And here is the part that I do not understand, now I am trying to run simply "mvn clean install" on the specific project but it is not building, I need to use the -U option and when the dependencies are downloaded, then the build is success.
I know that this is long scenario and for someone probably a tl;dr but would be very grateful if someone could explain it to me why there is a need to download the dependencies double.
Usually, the Eclipse plugin uses an embedded maven that is different than the installed in your operating system. If you use custom settings, you must configure both.
In Eclipse, you can go to Window > Preferences, and look for Maven > Installation. You may check there the maven you are using. There is a default EMBEDDED maven. You can use a button to Add.. others.
In Window > Preferences, and look for Maven > User Settings to define your settings.xml file.
For external (typical) maven installations, the settings.xml file is located in your home directory.
To avoid double configurations (and repositories), I think you can
Configure Eclipse to use the same settings.xml, or
Configure Eclipse to use an external maven.
I've imported a project from Git in Eclipse using this method:
File > Import > Git > Projects from Git > Next > Clone URL .
At this point I inserted the URI like this https://github.com/mygituser/My-Project .
Then my user and password, and the project was imported.
The problem is that Eclipse didn't recognize it as a Java project, and I really don't know why.
As consequence, I can't see errors or warnings on my project and neither use autocomplete, I'm getting this message "This compilation unit is not on the build path of a Java project".
Also, right click on My-Project > Build path shows the message "No actions avaliable".
If you need more information to help me, could you ask me on comments, please?
I appreciate your attention!
Most people don't include build files in repositories, only source. What you need to do is create a new Eclipse project the create a Git repo on top of that:
Create a new Eclipse project, and go to it with your terminal.
git init to initialize a repo.
git remote add origin https://github.com/mygituser/My-Project to add the remote.
git pull -u origin master to pull the changes.
Also, make sure that when you commit, you don't add build files that the author kept out. You can do this via a .gitignore file. Simply take this file and add it to your project directory.
This method applies to most Git repositories, as build and compiled files are usually left out.
Note that this method requires that you install Git for command line (or Git Bash). You can get Git at their website.
Since you already have the source code downloaded from the git repository, you should be able to create an Eclipse project from the existing source code.
I'd like to set the ftp servers for deploying from STS as described here: http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ftp.html
It should be in the settings.xml.
According to documentation settings is in either of 2:
The Maven install: $M2_HOME/conf/settings.xml
A user's install: ${user.home}/.m2/settings.xml
Where is the $M2_HOME. In other terms when working from STS(Eclipse), what is the installation folder for maven in this case. I can't find a settings.xml in ${user.home}/.m2/ .
I worked under Windows 7
Those 2 threads are related but do not provide a clear answer that worked for me at least:
maven doesnt seem to be installing with springsource tool suite
Eclipse (STS) + Maven , I have nothing appearing in the screenshot suggested in this last thread.
Thx in advance
I may be off-mark as I've never used STS myself, but if I understand correctly it is just a pre-packaged Eclipse distribution. If I'm correct your installation only contains an embedded version of Maven, but not a command line accessible one. You need to install one from here.
With the 3.x releases of Eclipse I found that you need to have your installation point to an external Maven installation for Eclipse to make use of the settings.xml files. Once you installed a downloaded version you can choose Window -> Preferences -> Maven -> Installations, press Add... and point to the version you just installed.
In Spring Tools Suite (3.6.1):
Windows - Preferences - Maven - User Settings, you can select which global- and user- version of the settings.xml to use.
Global maven settings.xml exist at apache-maven-3.0.4\conf\settings.xml [inside the maven installation]
and
Local maven settings.xml exist at C\Users\[username]\.m2\settings.xml[window OS install on C drive]
I have a project (built from an AppFuse template) that requires Maven 2.2.1. So I upgraded to this (from 2.1.0) and set my path and my M2_HOME and MAVEN_HOME env variables.
Then I ran mvn eclipse:eclipseand imported the project into Eclipse (Galileo).
However, in the problems list for the project (and at the top of the pom.xml GUI editor) it says:
Unable to build project
'/export/people/clegg/data/Workspace/funcserve/pom.xml;
it requires Maven version 2.2.1
This persists whether I set Eclipse to use its Embedded Maven implementation, or the external 2.2.1 installation, in the Preferences -> Maven -> Installations dialog.
I've tried closing and reopening the project, reindexing the repository, cleaning the project, restarting the IDE, logging out and back in again, everything I can think of! But Eclipse still won't believe I have Maven 2.2.1.
I just did a plugin update so I have the latest version of Maven Integration for Eclipse -- 0.9.8.200905041414.
Does anyone know how to convince Eclipse I really do have the right version of Maven? It's like it's recorded the previous version somewhere else and won't pay any attention to my changes :-(
Eclipse allows you to specify an external Maven installation. But there's a catch. :(
Have a look at Windows > Preferences > Maven > Installations.
You will see a message like this:
Note: Embedded runtime is always used for dependency resolution, but does
not use global settings when it is used to launch Maven.
To learn more, visit the maven web page.
Translating to English, it means that Eclipse will continue to employ its internal Maven instance in order to perform some tasks.
When you "Run As > maven install" it will run your pom.xml script employing the external Maven instance you specified but when Eclipse performs some of its internal stuff, it will continue to use the embedded Maven instance, whatever version it is.
(edited)
As far as I know, when you install M2Eclipse you are implicitly defining which "internal Maven instance" you will have, which is exactly that one packaged by the plugin.
In the plugin configuration, you can add external Maven instances by telling where they are installed.
If you are using a recent m2eclipse version, you can try this too:
<prerequisites>
<maven>>=2.2.1</maven>
</prerequisites>
Notice the greater than in >=2.2.1. It works fine for me.
A common source of trouble (of this kind) is if you change global preferences and don't remember or know that you have enabled some project specific settings. At least it's a chance that the global setting is now set to use the external maven but the project setting is still set to 'embedded'.
M2Eclipse uses an embedded maven instance, not the maven instance you have installed on your system.
Have you tried switching workspaces?
You can still reference the same project in the new workspace. This would provide about as much of a reset as you can do in terms of eclipses internal settings.
Try creating your eclipse project with mvn project:m2eclipse or use the maven import option under import project.
Using m2eclipse, my fallback in these situations is to do Maven > Update Dependencies and then Maven > Update Project Configuration. The first is just me being supersticious, but the second will rewrite .project and .classpath.
As Pascal says about, m2eclipse can also be pointed at an external instance. I've done this in the past, though not at 2.2.1.
Dan
I got the same issue. Resolved it by restarting the system because every time you change the 'Path' in environment variables you should restart the system or else if would not pick the changes.