Code Monkey home page Code Monkey logo

heroku-buildpack-java's Introduction

Heroku buildpack for Java CI

java

This is the official Heroku buildpack for Java apps. It uses Maven 3.9.4 to build your application and OpenJDK 8 to run it. However, the JDK version can be configured as described below.

How it works

The buildpack will detect your app as Java if it has a pom.xml file, or one of the other POM formats supports by the Maven Polyglot plugin, in its root directory. It will use Maven to execute the build defined by your pom.xml and download your dependencies. The .m2 folder (local maven repository) will be cached between builds for faster dependency resolution. However neither the mvn executable nor the .m2 folder will be available in your slug at runtime.

Documentation

For more information about using Java and buildpacks on Heroku, see these Dev Center articles:

Examples

Configuration

Choose a JDK

Create a system.properties file in the root of your project directory and set java.runtime.version=1.8.

Example:

$ ls
Procfile pom.xml src

$ echo "java.runtime.version=1.8" > system.properties

$ git add system.properties && git commit -m "Java 8"

$ git push heroku main
...
-----> Java app detected
-----> Installing OpenJDK 1.8... done
-----> Installing Maven 3.3.3... done
...

Choose a Maven Version

You can define a specific version of Maven for Heroku to use by adding the Maven Wrapper to your project. When this buildpack detects the presence of a mvnw script and a .mvn directory, it will run the Maven Wrapper instead of the default mvn command.

If you need to override this, the system.properties file also allows for a maven.version entry (regardless of whether you specify a java.runtime.version entry). For example:

java.runtime.version=1.8
maven.version=3.3.9

Customize Maven

There are three config variables that can be used to customize the Maven execution:

  • MAVEN_CUSTOM_GOALS: set to clean dependency:list install by default
  • MAVEN_CUSTOM_OPTS: set to -DskipTests by default
  • MAVEN_JAVA_OPTS: set to -Xmx1024m by default

These variables can be set like this:

$ heroku config:set MAVEN_CUSTOM_GOALS="clean package"
$ heroku config:set MAVEN_CUSTOM_OPTS="--update-snapshots -DskipTests=true"
$ heroku config:set MAVEN_JAVA_OPTS="-Xss2g"

Other options are available for defining a custom settings.xml file.

Development

To make changes to this buildpack, fork it on Github. Push up changes to your fork, then create a new Heroku app to test it, or configure an existing app to use your buildpack:

# Create a new Heroku app that uses your buildpack
heroku create --buildpack <your-github-url>

# Configure an existing Heroku app to use your buildpack
heroku buildpacks:set <your-github-url>

# You can also use a git branch!
heroku buildpacks:set <your-github-url>#your-branch

For example if you want to have Maven available to use at runtime in your application, you can copy it from the cache directory to the build directory by adding the following lines to the compile script:

for DIR in ".m2" ".maven" ; do
  cp -r $CACHE_DIR/$DIR $BUILD_DIR/$DIR
done

This will copy the local Maven repo and Maven binaries into your slug.

Commit and push the changes to your buildpack to your GitHub fork, then push your sample app to Heroku to test. Once the push succeeds you should be able to run:

$ heroku run bash

and then:

$ ls -al

and you'll see the .m2 and .maven directories are now present in your slug.

License

Licensed under the MIT License. See LICENSE file.

heroku-buildpack-java's People

Contributors

androbin avatar catsby avatar craigkerstiens avatar dependabot[bot] avatar dzuelke avatar ecopoesis avatar edmorley avatar eiryu avatar huntergerlach avatar jabrown85 avatar jkutner avatar jsimone avatar lillianzhang331 avatar malax avatar mattgraham avatar mmcgrana avatar nolith avatar ryanbrainard avatar schneems avatar sclasen avatar shreyasdube avatar snyk-bot avatar ticktock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heroku-buildpack-java's Issues

JFX RT

I got compilation problem when doing deployment on Heroku for my java class using class from jfxrt.jar.

May I know any solution for using OpenJDK?

Support Java 7

Java 7 has had a few releases and it would be very nice if Heroku would support it with the official Java build pack.

Ambiguous Redirect for BUILDPACK_LOG_FILE

When attempting builds with buildstep and herokuish, the error message

/dev/fd/63: line 124: ${BUILDPACK_LOG_FILE} : ambiguous redirect

is returned.

By setting the BUILDPACK_LOG_FILE variable in the shell session, the build completes successfully.

The NodeJS buildpack which also uses the buildpack-stdlib sets the variable in bin/complile:

https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/compile#L30

Can the variable also be set bin/compile in this java buildpack?

