Tuesday, January 10, 2012

Maven build error Error transferring file: Permission denied: connect


Problem: When you try to do a maven build, then it tries to download all POM files or JAR files from maven repo, and it throws following error:
Error transferring file: Permission denied: connect

It is not able to download even 1 file from maven repo.

This is the complete stack trace when run with -X option:


E:\LearningProjects>mvn -X archetype:generate  -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -Dartifa
ctId=my-app
+ Error stacktraces are turned on.
Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.6.0_27
Java home: C:\Program Files\Java\jdk1.6.0_27\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
[DEBUG] Building Maven user-level plugin registry from: 'C:\Users\testuser\.m2\plugin-registry.xml'
[DEBUG] Building Maven global-level plugin registry from: 'C:\Users\testuser\apache-maven-2.2.1\bin\..\conf\plugin-registry.xml'
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[DEBUG] Loading plugin prefixes from group: org.apache.maven.plugins
[INFO] org.apache.maven.plugins: checking for updates from central
[DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[DEBUG] Checking for pre-existing User-Agent configuration.
[DEBUG] Adding User-Agent configuration.
[DEBUG] Connecting to repository: 'central' with url: 'http://repo1.maven.org/maven2'.
[DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[WARNING] repository metadata for: 'org.apache.maven.plugins' could not be retrieved from repository: central due to an error: Err
or transferring file: Permission denied: connect
[DEBUG] Exception
org.apache.maven.wagon.TransferFailedException: Error transferring file: Permission denied: connect
        at org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputData(LightweightHttpWagon.java:143)
        at org.apache.maven.wagon.StreamWagon.getInputStream(StreamWagon.java:116)
        at org.apache.maven.wagon.StreamWagon.getIfNewer(StreamWagon.java:88)
        at org.apache.maven.wagon.StreamWagon.get(StreamWagon.java:61)
        at org.apache.maven.artifact.manager.DefaultWagonManager.getRemoteFile(DefaultWagonManager.java:546)
        at org.apache.maven.artifact.manager.DefaultWagonManager.getArtifactMetadata(DefaultWagonManager.java:443)
        at org.apache.maven.artifact.repository.metadata.DefaultRepositoryMetadataManager.resolve(DefaultRepositoryMetadataManager
.java:97)
        at org.apache.maven.plugin.DefaultPluginMappingManager.loadPluginMappings(DefaultPluginMappingManager.java:103)
        at org.apache.maven.plugin.DefaultPluginMappingManager.loadPluginMappings(DefaultPluginMappingManager.java:87)
        at org.apache.maven.plugin.DefaultPluginMappingManager.getByPrefix(DefaultPluginMappingManager.java:61)
        at org.apache.maven.plugin.DefaultPluginManager.getPluginDefinitionForPrefix(DefaultPluginManager.java:159)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1801)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:462
)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:175)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: java.net.SocketException: Permission denied: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:529)
        at java.net.Socket.connect(Socket.java:478)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:395)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:234)
        at sun.net.www.http.HttpClient.New(HttpClient.java:307)
        at sun.net.www.http.HttpClient.New(HttpClient.java:324)
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
        at org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputData(LightweightHttpWagon.java:115)
        ... 25 more
[INFO] Repository 'central' will be blacklisted
[DEBUG] Loading plugin prefixes from group: org.codehaus.mojo
[DEBUG] Skipping blacklisted repository central
[DEBUG] Skipping blacklisted repository central
[DEBUG] maven-archetype-plugin: using locally installed snapshot
[DEBUG] Artifact not found - using stub model: Unable to determine the latest version

  org.apache.maven.plugins:maven-archetype-plugin:pom:LATEST



[DEBUG] Using defaults for missing POM org.apache.maven.plugins:maven-archetype-plugin:pom:LATEST
[DEBUG] maven-archetype-plugin: using locally installed snapshot
[DEBUG] Artifact not found - using stub model: Unable to determine the release version

  org.apache.maven.plugins:maven-archetype-plugin:pom:RELEASE



