no main manifest attribute, in jar in Intellij Idea, using Gradle - java

Same thing works in my other project, but here I get an error :
no main manifest attribute, in jar
here's my Gradle :
group 'com.vladdrummer.txtadventureserver'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile "com.sparkjava:spark-core:2.7.2"
}
Here's where manifest is :
So, it seems to be in a right place.
The manifest itself :
Manifest-Version: 1.0
Main-Class: TextAdventureServer
and the Artifact:
So, it seems to me that everything is in place, but when I build Artifact and try java -jar txtadventureserver_main.jar - it shows me error:
no main manifest attribute, in txtadventureserver_main.jar
Where did I make a mistake?

Related

Facing issue while running gradle clean build

I am using Gradle 5 as my build tool for my Java application. I am getting below error while running gradle clean build.
Could not set unknown property 'stopPort' for root project '1-SimpleServlet' of type org.gradle.api.Project
PFA error image
Please find build.gradle file
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'jetty'
stopPort = 8081
stopKey = 'stopKey'
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5'
providedCompile 'org.apache.commons:commons-io:1.3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Pleas help me resolve this issue.
The jetty plugin has been deprecated with Gradle 3.0 and eventually been removed in Gradle 4.0 (Release Notes, Github Issue). Since you're using Gradle 5, I suggest to have a look at the official Building Java Web Applications guide which uses the gretty plugin.
Example build.gradle:
plugins {
id 'war'
id 'eclipse'
id 'org.gretty' version '3.0.1'
}
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
testCompile 'junit:junit:4.12'
}

Gradle Heroku Task 'stage'

I have a problem with deploying gradle project to heroku.
Here is my gradle.build file
plugins {
id 'java'
id 'distribution'
}
group 'com.artek.ej_bot'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
flatDir {
dirs 'libs'
}
mavenCentral()
}
dependencies {
compile files(fileTree(dir: 'libs', includes: ['*.jar']))
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
task stage {
dependsOn installDist
}
And I keep getting this error:
It looks like your project does not contain a 'stage' task, which Heroku needs in order to build your app
I run this command heroku config:set GRADLE_TASK="build" in terminal and deploy became successful
here's how I have setup the stage task for my gradle project deployed on Heroku
task stage(type: Copy, dependsOn: ['build', 'clean', 'shadowJar']) {
from 'build/libs/app-0.0.1.jar'
into project.rootDir
rename {
'app.jar'
}
}
stage.mustRunAfter(clean)

How to setup Amazon Polly SDK with Gradle in IntetlliJ

I am trying to setup AWS Polly Java SDK with Gradle in IntelliJ by following this. I have already created a simple Spring Boot application using the spring intializr, so I added the items specified in the tutorial to my build.gradle file. When try to import
import com.amazonaws.services.polly.AmazonPollyClient
IntelliJ fails to resolve name polly.
This is my full build.gradle file
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'io.ai.vivid'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.228'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile 'com.amazonaws:aws-java-sdk-s3'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Also IntelliJ complains that it can't resolve the name manvenBom in my build.gradle. I have already tried SO solutions to this like invalidate cache/restart but could not resolve the issue.
I used your build.gradle file to replicate the issue and was able to import AmazonPollyClient after making the following changes to the dependencies
dependencies {
compile 'com.amazonaws:aws-java-sdk-s3'
compile group: 'com.amazonaws', name: 'aws-java-sdk-polly', version: '1.11.67'
The Gradle version used 4.8

Including javafx.util.Pair as a dependency in gradle

I have a springboot app that I developed using oracle JDK and it uses the javafx.util.pair class. When the jar built is run on a system with OpenJDK it cannot find this class. How can i package this dependency with my jar? I am using gradle. Here is my build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE")
}
}
description = "CF Service Broker using Java / Spring"
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'cf-tile'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-devtools")
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('com.jayway.jsonpath:json-path')
testCompile group: 'junit', name: 'junit', version: '4.12'
}
I don't believe you can import javafx utils via gradle but you can, for platforms that do not include it in their version of OpenJDK, use openjfx.
For example you can install it in ubuntu using:
sudo apt-get install openjfx

NoClassDefFoundError for grizzly HTTP server

I am trying to execute a Grizzly HTTP Server inside a container.
Why i have this error, while running jar:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/grizzly/http/server/HttpServer
All was allright in maven with pom, but i met this error in gradle.
This is my build.gradle:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.13.0",
}
}
group 'com.mycompany'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'com.palantir.docker'
docker {
name "${project.group}/${jar.baseName}"
files 'build/libs'
buildArgs(['JAR_FILE': "${jar.archiveName}"])
}
jar {
manifest {
attributes 'Main-Class': 'com.mycompany.json_validator.Main'
}
baseName = 'JSON_validator-boot-docker'
version = '0.2.0'
archiveName = 'JSON_validator-boot-docker-0.2.0.jar'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.26'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-multipart', version: '2.7'
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.17'
compile group: 'org.glassfish.jersey', name: 'jersey-bom', version: '2.17', ext: 'pom'
}
All in all, i want to build jar for docker.
java.lang.NoClassDefFoundError:
org/glassfish/grizzly/http/server/HttpServer
NoClassDefFoundError indicates definition of the class could be found at the runtime, this could be missing jar/libraries. Make sure, you have included grizzly-http-server-x.x.x.jar and related jars in classpath.

Categories