Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

6/01/2015

IntelliJ IDEA: pass JAVA_HOME, M2_HOME, MAVEN_OPTS to the IDE using Yosemite

Place the following content (enhance it to your taste obviously) to /Library/LaunchDaemons/setenv.MAVEN_OPTS.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
  <dict>
  <key>Label</key>
  <string>setenv.BAR</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/launchctl</string>
    <string>setenv</string>
    <string>MAVEN_OPTS</string>
    <string>-XX:PermSize=500m -XX:MaxPermSize=800m -Xmx2g -Djavax.net.ssl.keyStore=/Users/doma/.keystore -Djavax.net.ssl.keyStorePassword=password -Djavax.net.ssl.trustStore=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/security/cacerts -Djavax.net.ssl.trustStorePassword=changeit</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>ServiceIPC</key>
  <false/>
</dict>
</plist>

You'll have to either restart your computer or run the following line to apply the changes:

launchctl load -w /Library/LaunchDaemons/setenv.MAVEN_OPTS.plist

The next candidate is M2_HOME, the file to create is /Library/LaunchDaemons/setenv.M2_HOME.plist :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
  <dict>
  <key>Label</key>
  <string>setenv.BAR</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/launchctl</string>
    <string>setenv</string>
    <string>M2_HOME</string>
    <string>/opt/local/share/java/apache-maven-3.1.1</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>ServiceIPC</key>
  <false/>
</dict>
</plist>

Again, restart or run the following to apply:

launchctl load -w /Library/LaunchDaemons/setenv.M2_HOME.plist

...and here's the proof that you don't have to set the value of the M2_HOME after each Maven project import:

Reference: http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-launchd-plist/


9/18/2014

Building and installing Apache Maven 3.0.5 from sources


cd ~/tools
wget http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.0.5/apache-maven-3.0.5-src.tar.gz
tar xvzf apache-maven-3.0.5-src.tar.gz
cd apache-maven-3.0.5
#for the next line to succeed, you need a binary maven version in the path
mvn clean install -DskipTests
cd ..
tar xvzf apache-maven-3.0.5/apache-maven/target/apache-maven-3.0.5-bin.tar.gz

9/09/2014

Installing Nexus OSS from sources

After all it's not that tricky. Build fails with Maven 3.0.x, make sure to use a later version, 3.2.3 seems to be working fine. You'll also need the http.ssl hacks.

Pre-requisities

You'll need git. Using Ubuntu/Debian, a
sudo apt-get install git
will do, or on FreeBSD you can use
sudo portmaster devel/git
And now the fun part. On FreeBSD, the lines involving maven can be omitted if a version is already installed via ports via a "sudo portmaster devel/maven3"
cd ~/tools
wget http://apache.cu.be/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.tar.gz
tar xvzf apache-maven-3.2.3-bin.tar.gz
ln -s ~/tools/apache-maven-3.2.3 ~/tools/maven
export PATH=~/tools/maven/bin:$PATH

export MAVEN_OPTS="-XX:PermSize=1500m -XX:MaxPermSize=1800m -Xmx4g"
cd ~/dev
git clone https://github.com/sonatype/nexus-oss.git
cd nexus-oss

# if you don't need https just uncomment below 
cat >> etc/org.sonatype.nexus.cfg << FILE_SEPARATOR
application-port-ssl=8443
FILE_SEPARATOR

mvn -Dskip-testsuite -DskipTests -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
sudo unzip -d /opt assemblies/nexus-base-template/target/nexus-base-template-*.zip
sudo ln -s /opt/nexus-base-template-* /opt/nexus

Autostart on Ubuntu/Debian

As of today, the wrapper service we can use in Karaf to autostart things does not work. As a workaround to autostart, create a /etc/init.d/nexus file:
#!/bin/bash

NEXUS_HOME=/opt/nexus

case "$1" in
  start)
    log_begin_msg "Starting Nexus OSS..."
        $NEXUS_HOME/bin/start
    log_end_msg 0
    ;;
  stop)
    log_begin_msg "Shutting down Nexus OSS..."
        $NEXUS_HOME/bin/stop
    log_end_msg 0
    ;;
  *)
  ;;
esac
...and execute this statement:
sudo update-rc.d nexus defaults 98 02

Autostart on FreeBSD

Start by putting the following script to /etc/rc.d/nexus:
#!/bin/sh

. /etc/rc.subr

name="nexus"
start_cmd="\${name}_start"
stop_cmd="\${name}_stop"
export NEXUS_HOME=/opt/nexus
export JAVA_HOME=/usr/local/openjdk7

