Deploying Java web application to Amazon Elastic B

2019-03-30 12:56发布

问题:

My team is developing a Java web application which is to be deployed in Amazon Elastic Beanstalk. The development environment is Eclipse and Subversion. They were able to deploy it using the Eclipse plugin, but to automate the deployment I'm experimenting with the CLI tools provided by Amazon.

Basically, I followed the steps detailed in the Amazon Blog post after converting the subversion repository into a git repository. I followed the steps explained in this SO answer

After following the above steps, I issued the command git aws.push, which is successfully completed. But while running the application, there are errors and . So I downloaded the war file from the Beanstalk environment and found that the folder structure is messed up and the source files are not compiled to class files. It appears like the source files are uploaded as such.

Do I need to build the application(using ant) prior to using aws.push? Or am I missing something?

回答1:

It seems now I have the answer for my question.

aws.push is not only for PHP applications, instead it can also be used for deploying Java and PHP applications. I have successfully used along with Apache Ant and the setup works fine in our UAT environment.

I developed a shell script which does the following:

  1. Check out the source code from subversion repository
  2. Build and created WAR file using Apache Ant
  3. Explode the WAR file to a git repository (initialised using Amazon EB tools)
  4. Add the exploded files to the git repo and commit the changes.
  5. Use aws.push to deploy the war file to EB.

(I don't have access to the shell script right now, so I may not be able to provide the detailed commands)

Here is the Shell Script in the basic form

source_dir="/home/libregeek/myapp"
workingcopy="$source_dir/trunk"
gitrepo="$source_dir/gitrepo"
cd $workingcopy
svn update
ant createwar
cd $gitrepo
unzip -o $workingcopy/build/myapp.war
git add *
git commit -m "Deployed new version"
git aws.push

There is a known issue with this script related to stale class files. To get away with it you may have to clean up the git repo.

Here is the ant target:

<target name="createwar" depends="build" description="Create WAR file for deployment">
<war destfile="${alternate.path}/${name}.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</war>
</target>


回答2:

It you're using Maven and Beanstalker, the equivalent functionality of git aws.push could be resumed to a single command, regardless if you're using git or not.

$ mvn package beanstalk:fast-deploy

but make sure your pom is ready



回答3:

I had the same problem - it appears the git method is only designed to work with PHP apps.

I'm currently looking for some other Java-based tool, as I don't use Eclipse, and the AWS console is a clunky way of managing releases (and the uploads are very slow).