buildpack-stdlib reference:
https://github.com/heroku/buildpack-stdlib/blob/master/stdlib.sh#L86

Test Failure: settings.xml md5 mismatch

TEST SUITE: compile_test.sh
testCompileWithVendorFlagGetsSystemProperties
ASSERT:expected:<a5fa7b9982fc64939c0e215f935a850a /tmp/shunit.CpBISg/tmp/output.aqbq/cache/.m2/settings.xml> but was:<5df822de6968caeaa726d554e7021b89 /tmp/shunit.CpBISg/tmp/output.aqbq/cache/.m2/settings.xml>
testExistingAppDoesNotDownloadJDK
testNewAppGetsSystemPropertiesFile
testCompile
ASSERT:expected:<a5fa7b9982fc64939c0e215f935a850a /tmp/shunit.CpBISg/tmp/output.Yxju/cache/.m2/settings.xml> but was:<5df822de6968caeaa726d554e7021b89 /tmp/shunit.CpBISg/tmp/output.Yxju/cache/.m2/settings.xml>
testCompilationFailure
testDownloadCaching
testNewAppsRemoveM2Cache
testNonLegacyExistingAppsRemoveCache
testLegacyAppsKeepM2Cache

Could not detect buildpack / Error compiling buildpack

Reproduce:

  • Create app on Heroku with CI
  • Add the heroku/java buildpack:

  • The buildpack shows correctly under the app:

  • However, running CI fails on the Java buildpack:

Anything I'm missing to get this working?

PS I'm adding the java buildpack to run selenium tests for my node/react app in case that is useful info

New Buildpack Breaks Rhino JavaScript Capabilities in OpenJDK 1.7

using any version of the buildpack later than the commit b7e7b29 breaks the use of Rhino JavaScript engine when using JDK 1.7.

As we tested in Heroku, we found out the file 'rhino.jar' is missing in the dir /app/.jdk/jre/lib/ when using any version of the buildpack after commit b7e7b29. It does exist when using a version of which this is the latest commit.

No plugin found for prefix 'dependency' in the current project and in the plugin groups

I'm seeing this error when running the buildpack:

