glassfish-embedded https://www.e-learn.cn/tag/glassfish-embedded zh-hans Any best practices for dealing with Java EE and java.endorsed.dirs? https://www.e-learn.cn/topic/3341292 <span>Any best practices for dealing with Java EE and java.endorsed.dirs?</span> <span><span lang="" about="/user/18" typeof="schema:Person" property="schema:name" datatype="">非 Y 不嫁゛</span></span> <span>2020-02-01 03:12:41</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I've recently run into a problem with glassfish standalone (v3.1) vs glassfish embedded (v3.1) vs java SE and the way java.endorsed.dirs is used. The specific problem I had is here, but I don't think it's the last time I'm going to run into something similar.</p> <p>The information I found here and here suggests adding the glassfish endorsed libs to the bootstrap classpath when compiling. However, this bug report suggests it is difficult to get the endorsed libs set correctly when using glassfish embedded.</p> <p>So, it seems like when I deploy to a standalone glassfish container my application is going to run against the endorsed libs that glassfish includes, but when using the embedded container it won't. I encountered my original problem because the maven-embedded-glassfish-plugin doesn't start glassfish embedded using the endorsed libs like glassfish standalone does. I'm also unsure whether other containers (ex: jboss) include the same set of endorsed libs as glassfish.</p> <p>So, am I (1)supposed to struggle (a lot) to make sure my application is compiled against the endorsed libs and always deployed to a container that is bootstrapped using the endorsed libs or should I (2)just stick to using what's bundled with Java SE 6?</p> <p>If I choose (2), will I have to worry about incompatibilities when deploying my application to a container that is bootstrapped with newer endorsed libs?</p> <p>I would appreciate any insight that anyone can offer. </p> <br /><h3>回答1:</h3><br /><p>I may be missing something obvious here but... Isn't GlassFish Embbeded shipped with libraries compatible with the Java EE specs? And aren't those libraries loaded by default? (If they aren't, please fill a bug here: http://java.net/jira/browse/EMBEDDED_GLASSFISH). </p> <p>What I mean is: You should compile against Java EE spec APIs, and just let the container use it's own implementations.</p> <p>For the first part, if you use Maven, I like the way Codehaus archetypes sets the endorsed libs. It is both clean and Application Server Agnostic:</p> <pre><code>&lt;properties&gt; &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt; &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt; &lt;/properties&gt; </code></pre> <p>...</p> <pre><code>&lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt; &lt;version&gt;2.3.2&lt;/version&gt; &lt;configuration&gt; &lt;source&gt;1.6&lt;/source&gt; &lt;target&gt;1.6&lt;/target&gt; &lt;compilerArguments&gt; &lt;endorseddirs&gt;${endorsed.dir}&lt;/endorseddirs&gt; &lt;/compilerArguments&gt; &lt;/configuration&gt; &lt;/plugin&gt; </code></pre> <p>...</p> <pre><code>&lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt; &lt;version&gt;2.1&lt;/version&gt; &lt;executions&gt; &lt;execution&gt; &lt;phase&gt;validate&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;copy&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;outputDirectory&gt;${endorsed.dir}&lt;/outputDirectory&gt; &lt;silent&gt;true&lt;/silent&gt; &lt;artifactItems&gt; &lt;artifactItem&gt; &lt;groupId&gt;javax&lt;/groupId&gt; &lt;artifactId&gt;javaee-endorsed-api&lt;/artifactId&gt; &lt;version&gt;6.0&lt;/version&gt; &lt;type&gt;jar&lt;/type&gt; &lt;/artifactItem&gt; &lt;/artifactItems&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; </code></pre> <p>Which is pretty much all you need to compile your projects against Java EE 6 APIs. Any Java EE 6 compliant App Server should provide those services, and you shouldn't be worried about how they are making it available to your application.</p> <p>The responsibility of bootstrapping Java EE Services should be of your App Server. If you try your own "in house" solution, chances are that JAR Hell will break loose. </p> <p>Cheers,</p> <br /><br /><br /><h3>回答2:</h3><br /><p><strong>EDIT</strong>: The <code>javaee-endorsed-api</code> approach above probably will work fine, but it gives me the willies. I don't think it is produced or maintained anymore. Furthermore the <code>pom.xml</code> it contains within it reflects that at some point it was called <code>javaee-compact-api</code>, and you can see how they strip the implementation classes out of it. By contrast, cherry-picking the API jars you want to use as endorsed (as I recommend below) seems to be more stable and flexible. Finally, if you still want to use the <code>javaee-endorsed-api</code> approach, you can still use the general approach I recommend and point to <code>javaee-endorsed-api.jar</code> instead.</p> <p>Ryan; I just combed through your long trail on this (touching StackOverflow, the java.net forums, etc.) on the same journey.</p> <p>During unit or integration testing you'll need to set the <code>java.endorsed.dirs</code> System property, as you know.</p> <p>The trick is you have to do this in such a way that the JVM running the tests picks it up. And that depends on how you have Surefire running.</p> <p>If for some reason you have Surefire set to <em>not</em> fork, this is probably a bad thing, and you should re-evaluate your configuration here.</p> <p>If you have Surefire set to fork, then you might think you could simply include <code>java.endorsed.dirs</code> in a <code>systemPropertyVariables</code> stanza, like this:</p> <pre><code>&lt;systemPropertyVariables&gt; &lt;java.endorsed.dirs&gt;weWillGetToThisInAMoment&lt;/java.endorsed.dirs&gt; &lt;/systemPropertyVariables&gt; </code></pre> <p>...but that would be wrong. The reason is that the program that is actually running is something called the <code>ForkedBooter</code>, and the <code>ForkedBooter</code> programmatically sets system properties for your unit tests. That is, by the time your <code>&lt;systemPropertyVariables&gt;</code> stanza is read by the <code>ForkedBooter</code> it's already too late.</p> <p>But you <em>can</em> use &lt;argLine&gt; in your Surefire configuration like this:</p> <pre><code>&lt;configuration&gt; &lt;argLine&gt;-Djava.endorsed.dirs=weWillGetToThisInAMoment&lt;/argLine&gt; &lt;/configuration&gt; </code></pre> <p>Now the VM that Surefire forks will have its endorsed directories set appropriately. Now let's talk about what value to supply.</p> <p>You want to cherry pick the APIs to override. In your case, <code>javax.annotation.*</code> is a legitimate choice. You want to supply the directory in your local Maven repository that houses the relevant jar.</p> <p>Here is the value that I use:</p> <pre><code>${settings.localRepository}${file.separator}org${file.separator}glassfish${file.separator}main${file.separator}javaee-api${file-separator}javax.annotation${file.separator}${javaxAnnotationVersion} </code></pre> <ul><li>Maven guarantees that <code>${settings.localRepository}</code> will expand to the value of where your local Maven repository lives.</li> <li><code>${file.separator}</code> is a way of getting the value of <code>System.getProperty("file.separator")</code> in a Maven property replacement.</li> <li>In my case, I've already declared a <code>&lt;dependency&gt;</code> on the GlassFish artifact that bundles up the javax.annotation package as defined in Java EE 6. So here I've constructed a path to the artifact. I've also defined a property named <code>javaxAnnotationVersion</code>, which, for me, is set to <code>3.1.2</code>.</li> </ul><p>Once you do all of this, then when Surefire forks a VM to run your unit tests, the endorsed directories will be set to the directory in your local Maven repository containing the jar that houses the <code>javax.annotation</code> classes, and now embedded GlassFish—which runs in-process—will use the Java EE 6 versions of <code>javax.annotation</code> classes instead of the Java SE 6 versions. I hope this helps you out.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/6439368/any-best-practices-for-dealing-with-java-ee-and-java-endorsed-dirs</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/jakarta-ee" hreflang="zh-hans">jakarta-ee</a></div> <div class="field--item"><a href="/tag/glassfish" hreflang="zh-hans">glassfish</a></div> <div class="field--item"><a href="/tag/glassfish-embedded" hreflang="zh-hans">glassfish-embedded</a></div> </div> </div> Fri, 31 Jan 2020 19:12:41 +0000 非 Y 不嫁゛ 3341292 at https://www.e-learn.cn What is the official Maven repository for Embedded GlassFish? https://www.e-learn.cn/topic/3080092 <span>What is the official Maven repository for Embedded GlassFish?</span> <span><span lang="" about="/user/216" typeof="schema:Person" property="schema:name" datatype="">假如想象</span></span> <span>2020-01-03 12:33:47</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>http://maven.glassfish.org/content/groups/glassfish/ looks like it should be GlassFish's official Maven repository, but it currently hosts only up to version 3.1.1-b05 of glassfish-embedded-all (see http://maven.glassfish.org/content/groups/glassfish/org/glassfish/extras/glassfish-embedded-all/).</p> <p>http://download.java.net/maven/glassfish/org/glassfish/extras/ is linked to from Embedded GlassFish's site (Embedded Jars). It doesn't look like an official Maven repository but hosts up to 3.1.1-b11 (at http://download.java.net/maven/glassfish/org/glassfish/extras/glassfish-embedded-all/).</p> <p>So the question is which would be the reliable repository to get the Maven dependencies for Embedded GlassFish from.</p> <br /><h3>回答1:</h3><br /><p>The latest (3.1.2) I could find was at https://maven.java.net/content/repositories/releases/org/glassfish/main/extras/glassfish-embedded-all/</p> <p>Unfortunately, for 3.1.2.2 as of August 21, 2012 seems to be nowhere!</p> <p>I've just opened an issue: http://java.net/jira/browse/GLASSFISH-19028 The very strange thing is that while opening the issue I saw the 3.1.2.2 still classified as "Unreleased Version"...</p> <p><strong>UPDATE!</strong> Today glassfish staff answered : 3.1.2.2 maven artifacts are not yet available on maven central / maven.java.net release repo. You can find them here: https://maven.java.net/content/repositories/releases/org/glassfish/main/extras/glassfish-embedded-all/3.1.2.2/</p> <br /><br /><br /><h3>回答2:</h3><br /><p>As of August 3, 2011 at 12:43 PM EDT http://download.java.net/maven/glassfish/org/glassfish/extras/glassfish-embedded-all/3.1.1 should get you what you want. This is the correct repository.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/6686615/what-is-the-official-maven-repository-for-embedded-glassfish</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/maven" hreflang="zh-hans">maven</a></div> <div class="field--item"><a href="/tag/glassfish-embedded" hreflang="zh-hans">glassfish-embedded</a></div> </div> </div> Fri, 03 Jan 2020 04:33:47 +0000 假如想象 3080092 at https://www.e-learn.cn How to test login/authentication with Arquillian - Java EE 7 https://www.e-learn.cn/topic/2995771 <span>How to test login/authentication with Arquillian - Java EE 7</span> <span><span lang="" about="/user/183" typeof="schema:Person" property="schema:name" datatype="">北城余情</span></span> <span>2019-12-30 02:19:10</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>We have a Java EE 7 application and use Arquillian to test stuff. Now we want to check for some permissions of the currently logged in user. My question is quite basic, how do I login a user when inside a testcase? I have read ProgrammaticLogin doesnt work in arquillian tests and Embedded Glassfish, security and Arquillian questions but they are not clearly answered. My current approach is something like this: </p> <pre><code>// Inject services etc. @Test public void testLogin(){ UserAccount user = new UserAccount(); user.setUsername("bob"); user.setPassword("bob"); userAccountService.save(user); ProgrammaticLogin pl = new ProgrammaticLogin(); String realmName = "secureJDBCRealm"; try { pl.login("bob", "bob".toCharArray(), realmName, true); } catch (Exception e){ e.printStackTrace(); } } </code></pre> <p>Now when I try to run this, a get a LoginException claiming that I have no LoginModule configured for "fileRealm". But "fileRealm" is not the realm i am searching for (I put it there to test first time, but then i changed it to "secureJDBCRealm", which is our custom Security Realm for GlassFish). We use <code>arquillian-glassfish-embedded-3.1</code> for testing.</p> <ul><li>Does anybody know where to define the Realm for Arquillian? </li> <li>Why does my application keep looking for fileRealm? Is this the default value? (couldn't find any specs here)</li> </ul><br /><h3>回答1:</h3><br /><p>Arquillian does not provide any support for defining realms. Instead you need to configure the realm in the container yourself. This is somewhat tricky when using an embedded Glassfish container but it is doable.</p> <p>I am assuming that <code>secureJDBCRealm</code> is a custom realm and not one of the standard/built-in Glassfish Realms. In order to configure a custom realm in a embedded Glassfish container you need to:</p> <ol><li><p>Place a <code>login.conf</code> file on the test class path that references the realm. To do this add a config directory to your resources directory and place <code>login.conf</code> inside that directory. Your <code>login.conf</code> will look something like this</p> <pre><code>secureJDBCRealm { com.blah.blah.LoginModule required; }; </code></pre></li> <li><p>Your custom realm along with any dependencies need to be on the test class path.</p></li> <li><p>You need to programmatically create the realm in glassfish. This can be done via org.glassfish.embeddable.CommandRunner. Luckily the Arquillian Embedded Container makes this available via JNDI which means you can do the following:</p> <pre><code>@Resource(mappedName = "org.glassfish.embeddable.CommandRunner") CommandRunner commandRunner; public void configureLoginRealm() { CommandResult commandResult = commandRunner.run("create-auth-realm", "--classname=com.blah.blah.SecureJDBCRealm", "--property=jaas-context= secureJDBCRealm", "secure-JDBC-realm"); log.debug(commandResult.getExitStatus().toString() + " " + commandResult.getOutput()); Throwable throwable = commandResult.getFailureCause(); if (throwable != null) { log.error(throwable.getMessage(), throwable); } } </code></pre> <p>}</p></li> <li><p>You can then programmatically login with</p> <pre><code>ProgrammaticLogin pl = new ProgrammaticLogin(); String realmName = "secureJDBCRealm"; try { pl.login("bob", "bob".toCharArray(), realmName, true); } catch (Exception e){ e.printStackTrace(); } finally { pl.logout(); } </code></pre></li> </ol><br /><br /><p>来源:<code>https://stackoverflow.com/questions/19271446/how-to-test-login-authentication-with-arquillian-java-ee-7</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/jboss-arquillian" hreflang="zh-hans">jboss-arquillian</a></div> <div class="field--item"><a href="/tag/java-ee-7" hreflang="zh-hans">java-ee-7</a></div> <div class="field--item"><a href="/tag/glassfish-embedded" hreflang="zh-hans">glassfish-embedded</a></div> </div> </div> Sun, 29 Dec 2019 18:19:10 +0000 北城余情 2995771 at https://www.e-learn.cn Using different eclipselink than bundled in glassfish-embedded-web https://www.e-learn.cn/topic/2845511 <span>Using different eclipselink than bundled in glassfish-embedded-web</span> <span><span lang="" about="/user/167" typeof="schema:Person" property="schema:name" datatype="">半世苍凉</span></span> <span>2019-12-24 02:26:27</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I use glassfish-embedded-web for integration tests inside a maven project:</p> <pre><code> &lt;dependency&gt; &lt;groupId&gt;org.glassfish.extras&lt;/groupId&gt; &lt;artifactId&gt;glassfish-embedded-web&lt;/artifactId&gt; &lt;version&gt;3.2-b06&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; </code></pre> <p>glassfish-embedded-web comes with Eclipselink 2.2.0, but the project requires features of 2.4. For regular deployment, this is solved by adding je required jars to glassfish's modules directory and this dependency:</p> <pre><code> &lt;dependency&gt; &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt; &lt;artifactId&gt;org.eclipse.persistence.core&lt;/artifactId&gt; &lt;version&gt;2.4.1&lt;/version&gt; &lt;scope&gt;provided&lt;/scope&gt; &lt;/dependency&gt; </code></pre> <p>I tried also compile scope, still the embedded EL 2.2.0 is used. Adding a test scope dependency on EL 2.4.1 doesn't help. Is there any way to solve this?</p> <br /><h3>回答1:</h3><br /><p>Did you try to specify the maven scope <strong>test</strong>? Otherwise it will not be available while testing! To only provide this version for testing you could use maven profiles.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>I see two possible solutions to this problem: either you <strong>build your own glassfish-embedded</strong> or you just use a brute force approach and <strong>modify the jar</strong>. </p> <p><strong>On the 1st approach:</strong> After spending some time building GF I figured that even with my dilettante shell scripting skills its easier to just use the second approach instead of figuring GF code. However, if you're up for this one I'd suggest to start at oracle wiki.</p> <p><strong>On the 2nd approach:</strong> As I've mentioned above, automating this task is the best approach in my opinion (at least if you're dealing with numerous libs and continuous changes), so I wrote this script with all the necessary instructions on how to use it. After you get the new jar just install it in your local repo. I'm using Nexus so for me it was a matter of couple buttons getting pressed.</p> <p>P.S.: Any comments/advices/improvements on the script are welcome.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/16670701/using-different-eclipselink-than-bundled-in-glassfish-embedded-web</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/glassfish" hreflang="zh-hans">glassfish</a></div> <div class="field--item"><a href="/tag/eclipselink" hreflang="zh-hans">eclipselink</a></div> <div class="field--item"><a href="/tag/glassfish-embedded" hreflang="zh-hans">glassfish-embedded</a></div> </div> </div> Mon, 23 Dec 2019 18:26:27 +0000 半世苍凉 2845511 at https://www.e-learn.cn Java EE 6 - Embedded container EJB tests https://www.e-learn.cn/topic/2688262 <span>Java EE 6 - Embedded container EJB tests</span> <span><span lang="" about="/user/73" typeof="schema:Person" property="schema:name" datatype="">≡放荡痞女</span></span> <span>2019-12-20 10:57:16</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>This questiong is regarding <strong>Java EE 6</strong>, using <strong>glassfish v3 embedded-all</strong>.</p> <p>I have a unit test that uses EJBContainer to test my stateless EJB. Problem is I'm having trouble looking up the EJB (remote) using JNDI:</p> <pre><code>setup() { ctx = EJBContainer.createEJBContainer().getContext(); } ... test() { BookService bookService = (BookService)ctx.lookup("java:global/BookServiceEJB!com.something.service.BookService"); ... } @Stateless public class BookServiceEJB implements BookService { ... } @Remote public interface BookService { ... } </code></pre> <p>gives the exception:</p> <pre><code>javax.naming.NamingException: Lookup failed for 'java:global/BookServiceEJB!com.something.service.BookService' in SerialContext [Root exception is javax.naming.NameNotFoundException: BookServiceEJB!com.something.service.BookService not found] ... caused by: javax.naming.NameNotFoundException: BookServiceEJB!com.something.service.BookService not found </code></pre> <p>I have tried several JNDI resource paths:</p> <p>e.g. </p> <pre><code>java:global/BookServiceEJB java:global/BookService </code></pre> <p>even:</p> <pre><code>java:global/BookShelf-1.0-SNAPSHOT/BookServiceEJB </code></pre> <p>etc...</p> <p>nothings works</p> <p>I <strong>do not have any xml deployment</strong> files configured, only a <code>persistence.xml</code> in META-INF.</p> <p>The test is using maven surefire:</p> <pre><code>mvn clean test </code></pre> <p>Any help is greatly appreciated!</p> <p><strong>Note</strong>: a full deploy to Glassfish server works (using appclient, and <code>@EJB</code> injection)</p> <br /><h3>回答1:</h3><br /><p>After much searching, found the solution that works for me...</p> <p>You'll have to configure the EJBContainer with the property: EJBContainer.MODULES, and the location where the module classes are (if using maven, 'target/classes').</p> <p>e.g. </p> <pre><code>... props = new Properties(); props.put(EJBContainer.MODULES, new File("target/classes")); ec = EJBContainer.createEJBContainer(props); ... </code></pre> <p>If your EJB uses JPA, theres another problem in that you will not be able to define a datasource in the embedded container, so have to use the default ds: 'jdbc/__default'.</p> <p>so for example my persistence.xml looks like so:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"&gt; &lt;persistence-unit name="bookshelf" transaction-type="JTA"&gt; &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt; &lt;class&gt;com.blah.domain.Book&lt;/class&gt; &lt;jta-data-source&gt;jdbc/__default&lt;/jta-data-source&gt; &lt;properties&gt; &lt;property name="eclipselink.logging.level" value="INFO"/&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>I haven't figured out how to configure the embedded container test to use one DS (jdbc/__default), and my app to use another (e.g. jdbc/booksDS)</p> <p><strong>see</strong>: http://www.mentby.com/glassfish/embedded-testing-woes.html</p> <p><strong>see</strong>: http://forums.java.net/jive/thread.jspa?messageID=395759</p> <p>To be honest I don't know why people are bothering with Java EE when solutions like spring is so much simpler...</p> <p>It has been very frustrating and alot of time wasted... hope this helps.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>There's a few items you need to check in order to make sure you can load the bean through the <em>context.lookup</em> avoiding a <em>NamingException</em>.</p> <ol><li><p>Make sure you have a bean. This may sound something obvious but I spent a lot of time trying to figure out why I wasn't able to get an instance of my service in the tests. The reason was that I was missing the <strong>Stateless</strong> annotation.</p></li> <li><p>Add the module when creating the container as @Dzhu pointed out. For maven <strong>classes</strong> will be <em>target/<strong>classes</strong></em>, for maven <strong>tests</strong> will be <em>target/<strong>test-classes</strong></em>.</p></li> <li><p>Something is wrong if you find a message like <code>SEVERE: EJB6005:No EJB modules found</code> in the console. It tells you that there are no <em>Stateless</em> annotated classes</p></li> <li><p>Take a look at the embedded glassfish console! In there you will see the lookup names for your beans. Pay attention to the messages in the format <code>INFO: EJB5181:Portable JNDI names for EJB YourBean: [java:global/classes/YourBean!bean.package.YourBean, java:global/classes/YourBean]</code>. That means you can lookup your bean either by calling <code>context.lookup("java:global/classes/YourBean!bean.package.YourBean")</code> or by the shorter name <code>context.lookup("java:global/classes/YourBean")</code> which can be useful if there's no name collisions. </p></li> </ol><p>Hope this helps someone. It would have been really helpful to have had this tips.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>I have written a small tutorial on using the embedded glassfish 3.1 container, also addressing the issue for needing a different persistence.xml for tests. Also fixing container crashes with remote interfaces and webservices. You can check it out at http://pschyska.blogspot.com/2011/06/unit-testing-ejb-31-with-netbeans-maven.html</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/3938347/java-ee-6-embedded-container-ejb-tests</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java-ee-0" hreflang="zh-hans">java-ee</a></div> <div class="field--item"><a href="/tag/jndi" hreflang="zh-hans">jndi</a></div> <div class="field--item"><a href="/tag/java-ee-6" hreflang="zh-hans">java-ee-6</a></div> <div class="field--item"><a href="/tag/glassfish-3" hreflang="zh-hans">glassfish-3</a></div> <div class="field--item"><a href="/tag/glassfish-embedded" hreflang="zh-hans">glassfish-embedded</a></div> </div> </div> Fri, 20 Dec 2019 02:57:16 +0000 ≡放荡痞女 2688262 at https://www.e-learn.cn Maven Embedded Glassfish plugin https://www.e-learn.cn/topic/2608990 <span>Maven Embedded Glassfish plugin</span> <span><span lang="" about="/user/133" typeof="schema:Person" property="schema:name" datatype="">时光怂恿深爱的人放手</span></span> <span>2019-12-18 12:28:47</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I cannot seem to get the Maven Glassfish plugin working for the life of me:</p> <pre><code>&lt;project&gt; ... &lt;pluginRepositories&gt; &lt;pluginRepository&gt; &lt;id&gt;glassfish-repository&lt;/id&gt; &lt;name&gt;Java.net Repository for Glassfish&lt;/name&gt; &lt;url&gt;http://download.java.net/maven/glassfish&lt;/url&gt; &lt;layout&gt;default&lt;/layout&gt; &lt;snapshots&gt; &lt;enabled&gt;true&lt;/enabled&gt; &lt;updatePolicy&gt;never&lt;/updatePolicy&gt; &lt;/snapshots&gt; &lt;/pluginRepository&gt; &lt;/pluginRepositories&gt; ... &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.glassfish&lt;/groupId&gt; &lt;artifactId&gt;maven-embedded-glassfish-plugin&lt;/artifactId&gt; &lt;version&gt;3.0&lt;/version&gt; &lt;configuration&gt; &lt;goalPrefix&gt;glassfish&lt;/goalPrefix&gt; &lt;app&gt;${artifactId}.war&lt;/app&gt; &lt;contextRoot&gt;${context.root}&lt;/contextRoot&gt; &lt;port&gt;${http.port}&lt;/port&gt; &lt;/configuration&gt; &lt;/plugin&gt; ... &lt;/plugins&gt; &lt;/build&gt; &lt;/project&gt; </code></pre> <p>When I run <code>mvn glassfish:run</code>, it is looking for a different plugin and cannot find it:</p> <pre><code>[INFO] The plugin 'org.apache.maven.plugins:maven-glassfish-plugin' does not exist or no valid version could be found </code></pre> <p>Any ideas?</p> <br /><h3>回答1:</h3><br /><p>You're not invoking the right plugin. It should be:</p> <pre><code>mvn embedded-glassfish:run </code></pre> <p>Actually, I'm using it like this: (with the same plugin repository you declared): </p> <pre><code>&lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.glassfish&lt;/groupId&gt; &lt;artifactId&gt;maven-embedded-glassfish-plugin&lt;/artifactId&gt; &lt;version&gt;3.0&lt;/version&gt; &lt;configuration&gt; &lt;goalPrefix&gt;glassfish&lt;/goalPrefix&gt; &lt;app&gt;target/test.war&lt;/app&gt; &lt;port&gt;8080&lt;/port&gt; &lt;contextRoot&gt;test&lt;/contextRoot&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;execution&gt; &lt;phase&gt;package&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;run&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; </code></pre> <p><strong>Update:</strong> Just in case, the fully qualified name of <strong>this</strong> plugin would be:</p> <pre><code>mvn org.glassfish:maven-embedded-glassfish-plugin:3.0:run </code></pre> <p>But using the short name works for me.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>@Walter White (can't/don't know how to reply to your comment so I'm answering instead): I've read that scattered WAR's are not fully supported by embedded GlassFish v3.</p> <p>Personally I'm anxiously awaiting v3.1 with Timer and MessageDriven support. Hopefully web service support will be included as well. Does anybody happen to have a clue about an ETA for v3.1?</p> <p>PS: <code>mvn org.glassfish:maven-embedded-glassfish-plugin:3.0:run</code> works for me. Will hook it up into a proper maven integration-test life cycle now.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>This problem outcome from fact that 2 differnt maven-glassfish plugins exist with the same name. Try to use </p> <pre><code>mvn org.glassfish:maven-glassfish-plugin:run </code></pre> <p>Detailed explanatation of this problem you can find here.</p> <br /><br /><br /><h3>回答4:</h3><br /><p>see on github working example</p> <p>mvn package embedded-glassfish:run</p> <pre><code>&lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;javax&lt;/groupId&gt; &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt; &lt;version&gt;7.0&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.glassfish.embedded&lt;/groupId&gt; &lt;artifactId&gt;maven-embedded-glassfish-plugin&lt;/artifactId&gt; &lt;version&gt;3.1.2.2&lt;/version&gt; &lt;configuration&gt; &lt;app&gt;target/${project.artifactId}-${project.version}&lt;/app&gt; &lt;port&gt;8080&lt;/port&gt; &lt;contextRoot&gt;${project.artifactId}&lt;/contextRoot&gt; &lt;/configuration&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.glassfish.main&lt;/groupId&gt; &lt;artifactId&gt;simple-glassfish-api&lt;/artifactId&gt; &lt;version&gt;4.0-b79&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.glassfish.main.extras&lt;/groupId&gt; &lt;artifactId&gt;glassfish-embedded-all&lt;/artifactId&gt; &lt;version&gt;4.0-b83&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;/plugin&gt; &lt;plugin&gt; &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt; &lt;version&gt;3.1&lt;/version&gt; &lt;configuration&gt; &lt;source&gt;1.8&lt;/source&gt; &lt;target&gt;1.8&lt;/target&gt; &lt;encoding&gt;UTF-8&lt;/encoding&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;pluginRepositories&gt; &lt;pluginRepository&gt; &lt;id&gt;maven.java.net&lt;/id&gt; &lt;name&gt;Java.net Repository for Maven&lt;/name&gt; &lt;url&gt;https://maven.java.net/content/groups/promoted/&lt;/url&gt; &lt;/pluginRepository&gt; &lt;pluginRepository&gt; &lt;id&gt;maven2-repository.dev.java.net&lt;/id&gt; &lt;name&gt;Java.net Repository for Maven&lt;/name&gt; &lt;url&gt;http://download.java.net/maven/glassfish/&lt;/url&gt; &lt;/pluginRepository&gt; &lt;/pluginRepositories&gt; </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/2238665/maven-embedded-glassfish-plugin</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/maven-2" hreflang="zh-hans">maven-2</a></div> <div class="field--item"><a href="/tag/glassfish" hreflang="zh-hans">glassfish</a></div> <div class="field--item"><a href="/tag/glassfish-3" hreflang="zh-hans">glassfish-3</a></div> <div class="field--item"><a href="/tag/glassfish-embedded" hreflang="zh-hans">glassfish-embedded</a></div> </div> </div> Wed, 18 Dec 2019 04:28:47 +0000 时光怂恿深爱的人放手 2608990 at https://www.e-learn.cn glassfish-embedded-maven-plugin - how to deploy resources https://www.e-learn.cn/topic/2410228 <span>glassfish-embedded-maven-plugin - how to deploy resources</span> <span><span lang="" about="/user/16" typeof="schema:Person" property="schema:name" datatype="">筅森魡賤</span></span> <span>2019-12-12 21:35:54</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I'm providing a quick and easy way for users to deploy my Java EE 6 application via glassfish-embedded-maven-plugin, so they don't have to install and configure a standalone glassfish. However, I'm running into trouble with resource deployment.</p> <p>The app needs a JavaMail resource from the container, and needs a JAAS realm with a suitable role-&gt;user/group mapping.</p> <p>When deploying to a standalone glassfish this is easily provided with a sun-resources.xml file and/or a couple of asadmin commands. However, I'm struggling to figure out how to do it with glassfish embedded.</p> <p>Is there a way I can auto-deploy a glassfish-resources.xml in my pom as part of the glassfish-embedded-maven-plugin invocation? The documentation for the plugin is nearly nonexistent or refers to the badly out of date 2.1 version, and I'm increasingly stuck.</p> <br /><h3>回答1:</h3><br /><p>It looks like the maven-embedded-glassfish-plugin is just too limited for this use case.</p> <p>Instead, use the embedded glassfish api. This has changed completely in 3.1, but most of the web refers to the old 3.0.1 api, so most examples you can find will be wrong. Start here:</p> <p>http://embedded-glassfish.java.net/nonav/apidocs/org/glassfish/embeddable/GlassFish.html</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/5455268/glassfish-embedded-maven-plugin-how-to-deploy-resources</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java-ee-0" hreflang="zh-hans">java-ee</a></div> <div class="field--item"><a href="/tag/maven" hreflang="zh-hans">maven</a></div> <div class="field--item"><a href="/tag/glassfish" hreflang="zh-hans">glassfish</a></div> <div class="field--item"><a href="/tag/java-ee-6" hreflang="zh-hans">java-ee-6</a></div> <div class="field--item"><a href="/tag/glassfish-embedded" hreflang="zh-hans">glassfish-embedded</a></div> </div> </div> Thu, 12 Dec 2019 13:35:54 +0000 筅森魡賤 2410228 at https://www.e-learn.cn Specify logging.properties in embedded Glassfish with maven-embedded-glassfish-plugin https://www.e-learn.cn/topic/2404922 <span>Specify logging.properties in embedded Glassfish with maven-embedded-glassfish-plugin</span> <span><span lang="" about="/user/146" typeof="schema:Person" property="schema:name" datatype="">狂风中的少年</span></span> <span>2019-12-12 18:51:19</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I use a project template containing a Maven configuration for an embedded Glassfish (using the maven-embedded-glassfish-plugin). I need to enable logging, but I do not even know which logging engine is enabled in the Glassfish (since I did not create the template).</p> <p>The template uses <em>slf4j-log4j12</em> as a dependency, but I am not sure if slf4j or java.util.logging does the actual logging. Therefore I created two logging files, one <code>logging.properties</code> and one <code>log4j.properties</code> and put them both to <code>src/main/resources</code> and <code>/src/main/resources/META-INF</code>, which both does not seem to work.</p> <p>I added <code>java.util.logging.config.file=logging.properties</code> to the Maven Glassfish system properties (also for log4j), and also this did not work out. I checked, that the properties files are in the JAR file.</p> <p>How can I determine which backend is responsible for logging?</p> <p><strong>How can I specify a logging configuration for embedded Glassfish using the Maven embedded Glassfish plugin?</strong></p> <p>Currently I get logging output at level INFO on default out. I guess this is the default setting.</p> <p>来源:<code>https://stackoverflow.com/questions/16335091/specify-logging-properties-in-embedded-glassfish-with-maven-embedded-glassfish-p</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/logging" hreflang="zh-hans">logging</a></div> <div class="field--item"><a href="/tag/glassfish-embedded" hreflang="zh-hans">glassfish-embedded</a></div> <div class="field--item"><a href="/tag/maven-glassfish-plugin" hreflang="zh-hans">maven-glassfish-plugin</a></div> </div> </div> Thu, 12 Dec 2019 10:51:19 +0000 狂风中的少年 2404922 at https://www.e-learn.cn Unexpected behaviour of EntityManager.merge() https://www.e-learn.cn/topic/2362354 <span>Unexpected behaviour of EntityManager.merge()</span> <span><span lang="" about="/user/81" typeof="schema:Person" property="schema:name" datatype="">人盡茶涼</span></span> <span>2019-12-12 06:15:31</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am using embedded glassfish (3.1.2.2) with junit (4.11), with JDK 1.7, though my source and target is set to 1.6 (maven-compiler-plugin configuration).</p> <p>Following is my code:</p> <p><strong>Person.java</strong></p> <pre><code>@Entity public class Person implements Serializable { private static final long serialVersionUID = 81398385247591972L; @Id @GeneratedValue private Long id; @Version private Long version; @Column(length = 15, nullable = false, unique = true, updatable = false) private String username; @Column(length = 50) private String status; // Constructors // getters/setters // hashCode, equals, toString } </code></pre> <p><strong>Service.java</strong></p> <pre><code>@Stateless public class Service { @PersistenceContext(unitName = "ExamplePU", type = PersistenceContextType.TRANSACTION) private EntityManager em; public Person add(Person person) { em.persist(person); return person; } public Person find(Long id) { return em.find(Person.class, id); } public Person modify(Person person) { return em.merge(person); } // some more code ... } </code></pre> <p><strong>ServiceTest.java</strong></p> <pre><code>public class ServiceTest { private static EJBContainer ejbContainer; private static Service service; // @BeforeClass, @AfterClass, @Before, @After @Test public void testMerge() { Person person; /* Step 1 */person = service.add(new Person("username", "status")); print("Added : " + person); person.setStatus("Away"); /* Step 2 */person = service.modify(person); print("Merged (status change) : " + person); person.setUsername("UsErNaMe"); /* Step 3 */person = service.modify(person); print("Merged (username change) : " + person); } // Some more tests } </code></pre> <p><strong>Step 1</strong> generates following SQL (as expected):</p> <pre><code>INSERT INTO PERSON (ID, STATUS, USERNAME, VERSION) VALUES (?, ?, ?, ?) bind =&gt; [1, status, username, 1] </code></pre> <p><strong>Step 2</strong> generates following SQL (as expected):</p> <pre><code>UPDATE PERSON SET STATUS = ?, VERSION = ? WHERE ((ID = ?) AND (VERSION = ?)) bind =&gt; [Away, 2, 1, 1] </code></pre> <p><strong>Step 3</strong> does not generate any SQL, but it does not throw any exception, which I am expecting, as the 'username' is annotated as <strong>@Column(..., updatable = false)</strong>. The print(...) method prints following output:</p> <blockquote> <p>Merged (username change) : Person [id=1, version=2, username=UsErNaMe, status=Away]</p> </blockquote> <p>This time the merge() operation has updated username, but not version. Also, now the database is out-of-sync with EntityManager cache.</p> <p>Is this expected, or bug in EclipseLink?</p> <p><strong>UPDATE</strong></p> <p>Expected result is exception at Step 3 above.</p> <p><strong>UPDATE</strong></p> <p>Have filed bug here.</p> <br /><h3>回答1:</h3><br /><p>You marked the column as non-updatable, and EclipseLink detects that the only change made to the person you tell it to merge is the user name. But the user name must not be updated. So it doesn't issue any SQL update query. </p> <p>If you mark a column as non-updatable, you shouldn't update it.</p> <p>So, to make things clear, the behavior you observe is the expected behavior.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/15108064/unexpected-behaviour-of-entitymanager-merge</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/jpa-20" hreflang="zh-hans">jpa-2.0</a></div> <div class="field--item"><a href="/tag/eclipselink" hreflang="zh-hans">eclipselink</a></div> <div class="field--item"><a href="/tag/glassfish-embedded" hreflang="zh-hans">glassfish-embedded</a></div> </div> </div> Wed, 11 Dec 2019 22:15:31 +0000 人盡茶涼 2362354 at https://www.e-learn.cn Deployed null when using embedded glassfish server https://www.e-learn.cn/topic/2308122 <span>Deployed null when using embedded glassfish server</span> <span><span lang="" about="/user/38" typeof="schema:Person" property="schema:name" datatype="">|▌冷眼眸甩不掉的悲伤</span></span> <span>2019-12-11 22:55:46</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>after reading several tutorials (e.g. ocpsoft, oracle) I started to use embedded glassfish for running my hello-world app. It does work with the remote server but for some reason nothing is deployed when using the embedded server.</p> <p>1.) "Cannot find javadb client jar file, derby jdbc driver will not be available by default." I am using derby and although e.g. variable AS_DERBY_INSTALL is set and exported it seems the jars cannot be found. Why?</p> <p>2.) "INFO: Deployed null" Why is my app not deployed???</p> <p>maven output when run e.g. as "mvn clean install" (doesn't make a difference whether I run "mvn install embedded-glassfish:run" or "mvn install embedded-glassfish:deploy").</p> <p><strong>maven output</strong></p> <pre><code>[...] There are no tests to run. Results : Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-war-plugin:2.1.1:war (default-war) @ transact --- [INFO] Packaging webapp [INFO] Assembling webapp [transact] in [/Users/grudom/Daten/IDE/EclipseProjects/workspace/transact/target/transact] [INFO] Processing war project [INFO] Copying webapp resources [/Users/grudom/Daten/IDE/EclipseProjects/workspace/transact/src/main/webapp] [INFO] Webapp assembled in [117 msecs] [INFO] Building war: /Users/grudom/Daten/IDE/EclipseProjects/workspace/transact/target/transact.war [INFO] WEB-INF/web.xml already added, skipping [INFO] [INFO] --- maven-install-plugin:2.3.1:install (default-install) @ transact --- [INFO] Installing /Users/grudom/Daten/IDE/EclipseProjects/workspace/transact/target/transact.war to /Users/grudom/.m2/repository/de/exim/transact/1.0-SNAPSHOT/transact-1.0-SNAPSHOT.war [INFO] Installing /Users/grudom/Daten/IDE/EclipseProjects/workspace/transact/pom.xml to /Users/grudom/.m2/repository/de/exim/transact/1.0-SNAPSHOT/transact-1.0-SNAPSHOT.pom [INFO] [INFO] --- maven-embedded-glassfish-plugin:3.1.2.2:run (default) @ transact --- Created New Bootstrap ClassLoader. ServerId = maven, ClassPaths = ClassPath Element : file:/Users/grudom/.m2/repository/org/glassfish/main/extras/glassfish-embedded-all/3.1.2.2/glassfish-embedded-all-3.1.2.2.jar ClassPath Element : file:/Users/grudom/.m2/repository/org/glassfish/embedded/maven-embedded-glassfish-plugin/3.1.2.2/maven-embedded-glassfish-plugin-3.1.2.2.jar ClassPath Element : file:/Users/grudom/.m2/repository/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.jar ClassPath Element : file:/Users/grudom/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar ClassPath Element : file:/Users/grudom/.m2/repository/org/glassfish/main/common/simple-glassfish-api/3.1.2.2/simple-glassfish-api-3.1.2.2.jar 03.09.2012 16:28:18 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default. 03.09.2012 16:28:18 org.hibernate.validator.internal.util.Version &lt;clinit&gt; INFO: HV000001: Hibernate Validator 4.3.0.Final 03.09.2012 16:28:18 PluginUtil getGlassFish INFO: Created GlassFish ServerId = maven, BootstrapProperties = {GlassFish_Platform=Static}, GlassFishRuntime = com.sun.enterprise.glassfish.bootstrap.StaticGlassFishRuntime@7cb9e9a3, GlassFishProperties = {embedded-glassfish-config.server.network-config.network-listeners.network-listener.http-listener.enabled=true, embedded-glassfish-config.server.network-config.network-listeners.network-listener.http-listener.port=8080}, GlassFish = com.sun.enterprise.glassfish.bootstrap.StaticGlassFishRuntime$1@119a0c4e, GlassFish Status = INIT, TimeTaken = 876 ms 03.09.2012 16:28:18 com.sun.enterprise.v3.services.impl.GrizzlyService createNetworkProxy INFO: Network listener https-listener on port 0 disabled per domain.xml 03.09.2012 16:28:19 com.sun.enterprise.v3.services.impl.GrizzlyProxy$2$1 onReady INFO: Grizzly Framework 1.9.50 started in: 52ms - bound to [0.0.0.0:8080] 03.09.2012 16:28:19 com.sun.enterprise.v3.server.AppServerStartup run INFO: GlassFish Server Open Source Edition 3.1.2.2 (java_re) startup time : Embedded (678ms), startup services(523ms), total(1.201ms) 03.09.2012 16:28:19 PluginUtil startGlassFish INFO: Started GlassFish ServerId = maven, GlassFish = com.sun.enterprise.glassfish.bootstrap.StaticGlassFishRuntime$1@119a0c4e, TimeTaken = 747 ms 03.09.2012 16:28:19 PluginUtil doDeploy INFO: Deployed null Hit ENTER to redeploy, X to exit </code></pre> <p><strong>pom.xml</strong></p> <pre><code>&lt;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"&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;de.exim&lt;/groupId&gt; &lt;artifactId&gt;transact&lt;/artifactId&gt; &lt;packaging&gt;war&lt;/packaging&gt; &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt; &lt;name&gt;transact Maven Webapp&lt;/name&gt; &lt;url&gt;http://maven.apache.org&lt;/url&gt; &lt;properties&gt; &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt; &lt;maven.build.timestamp.format&gt;yyyyMMdd'T'HHmmss&lt;/maven.build.timestamp.format&gt; &lt;glassfish.home&gt;/Users/grudom/Programme/glassfish&lt;/glassfish.home&gt; &lt;glassfish.adminUser&gt;admin&lt;/glassfish.adminUser&gt; &lt;glassfish.adminPassword&gt;admin&lt;/glassfish.adminPassword&gt; &lt;glassfish.domain.name&gt;domain1&lt;/glassfish.domain.name&gt; &lt;glassfish.domain.host&gt;localhost&lt;/glassfish.domain.host&gt; &lt;glassfish.domain.adminPort&gt;4848&lt;/glassfish.domain.adminPort&gt; &lt;eclipselink.version&gt;2.4.0&lt;/eclipselink.version&gt; &lt;/properties&gt; &lt;repositories&gt; &lt;repository&gt; &lt;id&gt;EclipseLink&lt;/id&gt; &lt;url&gt;http://download.eclipse.org/rt/eclipselink/maven.repo&lt;/url&gt; &lt;/repository&gt; &lt;/repositories&gt; &lt;pluginRepositories&gt; &lt;pluginRepository&gt; &lt;id&gt;maven2-repository.dev.java.net&lt;/id&gt; &lt;name&gt;Java.net Repository for Maven&lt;/name&gt; &lt;url&gt;http://download.java.net/maven/glassfish/&lt;/url&gt; &lt;/pluginRepository&gt; &lt;/pluginRepositories&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;junit&lt;/groupId&gt; &lt;artifactId&gt;junit&lt;/artifactId&gt; &lt;version&gt;3.8.1&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;log4j&lt;/groupId&gt; &lt;artifactId&gt;log4j&lt;/artifactId&gt; &lt;version&gt;1.2.16&lt;/version&gt; &lt;scope&gt;compile&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt; &lt;artifactId&gt;eclipselink&lt;/artifactId&gt; &lt;version&gt;${eclipselink.version}&lt;/version&gt; &lt;scope&gt;compile&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;javax&lt;/groupId&gt; &lt;artifactId&gt;javaee-api&lt;/artifactId&gt; &lt;version&gt;6.0&lt;/version&gt; &lt;scope&gt;provided&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.derby&lt;/groupId&gt; &lt;artifactId&gt;derby&lt;/artifactId&gt; &lt;version&gt;10.9.1.0&lt;/version&gt; &lt;scope&gt;compile&lt;/scope&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;build&gt; &lt;finalName&gt;${project.artifactId}&lt;/finalName&gt; &lt;pluginManagement&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt; &lt;version&gt;2.3.2&lt;/version&gt; &lt;configuration&gt; &lt;source&gt;1.6&lt;/source&gt; &lt;target&gt;1.6&lt;/target&gt; &lt;encoding&gt;ISO-8859-1&lt;/encoding&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt; &lt;version&gt;2.9&lt;/version&gt; &lt;configuration&gt; &lt;wtpversion&gt;1.5&lt;/wtpversion&gt; &lt;downloadSources&gt;true&lt;/downloadSources&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/pluginManagement&gt; &lt;/build&gt; &lt;profiles&gt; &lt;profile&gt; &lt;id&gt;glassfish&lt;/id&gt; &lt;activation&gt; &lt;activeByDefault&gt;false&lt;/activeByDefault&gt; &lt;/activation&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.glassfish.maven.plugin&lt;/groupId&gt; &lt;artifactId&gt;maven-glassfish-plugin&lt;/artifactId&gt; &lt;version&gt;2.1&lt;/version&gt; &lt;configuration&gt; &lt;terse&gt;false&lt;/terse&gt; &lt;echo&gt;true&lt;/echo&gt; &lt;debug&gt;true&lt;/debug&gt; &lt;glassfishDirectory&gt;${glassfish.home}&lt;/glassfishDirectory&gt; &lt;user&gt;${glassfish.adminUser}&lt;/user&gt; &lt;adminPassword&gt;${glassfish.adminPassword}&lt;/adminPassword&gt; &lt;domain&gt; &lt;name&gt;${glassfish.domain.name}&lt;/name&gt; &lt;host&gt;${glassfish.domain.host}&lt;/host&gt; &lt;adminPort&gt;${glassfish.domain.adminPort}&lt;/adminPort&gt; &lt;/domain&gt; &lt;components&gt; &lt;component&gt; &lt;name&gt;${project.artifactId}&lt;/name&gt; &lt;artifact&gt;${project.build.directory}/${project.build.finalName}.war&lt;/artifact&gt; &lt;/component&gt; &lt;/components&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/profile&gt; &lt;profile&gt; &lt;id&gt;embeddedglassfish&lt;/id&gt; &lt;activation&gt; &lt;activeByDefault&gt;true&lt;/activeByDefault&gt; &lt;/activation&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.glassfish.embedded&lt;/groupId&gt; &lt;artifactId&gt;maven-embedded-glassfish-plugin&lt;/artifactId&gt; &lt;version&gt;3.1.2.2&lt;/version&gt; &lt;configuration&gt; &lt;goalPrefix&gt;embedded-glassfish&lt;/goalPrefix&gt; &lt;app&gt;test.war&lt;/app&gt; &lt;port&gt;8080&lt;/port&gt; &lt;contextRoot&gt;test&lt;/contextRoot&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;execution&gt; &lt;phase&gt;install&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;run&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/profile&gt; &lt;/profiles&gt; &lt;/project&gt; </code></pre> <p>When using</p> <pre><code> &lt;groupId&gt;org.glassfish&lt;/groupId&gt; &lt;artifactId&gt;maven-embedded-glassfish-plugin&lt;/artifactId&gt; &lt;version&gt;3.0&lt;/version&gt; </code></pre> <p>maven throws a LifecycleExecutionException with caused by: java.io.FileNotFoundException: test.war. Looking on the file system test.war wasn't even created. If I change to version 3.1 then no exception is thrown but again "deployed null". Why is no war file being generated?</p> <br /><h3>回答1:</h3><br /><p>At last I found the problem. The correct configuration would be</p> <pre><code>&lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.glassfish&lt;/groupId&gt; &lt;artifactId&gt;maven-embedded-glassfish-plugin&lt;/artifactId&gt; &lt;version&gt;3.1&lt;/version&gt; &lt;configuration&gt; &lt;goalPrefix&gt;embedded-glassfish&lt;/goalPrefix&gt; &lt;app&gt;target/${project.build.finalName}.war&lt;/app&gt; &lt;port&gt;8080&lt;/port&gt; &lt;contextRoot&gt;${project.build.finalName}&lt;/contextRoot&gt; &lt;autoDelete&gt;true&lt;/autoDelete&gt; &lt;configFile&gt;path_to_File/domain.xml&lt;/configFile&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;execution&gt; &lt;phase&gt;install&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;run&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; </code></pre> <p>Apart from referencing the correct groupId and version the element "app" needed a change. Additionally, in order to use a non-embedded instance of javadb the configFile element is pointing to the domain.xml of the non-embedded glassfish server.</p> <p>Further documentation: http://docs.oracle.com/cd/E26576_01/doc.312/e24932/toc.htm</p> <p>Hope, it helps others, too.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/12250095/deployed-null-when-using-embedded-glassfish-server</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java-ee-0" hreflang="zh-hans">java-ee</a></div> <div class="field--item"><a href="/tag/maven-plugin" hreflang="zh-hans">maven-plugin</a></div> <div class="field--item"><a href="/tag/glassfish-embedded" hreflang="zh-hans">glassfish-embedded</a></div> </div> </div> Wed, 11 Dec 2019 14:55:46 +0000 |▌冷眼眸甩不掉的悲伤 2308122 at https://www.e-learn.cn