nexus_start() {
        \$NEXUS_HOME/bin/start
}

nexus_stop() {
        \$NEXUS_HOME/bin/stop
}

load_rc_config \${name}
run_rc_command "\$1"
...and adapt appropriately to your system of course. You'll need to make it executable:
chmod +x /etc/rc.d/nexus

To activate it, you need to add the following to your /etc/rc.conf:
nexus_enable="YES"

If you need this often

If you need to re-do the same thing from time to time in different environments for different projects, you prefer to simplify things. So here is the single-copy-paste-prepared version; the same as above, this time without the explanation, automated.

cat > /etc/rc.d/nexus << FILE_SEPARATOR
#!/bin/sh

. /etc/rc.subr

name="nexus"
start_cmd="\${name}_start"
stop_cmd="\${name}_stop"
export NEXUS_HOME=/opt/nexus
export JAVA_HOME=/usr/local/openjdk7

nexus_start() {
        \$NEXUS_HOME/bin/start
}

nexus_stop() {
        \$NEXUS_HOME/bin/stop
}

load_rc_config \${name}
run_rc_command "\$1"
FILE_SEPARATOR
chmod +x /etc/rc.d/nexus

cat >> /etc/rc.conf << FILE_SEPARATOR
nexus_enable="YES"
FILE_SEPARATOR

service nexus start

Usage

