java GlassFish v3 和 glassfish-maven-plugin (Mac)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1935137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 18:35:44  来源:igfitidea点击:

GlassFish v3 and glassfish-maven-plugin (Mac)

javamaven-2glassfishmaven

提问by anthonator

I'm trying to use the glassfish-maven-plugin (https://maven-glassfish-plugin.dev.java.net/) with GlassFish v3 (I'm on a Mac and using Eclipse) and I can't seem to get my web app to deploy. I keep running into:

我正在尝试将 glassfish-maven-plugin(https://maven-glassfish-plugin.dev.java.net/)与 GlassFish v3(我在 Mac 上并使用 Eclipse)一起使用,但我似乎无法让我的网络应用程序进行部署。我不断遇到:

The Master Password is required to start the domain. No console, no prompting possible. You should either create the domain with --savemasterpassword=true or provide a password file with the --passwordfile option.

启动域需要主密码。没有控制台,没有提示可能。您应该使用 --savemasterpassword=true 创建域,或者使用 --passwordfile 选项提供密码文件。

Here is the relevant portion of my POM file.

这是我的 POM 文件的相关部分。

<profiles>
    <profile>
        <id>development</id>
        <activation>
            <property>
                <name>phase</name>
                <value>development</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.glassfish.maven.plugin</groupId>
                    <artifactId>maven-glassfish-plugin</artifactId>
                    <version>2.2-SNAPSHOT</version>
                    <configuration>
                        <glassfishDirectory>${glassfish.directory}</glassfishDirectory>
                        <user>${glassfish.user}</user>
                        <passFile>${glassfish.directory}/domains/${project.artifactId}/config/domain-passwords</passFile>
                        <domain>
                            <name>${project.artifactId}</name>
                        </domain>
                        <components>
                            <component>
                                <name>${project.artifactId}</name>
                                <artifact>${project.build.directory}/artifacts/${project.artifactId}.war</artifact>
                            </component>
                        </components>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <pluginRepositories>
            <pluginRepository>
                <id>ocean</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>
    </profile>
</profiles>

Here is the start-domain command Maven is executing.

这是 Maven 正在执行的启动域命令。

asadmin --host localhost --port 4848 --user admin --passwordfile /var/folders/sk/skcc8rAVGSynOBBaOwWN3U+++TI/-Tmp-/mgfp5377058868244877698.tmp --interactive=false --echo=true --terse=true start-domain --debug=false --domaindir /Applications/GlassFish/v3/glassfish/domains --help=false --upgrade=false --verbose=false mvnrepo

asadmin --host localhost --port 4848 --user admin --passwordfile /var/folders/sk/skcc8rAVGSynOBBaOwWN3U++++TI/-Tmp-/mgfp5377058868244877698.tmp --interactive=false --echo=true --terse= true start-domain --debug=false --domaindir /Applications/GlassFish/v3/glassfish/domains --help=false --upgrade=false --verbose=false mvnrepo

The --passwordfile is using a temp file so I'm guessing that is the problem. For some reason the passFile parameter isn't working.

--passwordfile 正在使用临时文件,所以我猜这就是问题所在。由于某种原因, passFile 参数不起作用。

Any ideas? I'm I wrong with my assumption?

有任何想法吗?我的假设错了吗?

回答by Pascal Thivent

In the FairlyComplete Configuration Example, there is indeed a reference to the <passFile>element but the documentation of the various goals doesn't mention this element and refer to <passwordFile>instead (see for example glassfish:start-domainor glassfish:deploy). So, try to update the configuration of your plugin in your profile accordingly:

FairlyComplete Configuration Example 中,确实有对<passFile>元素的引用,但各种目标的文档没有提到这个元素,<passwordFile>而是引用(参见例如glassfish:start-domainglassfish:deploy)。因此,尝试相应地更新配置文件中插件的配置:

<plugin>
  <groupId>org.glassfish.maven.plugin</groupId>
  <artifactId>maven-glassfish-plugin</artifactId>
  <version>2.2-SNAPSHOT</version>
  <configuration>
    <glassfishDirectory>${glassfish.directory}</glassfishDirectory>
    <user>${glassfish.user}</user>
    <passwordFile>${glassfish.directory}/domains/${project.artifactId}/config/domain-passwords</passwordFile>
    <domain>
      <name>${project.artifactId}</name>
    </domain>
    <components>
      <component>
        <name>${project.artifactId}</name>
        <artifact>${project.build.directory}/artifacts/${project.artifactId}.war</artifact>
      </component>
    </components>
  </configuration>
</plugin>

As a side note, I recommend the maven-embedded-glassfish-pluginwhich allows to run Glassfish in a single JVM using its embedded API. Very nice. See Using maven plugin for v3 embedded glassfish for more details.

作为旁注,我推荐maven-embedded-glassfish-plugin,它允许使用其嵌入式 API 在单个 JVM 中运行 Glassfish。非常好。有关更多详细信息,请参阅为 v3 嵌入式 glassfish 使用 maven 插件

UPDATE:I did some further testing and, couldn't actually reproduce your problem on my machine (sigh).

更新:我做了一些进一步的测试,实际上无法在我的机器上重现您的问题(叹气)。

First, I created a new domain by executing the following command (from <glassfish_home>/bin):

首先,我通过执行以下命令(来自<glassfish_home>/bin)创建了一个新域:

$ ./asadmin create-domain  --savemasterpassword=true maven-glassfish-testcase

Then, I created a new webapp using maven's webapp archetype:

然后,我使用 maven 的 webapp 原型创建了一个新的 webapp:

$ mvn archetype:create -DgroupId=com.mycompany.app \
      -DartifactId=maven-glassfish-testcase \
      -DarchetypeArtifactId=maven-archetype-webapp

And updated the pom.xmlof the freshly created webapp as follow:

并更新了pom.xml新创建的 webapp 如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>maven-glassfish-testcase</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>maven-glassfish-testcase Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
    <glassfish.home>/home/pascal/opt/glassfishv3/glassfish</glassfish.home>
    <domain.username>admin</domain.username>
  </properties>
  <pluginRepositories>
    <pluginRepository>
      <id>ocean</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>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>maven-glassfish-testcase</finalName>
    <plugins>
      <plugin>
        <groupId>org.glassfish.maven.plugin</groupId>
        <artifactId>maven-glassfish-plugin</artifactId>
        <version>2.2-SNAPSHOT</version>
        <configuration>
          <glassfishDirectory>${glassfish.home}</glassfishDirectory>
          <user>${domain.username}</user>
          <passwordFile>${glassfish.home}/domains/${project.artifactId}/master-password</passwordFile>
          <debug>true</debug>
          <echo>true</echo>
          <domain>
            <name>${project.artifactId}</name>
            <adminPort>4848</adminPort> <!-- mandatory for mvn glassfish:deploy -->
          </domain>
          <components>
            <component>
              <name>${project.artifactId}</name>
              <artifact>${project.build.directory}/${project.build.finalName}.war</artifact>
            </component>
          </components>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

With this setup, running mvn glassfish:start-domainproduces the following output:

使用此设置,运行mvn glassfish:start-domain会产生以下输出:

$ mvn glassfish:start-domain
[INFO] Scanning for projects...
[INFO] snapshot org.glassfish.maven.plugin:maven-glassfish-plugin:2.2-SNAPSHOT: checking for updates from ocean
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-glassfish-testcase Maven Webapp
[INFO]    task-segment: [glassfish:start-domain]
[INFO] ------------------------------------------------------------------------
[INFO] [glassfish:start-domain {execution: default-cli}]
[INFO] asadmin --host localhost --port 4848 --user admin --passwordfile /home/pascal/opt/glassfishv3/glassfish/domains/maven-glassfish-testcase/master-password --interactive=false --echo=true --terse=true start-domain --debug=true --domaindir /home/pascal/opt/glassfishv3/glassfish/domains --help=false --upgrade=false --verbose=false maven-glassfish-testcase
[INFO] Started domain: maven-glassfish-testcase
[INFO] Domain location: /home/pascal/opt/glassfishv3/glassfish/domains/maven-glassfish-testcase
[INFO] Log file: /home/pascal/opt/glassfishv3/glassfish/domains/maven-glassfish-testcase/logs/server.log
[INFO] Admin port for the domain: 4848
[INFO] Debug port for the domain: 9009
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27 seconds
[INFO] Finished at: Mon Dec 21 20:16:17 CET 2009
[INFO] Final Memory: 4M/53M
[INFO] ------------------------------------------------------------------------

As you can see, the --passwordfileoption is passed correctly using the file specified in the POM. In other words, things are working as expected. Maybe try with an hard coded path to the password file to debug this setting, it should just work!

如您所见,该--passwordfile选项是使用 POM 中指定的文件正确传递的。换句话说,事情按预期进行。也许尝试使用密码文件的硬编码路径来调试此设置,它应该可以正常工作!

回答by Ingo Fischer

It just took me a while to realize that i accidentally left the "adminPassword" property in the Maven-Glassfish-Plugin Configuration (so i had both adminPassword and passwordFile set). The plugin still used the temporary passwordfile instead of my own one, resulting in the above error.

我花了一段时间才意识到我不小心在 Maven-Glassfish-Plugin 配置中留下了“adminPassword”属性(所以我设置了 adminPassword 和 passwordFile)。该插件仍然使用临时密码文件而不是我自己的,导致上述错误。

Just in case someone else is as stupid as me ;)

以防万一其他人和我一样愚蠢;)