[DEBUG] Using defaults for missing POM org.apache.maven.plugins:maven-archetype-plugin:pom:RELEASE
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-archetype-plugin' does not exist or no valid version could be found
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: The plugin 'org.apache.maven.plugins:maven-archetype-plugin' does not exis
t or no valid version could be found
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(DefaultLifecycleExecutor.java:1569)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1851)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:462
)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:175)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.version.PluginVersionNotFoundException: The plugin 'org.apache.maven.plugins:maven-archetype-pl
ugin' does not exist or no valid version could be found
        at org.apache.maven.plugin.version.DefaultPluginVersionManager.resolvePluginVersion(DefaultPluginVersionManager.java:229)
        at org.apache.maven.plugin.version.DefaultPluginVersionManager.resolvePluginVersion(DefaultPluginVersionManager.java:91)
        at org.apache.maven.plugin.DefaultPluginManager.verifyPlugin(DefaultPluginManager.java:179)
        at org.apache.maven.plugin.DefaultPluginManager.loadPluginDescriptor(DefaultPluginManager.java:1642)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(DefaultLifecycleExecutor.java:1540)
        ... 15 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Fri Jan 06 20:02:54 IST 2012
[INFO] Final Memory: 2M/121M
[INFO] ------------------------------------------------------------------------



Solution: I tried almost everything found on net for almost 2 days, that did not work. Initially i was trying to build with maven 3.x version, seeing
this error, i switched to maven2.x, but still same error. Initially i was using jdk1.7, then i downgraded to jdk 1.6 but that also did not solve the problem.
My OS was win7 64 bit and i heard somewhere about java 32 bit and 64 bit. I downloaded both 32 and 64 bit java, modified all environment variables but still
same issue persisted. Somewhere i read about Windows Firewall enabling/disabling. I enabled/disabled Firewall, allowed java/http through allowed programs,
but that also did not fix the issue. I use a wireless router to route the network connection got from my ISP. I even removed that connection and tried to
use the IP directly by my system (since the router was giving me local IP such as 192.168.1.2 and i though that might be problem), but still same issue :(.
At last what fixed it, is interesting: I had purchased a new system which had Intel motherboard. There was in-built antivirus and Firewall installed with it.
When i disabled 'Personal Firewall' from that ESET security options. Then maven started downloading everything and built successfully.

Interestingly, this fixed other couple of issues: such as running IE 64 bit version and downloading files using torrent.

27 comments:

Anonymous said...

I had to stop my vpn connection to work to stop this problem. Strange, I thought only my connection to my work url went through the vpn.

Anonymous said...

Thanks . This was a life saver . I would have never thought of this .

jonnu said...

exactly the same as the first Anon. I had to cull my VPN connection also, then everything was perfect.

jonnu said...

Try adding this to your environment variables.

MAVEN_OPTS=-Djava.net.preferIPv4Stack=true

Apparently it is a known bug in JDK 1.7. This fixed it for me.

Anonymous said...

Thanks for the MAVEN_OPTS=-Djava.net.preferIPv4Stack=true suggestion. Worked for me on Win7 over a VPN.

Anonymous said...

Fantastic! MAVEN_OPTS=-Djava.net.preferIPv4Stack=true fixed my Win7/VPN issue as well. Now I don't need to close down the VPN connection when maven needs to pull down new dependencies.

Diego said...

Thanks for the MAVEN_OPTS=-Djava.net.preferIPv4Stack=true suggestion. Worked for me on Win7 over a VPN, as well.
Thank you very much!I have more than 4 hours searching for this solution

Anonymous said...

MAVEN_OPTS fix did NOT work for me. Has anyone stumbled upon any other solutions. I cannot disconnect from VPN because the maven repository is on the network...

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

-Djava.net.preferIPv4Stack=true

Worked beautifully thanks.

Was pulling my hair out and cursing my company's VPN policy.

Anonymous said...

Ahaa, its pleasant dialogue concerning this post here at this webpage, I have read all
that, so now me also commenting at this place.


Here is my blog post - first america cash advance
my site: cash advance payday loans

Anonymous said...

Hello. And Bye. Thank you very much.

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

It is the best time to make some plans for the future and it's time to be happy. I've read this
post and if I could I desire to suggest you some interesting things or tips.

Perhaps you could write next articles referring to this article.
I wish to read more things about it!

Also visit my site ... weight loss programs

Anonymous said...

What i do not realize is in truth how you're not really a lot more neatly-liked than you may be right now. You are very intelligent. You recognize therefore significantly in relation to this matter, made me personally imagine it from numerous numerous angles. Its like men and women don't seem to be interested except it's something to accomplish with Girl gaga! Your own stuffs nice. At all times handle it up!

Here is my blog post free weight loss programs

Anonymous said...

Managіng both business halvеs is іmроrtant.
First and forеmοst, уou havе to be
prеpагed I was a misfit, cοnfеsses Јason, 39, an evеnts organiser, handling ρarty
arrangemеntѕ.

My website :: dallas internet marketing company

Anonymous said...

MAVEN_OPTS=-Djava.net.preferIPv4Stack=true

work for me. :)