Below is what I tried.
The below is my build.gradle
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* user guide available at https://docs.gradle.org/3.4/userguide/java_library_plugin.html
*/
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'
repositories {
mavenLocal()
mavenCentral()
}
sourceSets {
main {
resources.srcDirs = ["src"]
java {
srcDir 'src'
}
}
}
task stage {
dependsOn build
}
stage.mustRunAfter(clean)
dependencies {
compile fileTree(dir: './webapp/WEB-INF/lib', include: ['*.jar'])
compile 'org.springframework:spring-webmvc:4.2.5.RELEASE'
compile 'org.apache.poi:poi:3.14'
compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'org.apache.logging.log4j:log4j-api:2.5'
compile 'org.apache.logging.log4j:log4j-core:2.5'
compile group: 'javax.validation', name: 'validation-api', version: '1.1.0.Final'
compile group: 'org.json', name: 'json', version: '20141113'
compile group: 'mysql', name:'mysql-connector-java', version:'5.1.36'
compile group: 'org.mybatis',name:'mybatis-spring',version:'1.2.3'
compile group: 'org.mybatis',name:'mybatis',version:'3.3.0'
compile group: 'org.springframework', name:'spring-orm', version:'3.1.2.RELEASE'
compile group: 'org.springframework', name:'spring-jdbc', version:'3.1.2.RELEASE'
compile group: 'org.springframework', name:'spring-webmvc', version:'3.1.2.RELEASE'
compile group: 'commons-dbcp', name:'commons-dbcp', version:'1.2.2'
compile group: 'org.activiti', name: 'activiti-engine', version: '5.18.0'
compile group: 'javax.mail', name:'mail', version:'1.4.3'
compile group: 'commons-fileupload', name:'commons-fileupload', version:'1.3.2'
compile group: 'commons-io', name:'commons-io', version:'1.3.2'
compile group: 'org.apache.axis', name:'axis', version:'1.4'
compile group: 'commons-discovery', name: 'commons-discovery', version: '0.2'
compile group: 'commons-logging', name: 'commons-logging', version: '1.1.3'
compile group: 'javax.xml', name: 'jaxrpc-api', version: '1.1'
compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3'
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
compile group: 'org.twitter4j', name: 'twitter4j', version: '4.0.4'
compile group: 'org.twitter4j', name: 'twitter4j-stream', version: '3.0.5'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
testCompile 'junit:junit:3.8.1'
}
Procfile
web: build/install/twitter-api9/bin/TwitterApi
When I call my apis from postman I get below errors.
Error log:
2017-04-10T19:11:21.820853+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-10T19:11:26.250394+00:00 heroku[web.1]: Starting process with command `build/install/twitter-api9/bin/TwitterApi`
2017-04-10T19:11:28.283776+00:00 heroku[web.1]: Process exited with status 127
2017-04-10T19:11:28.198888+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2017-04-10T19:11:28.199032+00:00 app[web.1]: bash: build/install/twitter-api9/bin/TwitterApi: No such file or directory
2017-04-10T19:11:28.324886+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T19:11:50.592336+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/main/twitter_data" host=twitter-api9.herokuapp.com request_id=69ce91fa-9677-4b51-9190-dc40bf0f1648 fwd="49.205.228.96" dyno= connect= service= status=503 bytes= protocol=http
I think there is something wrong in procfile as my build is successful but the only problem is just when I try to access my application/api. The application is a spring mvc application which runs fine with war deployed in local tomcat.
EDIT:
Changed my Procfile to below where my war resides
web: sh build/libs
Now the error is:
Though the process exits with status 0 which I guess means everything is fine. But still the app crashes:
2017-04-11T14:37:32.333327+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-11T14:37:37.394992+00:00 heroku[web.1]: Starting process with command sh build/libs
2017-04-11T14:37:39.356372+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2017-04-11T14:37:39.441553+00:00 heroku[web.1]: Process exited with status 0
2017-04-11T14:37:39.458917+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-11T15:17:01.974207+00:00 heroku[run.7895]: Awaiting client
2017-04-11T15:17:02.034572+00:00 heroku[run.7895]: Starting process with command bash
2017-04-11T15:17:02.290336+00:00 heroku[run.7895]: State changed from starting to up
2017-04-11T14:38:47.445653+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/main/twitter_data" host=twitter-api9.herokuapp.com request_id=1673e258-3fc2-4630-ac22-4869b8e68b13 fwd="49.205.228.96" dyno= connect= service= status=503 bytes= protocol=https
Step by step on how to address this issue:
First check where the .war file is deployed which can be done as follows:
run $ heroku run bash -a twitter-api9 from cli.
Now that terminal is open, check with ls of the directories present. I am sure build will be one of them if not just grep for .war file.
Once you know the war location change your Procfile to below (for me the war was residing in build/libs/ may be different for others):
web: java $JAVA_OPTS -DTG_ENV=prod -jar webapp-runner.jar --port $PORT build/libs/*.war
The above will redirect the requests made to these location and since this is a web application you would need a webapp-runner.jar /or jetty-runner or equivalent to run the war which is not needed if its a jar.
Now the application is running and ready to take requests. But note the above works if the build is successful and webapp-runner.jar is in root dir else mention the full path of the jar.
Related
I am having a weird error, for which I found a lot of hits in google but most about android studio or library imports and I don't use android studio nor am I trying to build any app/library so I'll try and ask here and see if I understand the background of it.
I have a project in which I have this plugin:
https://gitlab.com/zkovari/gradle-mermaid-plugin/-/blob/master/examples/single-project/build.gradle
This is a plugin that displays my dependencies as a mermaid graph.
Everything was fine until today I updated some dependencies and created a sub-project to do something else.
I'm trying to generate the graph again and somehow it's failing with this error message.
> Task :generateMermaidDependenciesDiagram FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateMermaidDependenciesDiagram'.
> Configuration with name 'default' not found.
I can see in the source code of the plugin that it automatically sets some configurations
#Override
public void apply(Project project) {
GenerateMermaidDependenciesDiagram generateDependencyDiagramsTask = project.getTasks()
.create(GENERATE_MERMAID_DEPENDENCIES_DIAGRAM_TASK_NAME, GenerateMermaidDependenciesDiagram.class);
generateDependencyDiagramsTask.setConfiguration("default");
generateDependencyDiagramsTask
.setOutput(project.getBuildDir().toPath().resolve("mermaid/dependencies.mmd").toFile());
generateDependencyDiagramsTask.setDiagramGenerator(new MermaidDiagramGenerator());
}
So my question is a bit high level but what is the "default" configuration?
And in my project I don't really have any configuration block I simply have my dependencies:
dependencies {
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: awsVersion, transitive: false
...
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: slf4jVersion
}
My structure looks like this:
project:
-- build.gradle
-- settings.gradle
-- sub-project:
--- build.gradle
I think this stopped working when I added my sub-project but the plugin is applied at the root project level.
I do have a dependency between my sub-project and my root project (one of my sub-project tasks depends on the root project)
I'm trying to understand that this might be very similar but I'm not fully getting it.
Gradle: What Is The Default Configuration and How Do I Change It
I do apply the java plugin on my main project so I expect the configuration.default should exist.
Even if I think I shouldn't do it I tried to re-define a default configuration extending implementation but that did not work
https://docs.gradle.org/current/userguide/declaring_dependencies.html
configurations {
default.extendsFrom implementation
}
build file 'C:\dev\repo\connector-custom\build.gradle': 66: unexpected token: default # line 66, column 5.
default.extendsFrom implementation
I did a quick test and removing my subproject did work so I know the problem is there but no idea why.
It means somehow I must pass to my subproject the default configuration of the main project?
I created a module project using servicebuild template (gradebook-api, gradebook-service), but i have an error after an export package com.liferay.training.gradebook.validator in api below
Bundle-Name: gradebook-api
Bundle-SymbolicName: com.liferay.training.gradebook.api
Bundle-Version: 1.0.0
Export-Package: \
com.liferay.training.gradebook.exception,\
com.liferay.training.gradebook.model,\
com.liferay.training.gradebook.service,\
com.liferay.training.gradebook.service.persistence,\
com.liferay.training.gradebook.validator
-check: EXPORTS
-includeresource: META-INF/service.xml=../gradebook-service/service.xml
i have a problem in the BuildService gradle task that's says :
Some problems were found with the configuration of task
':modules:gradebook:gradebook-api:buildService' (type
'BuildServiceTask').
File 'C:\Liferay\ide-workspace\training-workspace\modules\gradebook\gradebook-api\service.xml'
specified for property 'inputFile' does not exist.
No value has been specified for property 'apiDir'.
And this is a how I add the api module as dependency in service.
dependencies {
compileOnly group: "com.liferay", name: "com.liferay.petra.io"
compileOnly group: "com.liferay", name: "com.liferay.petra.lang"
compileOnly group: "com.liferay", name: "com.liferay.petra.string"
compileOnly group: "com.liferay", name: "com.liferay.portal.aop.api"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
compileOnly group: "org.osgi", name: "org.osgi.annotation.versioning"
compileOnly group: "org.osgi", name: "org.osgi.core"
compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations"
compileOnly group: "javax.portlet", name: "portlet-api"
compileOnly group: "javax.servlet", name: "javax.servlet-api"
compile project(":modules:gradebook:gradebook-api")
}
buildService {
apiDir = "../gradebook-api/src/main/java"
}
group = "com.liferay.training.gradebook"
I am trying to create new Liferay workspace but i got the same error (May be this is an error with Gradle)
Be sure, you run gradle task in the corresponding folder (in gradebook-service folder). I got similar error when I ran it in upper folder which contains api and service folder.
Until recently I have only worked on LR 7.0, but the last day or so have been playing with 7.3. I encountered the exact issue you describe.
The only solution I found was to copy service.xml from gradebook-service into the root of both my gradebook-api and gradebook-web modules and also add the following to the build.gradle files of both the gradebook-api and gradebook-web modules:
buildService {
apiDir = "../gradebook-api/src/main/java"
}
After that service builder ran successfully. There may be a cleaner way around it, but this worked for me.
service.xml should stay in service module only. Here, it look you need few checks.
api module dependency should be compileonly. not in compile
scope.
block order also matters in gradle file. move below block
at the top of the file.
buildService {
apiDir = "../gradebook-api/src/main/java"
}
not sure why you need -check:exports header in bnd file. As, that is not required normally.
In the Gradle task tab, go to your specific module service folder and then build it from there. Don't forget to refresh your gradle by pressing Cntrl+F5.
This Worked for me.
I had the same situation and just added the buildService{...} in build.gradle in the api module.
buildService {
apiDir = "../gradebook-api/src/main/java"
}
After: BUILD SUCCESSFUL
I have a Spring boot application which consists of a scheduled task and a rest controller. The scheduled task connects to Gmail with Javamail to parse certain emails and store them in a MongoDB database and the controller is to query that data in the databse.
I am deploying this application in GKE. When I do, I see the following log messages and my task does not run:
The controller is accessible but as you can see the application starts but then the taskScheduler executor service shuts down. I can't find information in the logs about why this is happening. When I run it locally it works, so I thought it could be related to Docker, but I ran the application from a Docker container (also locally) and it worked as well.
I have another spring boot application that runs some scheduled tasks deployed on GKE and working the only difference is that it does not expose any rest controllers.
Do you have any idea what might be the cause of this issue?
Here's my main class
#EnableScheduling
#EnableMongoRepositories
#SpringBootApplication
public class EmailApplication {
public static void main(String[] args) {
SpringApplication.run(EmailCheckerApplication.class, args);
}
}
Here's my scheduled task. This does not run at all.
#Scheduled(fixedDelay = 60000) // I also tried with #Scheduled(cron = "0 */1 * * * *")
public void checkEmails() {
try {
//connects to Gmail
Message[] messages = getMessages();
//parse emails & store them in DB
closeAll();
} catch (Exception e) {
LOGGER.finest("Error Parsing emails: " + e.getMessage());
}
}
Here's my Dockerfile
FROM adoptopenjdk/openjdk13:jre-13.0.2_8-alpine
COPY build/libs/email-checker-0.0.1.jar /tmp
RUN chmod 744 /tmp/email-checker-0.0.1.jar
CMD ["java", "-jar", "-Dspring.profiles.active=${SPRING_PROFILES_ACTIVE}", "/tmp/email-checker-0.0.1.jar"]
Here's my dependencies in build.gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'javax.mail', name: 'mail', version: '1.4.7'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '2.4.2'
compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: '3.1.3'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb', version: '2.4.2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Edit
Weird, if I run kubectl logs -n service <pod-name> -f
I don't see the log messages of the ExecutorServices shutting down, but I don't see the log messages of the scheduled task either.
Here's the last log messages
I solved the issue. Actually there were two issues, but the main one is that when my application was trying to connect to Gmail, it was throwing an exception saying that Web login was required. So I realized that Spring boot was ignoring LOGGER.finest in my catch block. I was able to spot that first by adding a bunch of LOGGER.info before every single line of code in my scheduled task and then changing LOGGER.finest to LOGGER.info.
So to solve the main issue I followed some suggestions in this SO question and to solve the issue with LOGGER.finest I added the property logging.level.my-package=DEBUG in my application.properties (change my-package to a package in your application you want to set the log level to). If you have different profiles for lower environments and production, you can set it to ERROR in the production profile.
I have two different environments say lower env and production. I have few gradle dependencies which should not get downloaded or used in production. So I want to block those plugins to get downloaded or activated in PROD.
I want the below plugins not to get added in prod, but in development and test environments .
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-sleuth-zipkin-stream
compile group: 'org.springframework.cloud', name: 'spring-cloud-sleuth-zipkin-stream', version: '1.0.0.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-sleuth
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version: '2.1.1.RELEASE'
There are two recommended ways to disable the Daemon persistently for
an environment: Via environment variables: add the flag
-Dorg.gradle.daemon=false to the GRADLE_OPTS environment variable. Via properties file: add org.gradle.daemon=false to the
«GRADLE_USER_HOME»/gradle.properties file.
Hi I want to use a gradle property in my gradle build file like this:
compile group: 'org.hibernate', name: 'hibernate-core', version: '${hibernateVersion}'
and i have in the gradle.properties this entry
hibernateVersion:5.2.6.Final
But each time it gives me error:
Could not create an instance of type org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency_Decorated
Try:
compile "org.hibernate:hibernate-core:$hibernateVersion"