2016-04-19T14:25:47.89-0500 [STG/0]      OUT        [ERROR] No plugin found for prefix 'dependency' in the current project and in the plugin groups [org.apache.maven.plug
ins, org.codehaus.mojo] available from the repositories [local (/tmp/cache/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]

Please let me know if there is another forum more appropriate for these types of issues.

Cloud Foundry uploading everything?

I have this defined in my manifest.yml:

When I run:

cf push my-group-my-project-test

In my root directory, where pom.xml resides, I expected the application files to be uploaded, and the dependencies to be pulled down by maven on the platform.

What is happening is that everything on local, including dependencies, is being uploaded (to the tune of 56 megs). Am I missing the purpose of this buildpack? I thought the point was to download and cache the dependencies on the platform to improve performance.

pom.xml not in root

In my project, i do not have the pom.xml in my root, when i do a push, heroku says that my app was not detected. How can i specify where my pom.xml is ?

My pom.xml is in:
./app-name-serve/pom.xml

Build Pack Error when deploying dokku

Hello,

I'm over 2 days trying to figure out what can be happening on my environment
When trying to rebuild an existing aplication I'm getting the following error:
/tmp/buildpacks/heroku-buildpack-java/bin/compile: line 43: detect_java_version: command not

Below is the command I'm executing...

dokku rebuild:force myapp

Cloning into '/tmp/tmp.VjWEqvvaUa'...
done.
HEAD is now at 1924c62... Merge branch 'backlog#1234' into master_homolog
-----> Building myapp using buildstep...
-----> Installing ENV in build environment ...
-----> Using u1000 to run an application
-----> Java app detected
/tmp/buildpacks/heroku-buildpack-java/bin/compile: line 43: detect_java_version: command not found

Any help is more than welcome.

Add -Djetty.skip=true to mvn command

A common practice is to bind jetty:run to the pre-integration-test phase; however, this phase/goal does not respect the skipTests=true flag, so Jetty attempts to start itself during a build on Heroku. Jetty has a custom jetty.skip flag in 6.1.26, so developers could add the following property to POMs to link this to the skipTests=true flag, like this:

<properties>
  <jetty.skip>${skipTests}</jetty.skip>
</properties>

However, this would have to be done on every POM, and I do not see any reason we would ever want Jetty to be started during a build, so this is a proposal to add -Djetty.skip=true to the mvn command for the Java buildpack.

buildpack test script does not use run_mvn helper

The test script uses the mvn directly ignoring all the settings that would have been set when using the run_mvn function. Especially the custom settings.xml is ignored which causes builds to compile, but fail during tests if there is still a dependency to download.

A workaround for now is to set the test script in app.json:

  "scripts": {
      "test": "mvn -s settings.xml test"
  },

but maybe it would be nice to make the buildpack consistently using the settings.xml.

Print JDK Version For All Versions

If no version is detected, the OpenJDK version is not printed.

e.g.

git push heroku master
...
-----> Heroku receiving push
-----> Fetching custom buildpack... cloning with git...done
-----> Java app detected
-----> Installing OpenJDK ...done
-----> Installing Maven 3.0.3... done

Removing `system.properties` from an app should revert to the default java version

If I set my java version using system.properties and later remove the file, the java version is still detected using the same version as set in the original system.properties. e.g. If I set java.runtime.version=1.7, then delete system.properties, the next time I push, my app will still be using JDK 1.7.

Example:

~/dev/bare[master] ★ heroku create
Creating aqueous-anchorage-7595... done, stack is cedar
http://aqueous-anchorage-7595.herokuapp.com/ | [email protected]:aqueous-anchorage-7595.git
Git remote heroku added
~/dev/bare[master] ★ git push heroku master 
Counting objects: 33, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (33/33), 3.64 KiB, done.
Total 33 (delta 8), reused 33 (delta 8)
-----> Java app detected
-----> Installing OpenJDK 1.6...done
...
~/dev/bare[master] ★ echo "java.runtime.version=1.7" > system.properties
~/dev/bare[master±] ★ git add .
~/dev/bare[master±] ★ git commit -m "java 7"
[master 8aa1eb9] java 7
 1 file changed, 1 insertion(+)
 create mode 100644 system.properties
~/dev/bare[master] ★ git push heroku master 
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 299 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
-----> Java app detected
-----> Installing OpenJDK 1.7...done
...
~/dev/bare[master] ★ git rm system.properties
rm 'system.properties'
~/dev/bare[master±] ★ git commit -m "no java 7"
[master 810d13a] no java 7
 1 file changed, 1 deletion(-)
 delete mode 100644 system.properties
~/dev/bare[master] ★ git push heroku master 
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 219 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
-----> Java app detected
-----> Installing OpenJDK 1.7...done

We have a couple options. In both cases, we'll ignore any system.properties found in the $CACHE_DIR and default to JDK 1.6. We can:

  • Fall back to the platform JDK, 1.6_20; or
  • Vendor the latest JDK 1.6 into all slugs.

I prefer the latter, but it means we'll start vendoring the JDK into all apps, not just net new. This seems fine since we've been vendoring the JDK into all new apps since September.

Another option, which I'm really not sure is possible, is to inspect the git history to see if the file has been removed. This would be backwards compatible, but I'm not sure what kind of performance problems it might introduce.

Cache dir not automatically created?

We started getting this error after this commit: db89ce6, looks like cache dir was not automatically created when writing the system.properties file to it.

buildpacks/java/bin/compile /var/EUAD4ABKBEIC7F63IDQJVTVF5ATUY6DZYKUQTKT2FUOR3Z76I5WQ/app-71 /var/EUAD4ABKBEIC7F63IDQJVTVF5ATUY6DZYKUQTKT2FUOR3Z76I5WQ/cache-71
-----> Installing JDK 1.8.../tmp/jvm-common/bin/java: line 302: /var/EUAD4ABKBEIC7F63IDQJVTVF5ATUY6DZYKUQTKT2FUOR3Z76I5WQ/cache-71/system.properties: No such file or directory

Implement support for slices

The heroku/maven Cloud Native Buildpack should use the slices feature to put the source code, dependencies, and compiled artifacts into their own layers.

Maven wrapper not used

Hi there,

we have a spring boot application which uses the maven wrapper but the buildpack does not detect the maven wrapper for the test setup. We went through the scripts and it should work but it doesn't

Do you have a suggestion what might go wrong?

Corporate Proxy

Hi,

we want to use the buildpack in our on-premise cloud foundry installation.

Unfortunatly, we are behind a corportate proxy.

Could you list the URL we need to whiltelist to download maven/jdk/zulu-jdk?

Cheers

Install Java without Maven

Is it possible to just install Java without building apps with Maven? My use case is just to create an app that has both Node and Java environments (with multi-buildpack) to run Closure Compiler, so it does not actually need to build Java apps.

Maven downloaded over HTTP

The buildpack downloads compiled maven archives from S3 (plus maven sources when building) over HTTP and then doesn't perform any additional (hash, signature) validation:

mavenUrl="http://lang-jvm.s3.amazonaws.com/maven-${mavenVersion}.tar.gz"

for MAVEN in $(cat ${VENDOR_DIR}/sources.txt)
do
echo " $MAVEN..."
curl -O --silent --location $MAVEN
done

https://github.com/heroku/heroku-buildpack-java/blob/210afcc00b12a387ae55055d69a1cd16ec7eff05/vendor/maven/sources.txt

Both the S3 lang-jvm bucket and apache.org support HTTPS, so a s/http:/https:/ should work fine:

$ curl -IsSf https://lang-jvm.s3.amazonaws.com/maven-3.3.9.tar.gz | head -n 1
HTTP/1.1 200 OK

$ curl -IsSf http://apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz | head -n 1
HTTP/1.1 200 OK

accessing file in WEB-INF folder after deploying WAR

Hi ,
I'm using a file in my WEB-INF folder , and i can't access it as
"serveletcon.getRealPath("/") " returns null , although i tried the same WAR file on a tomcat server on linux in other site and everything went right.

to be more descriptive in the problem , I use this code in my servlet :
System.out.println("servlet / : " + serveletcontext.getRealPath("/"));
and by viewing the logs , it produces this :
2014-04-15T17:55:40.418881+00:00 app[web.1]: servlet / : null

so , the function "getRealPath" doesn't return a path , even if i pass a "/" to it .
I opened a ticket in heroku and Damien (the developer who supported the ticket) told me that to be tracked , i should open an issue here on GitHub .

also i have searched and found these , please check :

http://cmhbl0g.blogspot.com/2013/12/heroku-reading-files-from-web-inf.html

http://ananthkannan.blogspot.com/2009/12/servletcontextgetrealpath-returns-null.html

addons in bin/release don't get updated

Not sure if this is an issue, but annoys me a little bit.

If you deploy at first time one app, the addons included in bin/release get installed. If you specify a custom buildpack with different addons, the already ones installed don't change and the new ones specified in bin/release don't appear. After pushing changes noting happens neither.

Just wondering if this is a bug or a normal and expected behavior.

mvn verify

In /bin/test would it be a good idea to call "mvn verify" instead of "mvn test"? If you have integration tests with the maven-failsafe-plugin then they won't run with just the test goal.

Query : how to enable gzip compression?

I added this in the application.properties file of my spring boot app.
server.compression.enabled=true
In the localhost, gzip is working correctly. But in the heroku server, gzip header is missing and file is not being compressed. Any clue on how I can enable gzip for my java app? I am using jar deploy and no Procfile.

Issue using encrypted pw to private repo

Using the custom_settings branch allows for a settings.xml with a plain text pw to a secure repo to be added.

When an encrypted pw is used with a settings-security.xml is used the authentication fails on Heroku after working fine locally.

Query:How to enable gzip compression

This may be a bit lame question. I am using spring MVC REST, Is there a way to enable gzip compression using Heroku build pack for that or is there any way by which I can change the server.xml?

Unmanaged dependency failed to be resolved

I followed the instructions from:

https://devcenter.heroku.com/articles/local-maven-dependencies

When I push my app to Heroku it can not find the added jar in its local repository. This works fine on my local instance.

[ERROR] Failed to execute goal on project api: Could not resolve dependencies for project com.h2lo:api:jar:1.0: Could not find artifact pubnub:pubnub-java:jar:3.4 in project.local (file:/tmp/build_30y04zs5a9clk/repo) -> [Help 1]

Thoughts?

Thanks in advance.

Franz Garsombke

Build pack unable to read environment variables

Hi,

I have changed build pack to read settings.xml from another location. The file has reference to environment variables. I used heroku config:add to set username and password of maven repo. However when it starts to run, I see the script compile is not able to read these env variables.

This is how my settings.xml look
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <servers> <server> <id>archiva</id> <username>${env.MI-REPO-USER}</username> <password>#{env.MI-REPO-PASSWORD}</password> </server> </servers> </settings>

My compile script is changed to use this file hosted and print the credentials.

MAVEN_SETTINGS_URL="http://192.81.131.224/settings.xml" echo -n "-----> Installing settings.xml..." echo $MI_REPO_USER echo $MI_REPO_PASSWORD

When I do push on heroku I get empty values for MI_REPO_USER and MI_REPO_PASSWORD

Any help much appreciated

Nandish

Add a way to include settings.xml

Mostly seeing this for connecting to private repos. Either offering this or some other solution to the problem is of growing importance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.