To deploy to the locally installed Nexus, you can
  • - change your pom.xmls to refer to this local nexus for deployment
  • - change your settings.xml use the local nexus for deployment
  • <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              http://maven.apache.org/xsd/settings-1.0.0.xsd">
    
       <mirrors>
            <mirror>
                <id>nexus</id>
                <name>nexus</name>
                <mirrorOf>external:*</mirrorOf>
                <url>http://127.0.0.1:8081/content/groups/public/</url>
            </mirror>
        </mirrors>
    
        <servers>
            <server>
                <id>jnc</id>
                <username>tomcat</username>
                <privateKey>${user.home}/.ssh/id_rsa</privateKey>
            </server>
            <server>
                <id>nexus</id>
                <username>admin</username>
                <password>{Oen5wNM4lygHMZ9vf+6T5qmsePRcQbWtrc2AWkTrpKg=}</password>
            </server>
            <server>
                <id>snapshots</id>
                <username>admin</username>
                <password>{Oen5wNM4lygHMZ9vf+6T5qmsePRcQbWtrc2AWkTrpKg=}</password>
            </server>
            <server>
                <id>releases</id>
                <username>admin</username>
                <password>{Oen5wNM4lygHMZ9vf+6T5qmsePRcQbWtrc2AWkTrpKg=}</password>
            </server>
        </servers>
    
        <profiles>
            <profile>
                <id>local</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
        <nexus.url>http://127.0.0.1:8081</nexus.url>
                    <repos.public.url>${nexus.url}/content/groups/public</repos.public.url>
                    <repos.release.url>${nexus.url}/content/repositories/releases</repos.release.url>
                    <repos.snapshot.url>${nexus.url}/content/repositories/snapshots</repos.snapshot.url>
                </properties>
                <repositories>
                    <repository>
                        <id>nexus</id>
                        <name>public</name>
                        <url>${repos.public.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </repository>
                    <repository>
                        <id>snapshots</id>
                        <name>snapshots</name>
                        <url>${repos.snapshot.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                        <releases>
                            <enabled>false</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </repository>
                    <repository>
                        <id>releases</id>
                        <name>releases</name>
                        <url>${repos.release.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>false</enabled>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </repository>
                </repositories>
    
                <pluginRepositories>
                    <pluginRepository>
                        <id>nexus</id>
                        <name>public</name>
                        <url>${repos.public.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </pluginRepository>
                    <pluginRepository>
                        <id>snapshots</id>
                        <name>snapshots</name>
                        <url>${repos.snapshot.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                        <releases>
                            <enabled>false</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </pluginRepository>
                    <pluginRepository>
                        <id>releases</id>
                        <name>releases</name>
                        <url>${repos.release.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>false</enabled>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </pluginRepository>
                </pluginRepositories>
            </profile>
        </profiles>
    </settings>
    
    
    ...and this goes to settings-security.xml, using the default password for authentication. If following this guide, on your local, firewalled server the default username/password combination might do. Otherwise change your password in nexus and update your settings.xml and settings-security.xml appropriately as described here.
    <settingsSecurity>
      <master>{KFp2s9kTyrcHsy+BT4dooaLri1eMcy+32raBPgydYvw=}</master>
    </settingsSecurity>
    
  • - use the following construct which overrides your default deployment directory:
    mvn clean deploy -DaltDeploymentRepository=nexus::default::http://127.0.0.1:8081/content/repositories/snapshots
    

Possible errors

Using Maven versions earlier than 3.2.3 may yield to the following error:
Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

9/05/2014

Building and installing Apache Maven from sources (no sudo needed)

Maven 3.0.3

Maven 3.0.4 is known for it's incompatibilities connecting to self signed certificates, which can be solved by a small patch. If you don't depend on this version, it's even easier not to use the broken version at all. Here's how to build from sources:
mkdir -p ~/tools
cd ~/tools
wget http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.0.3/apache-maven-3.0.3-src.tar.gz
tar xvzf apache-maven-3.0.3-src.tar.gz
cd apache-maven-3.0.3
#for the next line to succeed, you need a binary maven version in the path
mvn clean install -DskipTests
cd ..
tar xvzf apache-maven-3.0.3/apache-maven/target/apache-maven-3.0.3-bin.tar.gz

Maven 3.2.3

mkdir -p ~/tools
cd ~/tools
wget http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.2.2/apache-maven-3.2.2-src.tar.gz
tar xvzf apache-maven-3.2.2-src.tar.gz
cd apache-maven-3.2.2
#for the next line to succeed, you need a binary maven version in the path
mvn clean install -DskipTests
cd ..
tar xvzf apache-maven-3.2.2/apache-maven/target/apache-maven-3.2.2-bin.tar.gz

11/27/2009

AppFuse Struts2 Tutorial with Eclipse / SpringSource Tools Suite

Excerpt from AppFuse's website:

AppFuse is an open source project and application that uses open source tools built on the Java platform to help you develop Web applications quickly and efficiently. It was originally developed to eliminate the ramp-up time found when building new web applications for customers. At its core, AppFuse is a project skeleton, similar to the one that's created by your IDE when you click through a wizard to create a new web project.

AppFuse builds on Maven to accomplish its goal. AppFuse + Maven can be used command line, creating our application with just a single line; but here we will be using Eclipse.

In this tutorial we'll go through the creation of a simple Struts2 web-application, which we'll extend later. We'll use SpringSource Tools Suite 2.2.1 (STS) which is a free tool based on Eclipse 3.5.1 with a pre-configured set of plugins useful for web-development. STS has the Maven2 plugin which we'll use to configure AppFuse for us.

So, grab a copy of SpringSource Tools from http://www.springsource.com/products/sts. After the installation, select File->New->Project... Type maven, and click Next:



Leave "Use default Workspace location" checked and click Next.



Enter struts in the filter, and select struts2-archetype-starter. This is a so called "Maven Archetype", a ready-to-be-used project template built around the Project Object Model (POM), which will create a starter application for Apache Struts 2.0. Click Next.



Now enter the following info:
  • Group Id: org.techmissive
  • Artifact Id: testdrive-struts
  • Version: 1.0.0
  • Package: org.techmissive.testdrive.struts
And click "Finish":



We have created our template project. Now Eclipse (I mean STS of course) will start downloading all our dependencies, and build the project for us. On OSX, we can see directly the Maven-log; on Windows we have to open the Console view (Alt+Shift+Q then C), and click the down-arrow next to the Open Console button on its toolbar (the window-like button left of the green lamp) and select Maven console to see what Maven is doing.



Included with this template is Jetty, a lightweight servlet container, which can be used to test our application locally without installing a full blown J2EE Server. Let's see how we can start it from STS.

Select Run -> Run Configurations... from the Menu, here we'll specify what happens when we start our application. Select 'Maven Build' from the list, and click on the New icon on the top of the window to create a new configuration.



To set the Base directory, click on Browse Workspace. Now click on testdrive-struts and OK. This sets ${workspace_loc:/testdrive-struts} in the Base directory field, which is a relative resolution from our workspace location.

To run Jetty, we have to run a given goal, so enter jetty:run-war in the goals field.

Replace the New_configuration default name with something more meaningful, like Run Jetty.



Click Apply to save, and Run to start the configuration we just created.

Now Eclipse is working again, starts to download all kind of stuff. But in the end proudly confirms the successful starting of Jetty:



Let's test if it works. Jetty is listening by default on the port 8080, so let's start a browser and check what is there. Start Safari and enter http://localhost:8080/testdrive-struts in the address field:



We have a running Web-application and we didn't have to write a single line of code. This is the main purpose of AppFuse: to provide us a skeleton application we can start working on without hours of hunting for the libraries, configuring them, etc. I just wish all the profiles would work the first time like this one...