我按照这个maven-glassfish-plugin示例但错误消息,为什么?

时间:2010-06-26 10:36:59

标签: java maven-2 java-ee glassfish

昨天,我读了glassfish嵌入的例子,这个地址是: http://weblogs.java.net/blog/arungupta/archive/2008/11/totd_56_simple.html

但是我运行命令glassfish:run有一条错误消息

No plugin found for prefix 'glassfish' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories

我的pom.xml是

<dependencies>
    <dependency>
        <groupId>org.glassfish.distributions</groupId>
        <artifactId>web-all</artifactId>
        <version>10.0-SNAPSHOT</version>
        <type>jar</type>
        <classifier>build</classifier>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.embedded</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>3.0-Prelude-SNAPSHOT</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>utf-8</encoding>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.glassfish.maven.plugin</groupId>
            <artifactId>maven-glassfish-plugin</artifactId>

        </plugin>
    </plugins>
    <finalName>SSH2Maven</finalName>
</build>
<pluginRepositories>
    <pluginRepository>
        <id>ocean glassfish</id>
        <url>http://maven.ocean.net.au/snapshot</url>
        <releases>
            <enabled>false</enabled>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </pluginRepository>
</pluginRepositories>
<repositories>
    <repository>
        <id>glassfish repo</id>
        <url>http://maven.glassfish.org/content/groups/glassfish</url>
    </repository>
</repositories>

为什么呢? Plz给我一个完整的pom.xml示例,thx。

2 个答案:

答案 0 :(得分:2)

正如我在previous answer中所怀疑的那样,您正在使用的内容以及您所关注的教程已过时(GlassFish v3 Prelude在GlassFish v3之前,已于2009年12月发布并使用最近发布的GlassFish进行了更新3.0.1)从那时起Maven插件之类的东西发生了变化。

所以,尽管应该可以让事情有效,但我不会花一些时间去尝试:)相反,这里是 maven-embedded-glassfish-的最新(最小)配置插件

<project>
  ...
  <pluginRepositories>
    <pluginRepository>
      <id>m.g.o-groups-glassfish</id>
      <url>http://maven.glassfish.org/content/groups/glassfish</url>
    </pluginRepository>
  </pluginRepositories>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.glassfish</groupId>
        <artifactId>maven-embedded-glassfish-plugin</artifactId>
        <version>3.0.1</version>
        <configuration>
          <app>${project.build.directory}/${build.finalName}.war</app>
          <autoDelete>true</autoDelete>
          <port>8080</port>
          <contextRoot>test</contextRoot>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
</project>

然后运行:

mvn embedded-glassfish:run

将您的浏览器指向http://localhost:8080/test

答案 1 :(得分:0)

这是最新的&lt;插件&gt;用于运行Embedded GlassFish 4.0:

<plugin>
            <groupId>org.glassfish.embedded</groupId>
            <artifactId>maven-embedded-glassfish-plugin</artifactId>
            <version>4.0</version>
            <configuration>
                <app>target/${project.artifactId}.war</app>
                <port>8080</port>
                <ports>
                    <https-listener>8181</https-listener>
                </ports>       
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.glassfish.main.common</groupId>
                    <artifactId>simple-glassfish-api</artifactId>
                    <version>4.0</version>
                </dependency>                    
                <dependency>
                    <groupId>org.glassfish.main.extras</groupId>
                    <artifactId>glassfish-embedded-all</artifactId>
                    <version>4.0</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>start</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>start</goal>
                        <goal>deploy</goal>
                    </goals>
                </execution>
                <execution>
                    <id>stop</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>undeploy</goal>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

请参阅以下工作样本:

https://github.com/arun-gupta/javaee7-samples/