0

我已经通过 Eclipse 方式创建了 tomcat 项目。我在原型选择阶段选择了tomcat原型。它为一个项目创建了 6 个目录,包括“-api”、“-api-impl”等。

现在我该如何运行?

在命令行我可以发出

mvn tomcat6:run

或者

mvn tomcat7:run

它会运行。

如何在eclipse中做同样的事情?

更新

可能这个命令相当于 ->Debug As... 并在“goals”中输入“tomcat6:run”。但在这种情况下,我会收到类似的错误

Downloading: http://repo.maven.apache.org/maven2/org/apache/tomcat/maven/tomcat6-maven-plugin/2.1/tomcat6-maven-plugin-2.1.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.tomcat.maven:tomcat6-maven-plugin:2.1: Plugin org.apache.tomcat.maven:tomcat6-maven-plugin:2.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.tomcat.maven:tomcat6-maven-plugin:jar:2.1

更新 2

如果我设置调试输出,我会得到“连接被拒绝”异常:

[DEBUG] Resolving plugin prefix tomcat6 from [org.apache.maven.plugins, org.codehaus.mojo]
[DEBUG] Using connector WagonRepositoryConnector with priority 0 for http://repo.maven.apache.org/maven2
Downloading: http://repo.maven.apache.org/maven2/org/apache/tomcat/maven/tomcat6-maven-plugin/2.1/tomcat6-maven-plugin-2.1.pom
[DEBUG] Writing resolution tracking file D:\Users\Dims\Design\!Lib\!m2\repository\org\apache\tomcat\maven\tomcat6-maven-plugin\2.1\tomcat6-maven-plugin-2.1.pom.lastUpdated
[WARNING] Failed to retrieve plugin descriptor for org.apache.tomcat.maven:tomcat6-maven-plugin:2.1: Plugin org.apache.tomcat.maven:tomcat6-maven-plugin:2.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.tomcat.maven:tomcat6-maven-plugin:jar:2.1
org.apache.maven.plugin.PluginResolutionException: Plugin org.apache.tomcat.maven:tomcat6-maven-plugin:2.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.tomcat.maven:tomcat6-maven-plugin:jar:2.1
    at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:129)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getPluginDescriptor(DefaultMavenPluginManager.java:142)
    at org.apache.maven.plugin.DefaultBuildPluginManager.loadPlugin(DefaultBuildPluginManager.java:59)
    at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolveFromProject(DefaultPluginPrefixResolver.java:139)
    at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolveFromProject(DefaultPluginPrefixResolver.java:122)
    at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolve(DefaultPluginPrefixResolver.java:86)
    at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.findPluginForPrefix(MojoDescriptorCreator.java:262)
    at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.getMojoDescriptor(MojoDescriptorCreator.java:222)
    at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:106)
    at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:86)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:98)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.sonatype.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for org.apache.tomcat.maven:tomcat6-maven-plugin:jar:2.1
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:296)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:186)
    at org.sonatype.aether.impl.internal.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:279)
    at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:115)
    ... 23 more
Caused by: org.sonatype.aether.resolution.ArtifactResolutionException: Could not transfer artifact org.apache.tomcat.maven:tomcat6-maven-plugin:pom:2.1 from/to central (http://repo.maven.apache.org/maven2): Connection to http://repo.maven.apache.org refused
    at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:538)
    at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:216)
    at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:193)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:281)
    ... 26 more
Caused by: org.sonatype.aether.transfer.ArtifactTransferException: Could not transfer artifact org.apache.tomcat.maven:tomcat6-maven-plugin:pom:2.1 from/to central (http://repo.maven.apache.org/maven2): Connection to http://repo.maven.apache.org refused
    at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:951)
    at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:941)
    at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:669)
    at org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:60)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.maven.wagon.TransferFailedException: Connection to http://repo.maven.apache.org refused
    at org.apache.maven.wagon.shared.http4.AbstractHttpClientWagon.fillInputData(AbstractHttpClientWagon.java:799)
    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.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:601)
    ... 4 more
Caused by: org.apache.maven.wagon.providers.http.httpclient.conn.HttpHostConnectException: Connection to http://repo.maven.apache.org refused
    at org.apache.maven.wagon.providers.http.httpclient.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:158)
    at org.apache.maven.wagon.providers.http.httpclient.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
    at org.apache.maven.wagon.providers.http.httpclient.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
    at org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:573)
    at org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)
    at org.apache.maven.wagon.providers.http.httpclient.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at org.apache.maven.wagon.providers.http.httpclient.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at org.apache.maven.wagon.shared.http4.AbstractHttpClientWagon.execute(AbstractHttpClientWagon.java:674)
    at org.apache.maven.wagon.shared.http4.AbstractHttpClientWagon.fillInputData(AbstractHttpClientWagon.java:793)
    ... 8 more
Caused by: java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at org.apache.maven.wagon.providers.http.httpclient.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:123)
    at org.apache.maven.wagon.providers.http.httpclient.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
    ... 16 more

解决方案

防病毒防火墙阻止 eclipse 访问网络。因此,从 Eclipse 中运行目标失败了。

4

1 回答 1

0

教程将帮助您使用 Eclipse 设置 Tomcat。但是上面的命令是 Maven。Eclipse有 Maven插件,但有很多抱怨。因此,如果您认为 Eclipse 上的 Tomcat 使用第一个链接,如果 Maven 是优先获取插件

于 2013-03-29T23:54:21.837 回答