How fix a duplicate src folder when build a java project in aws codebuild?

0

SOLVED

Hello,

I am implementing a lambda function with the tool of continuous integrations of aws . CodeSource , CodeBuild CodePipeLine.

After set up all, when i test the lambda the result is

{
  "errorMessage": "Class not found: com.ad.client.App",
  "errorType": "java.lang.ClassNotFoundException"
}
START RequestId: e8e8db05-5631-4c98-bb7e-6b388ff61af5 Version: $LATEST
Class not found: com.ad.client.App: java.lang.ClassNotFoundException
java.lang.ClassNotFoundException: com.ad.client.App
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)

END RequestId: e8e8db05-5631-4c98-bb7e-6b388ff61af5
REPORT RequestId: e8e8db05-5631-4c98-bb7e-6b388ff61af5	Duration: 110.17 ms	Billed Duration: 200 ms 	Memory Size: 128 MB	Max Memory Used: 68 MB	

All stage of Pipeline are succeeded(Source , Build , Deploy)

If a load the jar directly in the lambda console the result is the correct
I review the log of the build and found this:

[Container] 2019/06/13 13:09:38 Running command echo THE PATH WORK IS !!! 
THE PATH WORK IS !!! 
 
[Container] 2019/06/13 13:09:38 Running command pwd 
/codebuild/output/src748698927/src 
 
[Container] 2019/06/13 13:09:38 Running command echo The list of file is !! 
The list of file is !! 
 
[Container] 2019/06/13 13:09:38 Running command ls 
Readme.md 
buildspec.yml 
dependency-reduced-pom.xml 
ftc-client.iml 
outputtemplate.yaml 
pom.xml 
src 
target 
template.yaml 
 
[Container] 2019/06/13 13:09:38 Running command echo CODE BUILD SRC DIRECTORY 
CODE BUILD SRC DIRECTORY 
 
[Container] 2019/06/13 13:09:38 Running command echo $CODEBUILD_SRC_DIR 
/codebuild/output/src748698927/src 

INFO] skip non existing resourceDirectory /codebuild/output/src748698927/src/src/main/resources 

In some portion of code show me that the path src is duplicated, i don't know if it has something to related with the problem

My config files are:

template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Ftc-client
Resources:
  FtcClientFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: com.ad.client.App::handleRequest
      Runtime: java8
      CodeUri: ./
      Events:
        MyFtcClientApi:
          Type: Api
          Properties:
            Path: /client
            Method: GET

buildspec.yml

version: 0.2

phases:
  install:
    runtime-versions:
      java: openjdk8
  build:
    commands:
      - echo Build started on `date`
      - mvn test
      - export BUCKET=my-bucket-for-test
      - aws cloudformation package --template-file template.yaml --s3-bucket $BUCKET --output-template-file outputtemplate.yaml
    finally:
      - echo THE PATH WORK IS !!!
      - pwd
      - echo The list of file is !!
      - ls
      - echo CODE BUILD SRC DIRECTORY
      - echo $CODEBUILD_SRC_DIR
  post_build:
    commands:
      - echo Build completed on `date`
      - mvn package
artifacts:
  files:
    - target/ftc-client-1.0-SNAPSHOT.jar
    - template.yaml
    - outputtemplate.yaml
  discard-paths: yes

appspec.yml

version: 0.0
os: linux
files:
  - source: target/ftc-client-1.0-SNAPSHOT.jar
    destination: /tmp
The source code structure is :
/fclient/src/main/java/com/ad/App.java
/tclient/buildspec.yml
/fclient/pom.xml
/fclient/template.yaml

thank for everyone whom can give me a cue
...

Answer:
The problem wasn't the duplicate folder,
This is the solution , It is necessary to unzip the jar in the root of my source .

version: 0.2
phases:
  install:
    runtime-versions:
      java: openjdk8
  pre_build:
    commands:
      - echo Test started on `date`
      - mvn clean compile test
  build:
    commands:
      - echo Build started on `date`
      - export BUCKET=my-bucket-for-test
      - mvn package shade:shade
      - mv target/ftc-client-1.0-SNAPSHOT.jar
      - unzip ftc-client-1.0-SNAPSHOT.jar
      - rm -rf target tst src buildspec.yml pom.xml ftc-client-1.0-SNAPSHOT.jar
      - aws cloudformation package --template-file template.yaml --s3-bucket $BUCKET --output-template-file outputtemplate.yaml
  post_build:
    commands:
      - echo Build completed on `date` !!!
artifacts:
  files:
    - tarjet/ftc-client-1.0-SNAPSHOT.jar
    - template.yaml
    - outputtemplate.yaml

Edited by: alexdiazco on Jun 13, 2019 3:09 PM
Answer

gefragt vor 5 Jahren354 Aufrufe
1 Antwort
0

Solved

beantwortet vor 5 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen