0

I'm working with the javaee tutorials with glassfish and maven. I can get the example to run fine. What I'm trying to do is recreate the same example from scratch which I have done. (created by opening a new maven project in netbenas

With the examples though, from command line when I mvn install the example app automatically gets deployed on the glassfish server. I'm thinking the reason fort his is that the example file is already placed in the glassfish directory

C:\
glassfish4
       docs
          javaee-tutorial
                       examples
                             web
                               jsf
                                 hello1 (target application)

Now my project is being created in a different NetBeansProjects directory

C:\
netbeansprojects
            javaee_tuts
                     practiceproject (target application)

The example project gets automatically deployed, but my practiceproject doesn't get deployed. I'm guessing because the project is not in the glassfish directory or it could a combination of this and other things, of which I'm not sure. I thought maybe I could configure it somehow with the pom.xml but I'm very new to maven, and not too familiar with the pom.

Here are the two poms

example pom

<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/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>

   <parent>
      <artifactId>jsf</artifactId>
      <groupId>org.glassfish.javaeetutorial</groupId>
      <version>7.0.3</version>
   </parent>

   <groupId>org.glassfish.javaeetutorial</groupId>
   <artifactId>hello1</artifactId>
   <version>7.0.3</version>
   <packaging>war</packaging>

   <name>${project.artifactId}</name>
</project>

My practiceproject pom

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mavenpractice</groupId>
<artifactId>practiceproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>practiceproject</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>7.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

</project>

I can get the project to deploy through netbeans, that's no problem, but I want to practice using maven through command line. So to conclude with a single question:

What do I need to do to get my practice project to auto deploy on glassfish using mvn install from command line?

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • The default `mvn install` doesn't automatically deploy your project to glassfish server. It just installs your built project into its own maven cache (commonly found here: ${MAVEN_HOME}/repository). You need some external maven plugins to work with this: See [this question](http://stackoverflow.com/q/9964922/205936) and [this SO answer](http://stackoverflow.com/a/12752063/205936) - customise accordingly. You can find the maven glassfish plugin [here](https://maven-glassfish-plugin.java.net/) – S.R.I Nov 18 '13 at 05:35
  • @S.R.I. Then why does the example app get deployed to the server. Is it because It is in the glassfish directory? That is my question. If I'm using `mvn install` for the example and the example gets deployed, what can I do to replicate this action? Should I place the `practiceproject` in the glassfish directory also? – Paul Samsotha Nov 18 '13 at 05:39
  • That's because Netbeans already has a connector configured in its pom.xml (or `build.xml` if it's ant based deploy) to deploy into glassfish. That's the reason why you could deploy easily through an IDE. But while running/deploying from command line, you have to rely on maven plugins to do the task for you. – S.R.I Nov 18 '13 at 05:47
  • If you're looking for scripts that do this in your IDE, look under those `nbproject` folders - something like `build-impl.xml` or `ant-deploy.xml`. – S.R.I Nov 18 '13 at 05:49

1 Answers1

1

mvn install don't make deploy, but you can use some plugin like cargo and asadmin for help in that task.

https://github.com/Codeartisans/asadmin

http://cargo.codehaus.org/

bcfurtado
  • 181
  • 2
  • 12