开发者

Setting up IntelliJ and GlassFish on a Mac

开发者 https://www.devze.com 2023-01-27 21:29 出处:网络
I\'m looking for help coming up with the steps required to get a basic \"hello world\" web app up and running on a Mac using IntelliJ and GlassFish. So far I\'ve found this guide, which is helpful but

I'm looking for help coming up with the steps required to get a basic "hello world" web app up and running on a Mac using IntelliJ and GlassFish. So far I've found this guide, which is helpful but outdated (some dialogs/steps have changed since it was written).

Can anyone well-ver开发者_运维问答sed in these tools help me sort out the steps required to get a basic web app deployed to GlassFish 3.0.1 using IntelliJ 9.0.4?


First, get Glassfish running on its own. This experience will serve you well, since the process is pretty much the same on all Unix systems. If you only learn to interact with Glassfish through your IDE, then you'll be totally lost without the IDE.

There are two ways to deploy an app: through the admin web interface (user-friendly, but painfully slow), or through the command line. Here's how you do the latter: first, make sure that the asadmin utility that came with Glassfish is on your path, then do something like this:

asadmin --user admin deploy --name hello ~/projects/hello/build/hello.ear

By default, the admin user has an empty password; if it doesn't, you'll be prompted for it.


I don't know about Glassfish, but I can tell you how to do it with Tomcat. The only difference should be the app server that you start inside IntelliJ:

  1. Under project settings, create a web module - that'll give you your /WEB-INF and web.xml
  2. Under project settings, create an artifact that maps to your exploded WAR file. Make sure that the JARs you need are added to the WEB-INF/lib; your .class files are copied to WEB-INF/classes; all necessary resources are put where you want them.
  3. Set up Glassfish and tell it to deploy your exploded WAR artifact. Give it the name of your web app as context root (e.g., "/foo").
  4. Run the web app. IntelliJ will compile your code, create the exploded WAR artifact in the /out directory, and deploy to your app server.
  5. You should see the app start under the URL http://localhost:4848/foo/index.html, assuming you have an index.html welcome file in your web.xml

JNDI set up is another matter.


IMO the best way to have an EAR/WAR deployed on any application server is to use Maven to build an EAR and Cargo Maven plugin for redeploying. The reason why I would use it is that it's totally IDE-independent and can use it both in development and my continuous integration server.

pom.xml fragment of EAR/WAR module for Glassfish:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.0.2</version>
    <configuration>
        <container>
            <containerId>glassfish2x</containerId> <!-- or glassfish3x -->
            <type>installed</type>
            <home>${glassfish.home}</home>
        </container>
        <configuration>
            <properties>
                <cargo.remote.password>${glassfish.password}</cargo.remote.password>
            </properties>
        </configuration>
        <deployer>
            <type>installed</type>
            <deployables>
                <deployable>
                    <location>${project.build.directory}/${project.build.finalName}.${project.packaging}</location>
                </deployable>
            </deployables>
        </deployer>
    </configuration>
</plugin>

Redeploy command:

mvn cargo:redeploy -Dglassfish.home=/path/to/glassfish/-Dglassfish.password=adminadmin -DskipTests=true -o

You should learn about Maven 2 if you don't know what it is.


I had success with this tutorial: Developing applications for GlassFish Server in IntelliJ IDEA 10. I'm using IDEA 11 and GlassFish 3.1.2

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号