I'm getting an error when trying to create a capsule using Gradle.
Failed to find Premain-Class manifest attribute in
E:\Dropbox\Projects\Kotlin\Games\CSGO\Charlatano\build\libs\capsule.jar
Error occurred during initialization of VM
agent library failed to init: instrument
CAPSULE: Client connection failed.
CAPSULE EXCEPTION: Accept timed out while processing null null: null (for stack trace, run with -Dcapsule.log=verbose)
Press any key to continue . . .
Here is my build.script
buildscript {
ext.kotlin_version = '1.1-M01'
ext.jna_version = '4.3.0-SNAPSHOT'
ext.quasar_version = '0.7.6'
ext.gdxVersion = '1.9.4'
repositories {
mavenCentral()
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'
group 'com.charlatano'
version '0.4.3'
mainClassName = 'com.charlatano.Charlatano'
sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1' }
}
configurations {
quasar
capsule
}
dependencies {
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: kotlin_version
compile group: 'net.java.dev.jna', name: 'jna', version: jna_version
compile group: 'net.java.dev.jna', name: 'jna-platform', version: jna_version
compile group: 'org.jire.arrowhead', name: 'arrowhead', version: '1.2.1'
capsule group: 'co.paralleluniverse', name: 'capsule', version: '1.0.3'
quasar group: 'co.paralleluniverse', name: 'quasar-core', version: quasar_version
compile group: 'co.paralleluniverse', name: 'quasar-core', version: quasar_version
compile group: 'co.paralleluniverse', name: 'quasar-actors', version: quasar_version
compile group: 'co.paralleluniverse', name: 'quasar-kotlin', version: quasar_version
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
}
task capsule(type: Jar, dependsOn: jar) {
archiveName = "capsule.jar"
from jar // embed our application jar
from { configurations.runtime } // embed dependencies
from(configurations.capsule.collect { zipTree(it) }) { include 'Capsule.class' } // we just need the single Capsule class
manifest {
attributes(
'Main-Class' : 'Capsule',
'Application-Class' : mainClassName,
'Extract-Capsule' : 'false', // no need to extract the capsule
'Min-Java-Version' : '1.8.0',
'JVM-Args' : run.jvmArgs.join(' '),
'System-Properties' : run.systemProperties.collect { k,v -> "$k=$v" }.join(' '),
'Java-Agents' : configurations.quasar.iterator().next().getName()
)
}
}
run {
jvmArgs "-javaagent:${configurations.quasar.iterator().next()}"
}
Here are the jar files it generates.
https://dl.dropboxusercontent.com/u/91292881/ShareX/2016/09/libs.zip
Please tell me what is wrong, thanks!
It seems that MANIFEST.md in capsule is broken and it misses a Premain-Class attribute like below:
Premain-Class: org.eclipse.package.ObjectSizeFetcher
Your's capsule manifest file should look like:
Manifest-Version: 1.0
Created-By: 1.5.0_18 (Sun Microsystems Inc.)
Premain-Class: org.eclipse.package.ObjectSizeFetcher
Check similar issue to find more: "Failed to load Premain-Class manifest attribute" while trying to get the size of an object using java agent
Related
I have a grails application written in Groovy. It is built and works when it's launched with :
./gradlew bootRun
Now I want to run it with java to put it in a Docker container. This is the Dockerfile I prepared :
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=build/libs/*.war
ADD ${JAR_FILE} app.war
ENTRYPOINT ["java"]
CMD ["-Dgrails.env=development","-jar","app.war"]
The server fails to start because of the following error:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is java.lang.ClassNotFoundException: com.flosslab.eGrocery.showcase.CmsTagLib
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 29 more
Caused by: java.lang.ClassNotFoundException: com.flosslab.eGrocery.showcase.CmsTagLib
When I checked the classes folder in WEB-INF, I found that the class is there in the correct path. I tried with a Tomcat setup, with Docker and without Docker and I'm still encountering the exact same error. I think something is wrong with the .WAR build. Here is the build.gradle file
build.gradle:
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/core" }
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0"
// classpath "org.grails.plugins:hibernate4:5.0.2"
classpath 'org.springframework:springloaded:1.2.8.RELEASE'
classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
}
}
version "1.0.49"
group "com.flosslab.egrocery"
apply plugin: "com.github.ManifestClasspath"
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
apply plugin: "asset-pipeline"
war.archiveName = "egrocery-showcase.war"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/core" }
maven { url "https://repo.grails.org/grails/core" }
maven { url "http://192.168.12.16:8081/artifactory/egrocery-local" }
maven { url "http://192.168.12.16:8081/artifactory/libs-release-local" }
maven { url "http://192.168.12.16:8081/artifactory/plugins-release-local" }
mavenCentral()
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
def elasticsearchVersion = '5.6.8'
ext['elasticsearch.version'] = elasticsearchVersion
dependencies {
compile fileTree(dir: "libs", includes: ["*.jar"])
compile "com.flosslab.egrocery:domain:1.0.49"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-core"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-datastore-rest-client:5.0.3.RELEASE"
console "org.grails:grails-console"
profile "org.grails.profiles:web:$grailsVersion"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.grails.plugins:spring-security-rest:2.0.0.M2"
compile "org.grails.plugins:spring-security-rest-gorm:2.0.0.M2"
runtime "org.grails.plugins:asset-pipeline"
runtime group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.7'
runtime group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7'
// compile group: 'org.elasticsearch', name: 'elasticsearch', version: elasticsearchVersion
// compile group: 'org.elasticsearch.client', name: 'transport', version: elasticsearchVersion
// compile "org.grails.plugins:elasticsearch:1.4.1"
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:cache-ehcache:3.0.0.BUILD-SNAPSHOT"
compile "net.sf.ehcache:ehcache:2.10.2.2.21"
compile "net.sf.ehcache:ehcache-core:2.6.11"
compile "com.google.code.maven-play-plugin.net.tanesha.recaptcha4j:recaptcha4j:0.0.8"
runtime group: "org.postgresql", name: "postgresql", version: "42.1.4"
compile group: "net.java.dev.jna", name: "platform", version: "3.5.0"
compile group: "com.nimbusds", name: "nimbus-jose-jwt", version: "4.8"
compile group: "org.pac4j", name: "pac4j-core", version: "1.8.3"
compile "org.grails.plugins:fields"
testCompile "org.grails:grails-plugin-testing"
// testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}
configurations {
all {
exclude module: "bcmail-jdk14"
exclude module: "bctsp-jdk14"
exclude group: "com.google.guava", module: "guava"
exclude group: "com.google.guava", module: "guava-base"
}
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
gradle.properties:
grailsVersion=3.1.8
gradleWrapperVersion=2.11
Maybe there is something is lacking or something is wrong with the grails/groovy version ? I'm stuck for the entire day so I would appreciate your help.
Update :
Here is the Dockerfile I tried with Tomcat that I mentionned earlier. It gives me the exact same error.
FROM tomcat:8.5.75-jdk8-temurin
COPY egrocery-showcase.war /usr/local/tomcat/webapps
CMD ["catalina.sh", "run"]
I can't believe I wasted two days straight on this because someone wrote the package with an uppercase letter. There was a class in a package :
package com.flosslab.eGrocery.showcase
When I changed it to
package com.flosslab.egrocery.showcase
I got past this error.
I am building a bot in Intellij using Gradle. I've completed the bot and try to execute the jar task in build a .jar to with all the dependancies. However, I keep running into an error.
Cannot convert the provided notation to a File or URI: [ZIP 'C:\Users\name.gradle\caches\modules-2\files-2.1\net.dv8tion\JDA\4.3.0_282\c2e3739477a8e59699355db3bae73b3ab0a1c62e\JDA-4.3.0_282.jar', ZIP 'C:\Users\name.gradle\caches\modules-2\files-2.1\me.duncte123\botCommons\1.0.73\bdadec013dad0b8dc6c582ddc080677978d7adcd\botCommons-1.0.73.jar', ZIP 'C:\Users\name.gradle\caches\modules-2\files-2.1\com.sedmelluq\lavaplayer\1.3.64\69e1889fc5db48dafd1a22f76721d3d95a5b06be\lavaplayer-1.3.64.jar', ZIP 'C:\Users\name.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic\1.2.3\7c4f3c474fb2c041d8028740440937705ebb473a\logback-classic-1.2.3.jar', ZIP 'C:\Users\name.gradle\caches\modules-2\files-2.1\io.github.cdimascio\java-dotenv\5.1.1\6c5712d04751e707b9f925aab756302e74103f59\java-dotenv-5.1.1.jar', ZIP 'C:\Users\name.gradle\caches\modules-2\files-2.1\mysql\mysql-connector-java\5.1.6\380ef5226de2c85ff3b38cbfefeea881c5fce09d\mysql-connector-java-5.1.6.jar', ZIP 'C:\Users\name.gradle\caches\modules-2\files-2.1\net.sf.trove4j\trove4j\3.0.3\42ccaf4761f0dfdfa805c9e340d99a755907e2dd\trove4j-3.0.3.jar', ZIP 'C:\Users\name.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.10.1\18eee15ffc662d27538d5b6ee84e4c92c0a9d03e\jackson-databind-2.10.1.jar', ...].
The following types/formats are supported:
- A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
- A String or CharSequence URI, for example 'file:/usr/include'.
- A File instance.
- A Path instance.
- A Directory instance.
- A RegularFile instance.
- A URI or URL instance.
- A TextResource instance.
(The list of ZIPs was cut short due to there being way too many to list out.)
Below is what my build.gradle file looks like when I try to run.
plugins {
id 'java'
id 'application'
}
group 'com.darkascendants'
version '1.0-SNAPSHOT'
application {
mainClassName = 'com.darkascendants.DABot'
}
repositories {
mavenCentral()
jcenter()
maven {
name 'm2-dv8tion'
url 'https://m2.dv8tion.net/releases'
}
}
apply plugin: 'java'
dependencies {
implementation group: 'net.dv8tion', name: 'JDA', version: '4.3.0_282'
implementation group: 'me.duncte123', name: 'botCommons', version: '1.0.73'
implementation group: 'com.jagrosh', name: 'jda-utilities', version: '3.0.1'
implementation group: 'com.sedmelluq', name: 'lavaplayer', version: '1.3.64'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
implementation group: 'io.github.cdimascio', name: 'java-dotenv', version: '5.1.1'
implementation group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'
implementation fileTree('libs') { include '*.jar' }
}
compileJava.options.encoding = 'UTF-8'
jar {
manifest {
attributes(
'Main-Class': 'com.darkascendants.DABot'
)
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
}
}
}
Why am I running into this issue?
What is in 2021 the best way to create an executable jar file with Gradle in IntelliJ using OpenJFX? Every solution I found is very complex and uses workarounds. This is my current build.gradle file
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
repositories {
mavenCentral()
}
javafx {
version = "15.0.1"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
mainClassName = 'com.company.crawl.main.Main'
group 'com.company'
version '1.0-SNAPSHOT'
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '9.2.0.jre15'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compile group: 'org.apache.commons', name: 'commons-csv', version: '1.8'
}
jar {
from configurations.compile.collect {zipTree it}
manifest.attributes "Main-Class": "com.company.crawl.main.Main"
}
If I run gradle :jar, the jar file includes the dependencies but not the openjfx sdk. What do I have to do to run the jar using the openjfx sdk?
UPDATE 1
changed the jar path to this:
jar {
manifest {
attributes 'Main-Class': 'com.company.crawl.main.Main'
}
from {
configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it)}
}
}
after rebuilding the jar, I get the error: "JavaFX runtime components are missing". I don't know why because in the jar file the javafx folders are included. After that I added the VM options:
--module-path /path/to/javafx-sdk/lib --add-modules=javafx.controls,javafx.fxml
and the jar file runs. So what am I doing wrong?
when I launch my .jar with this command "java -jar epsilon-1.0.jar"
He says "Cannot find or load main class net.epsilon.app.Main"
plugins {
id 'java'
}
group 'net.epsilon'
version '1.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
task fatJar(type: Jar) {
manifest {
attributes["Main-Class"] = "net.epsilon.app.Main"
}
destinationDir = file("C:/Users/EliXorZz/Desktop/EpsilonAPP")
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.13'
compile group: 'com.github.docker-java', name: 'docker-java', version: '3.2.0'
compile group: 'redis.clients', name: 'jedis', version: '3.3.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile 'me.tongfei:progressbar:0.8.1'
}
Help me please.
Thank you.
Sorry, I'm not english.
No it can't work this way.
First, you are copying all the jars to a folder called C:/Users/EliXorZz/Desktop/EpsilonAPP, but when you run your jar, you never tell java to place those jars you copied into the classpath.
So actually the command to run your jar is:
java -jar epsilon-1.0.jar -classpath 'C:/Users/EliXorZz/Desktop/EpsilonAPP/*'
I am creating a Docker image for my Java Gradle Project.
In my Docker File as I came to an understanding. Executing the dockerFile using Gradle docker creates an image for my docker file ready to be executed. it also creates a jar file for my Gradle project to be executed.
My docker File is as follows :
FROM openjdk:13-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} ./app.jar
CMD ["java","-jar","app.jar" , "Simulator.NewMain"]
and by build.gradle is as follows :
buildscript {
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
}
repositories {
mavenLocal()
mavenCentral()
}
}
plugins {
id 'com.palantir.docker' version '0.22.1'
id 'java'
}
allprojects {apply plugin: 'idea'}
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'Simulator.NewMain'
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven { url "http://streamreasoning.org/maven" }
maven { url "http://service.hucompute.org/artifactory/libs-release" }
maven { url "https://raw.githubusercontent.com/alexeygrigorev/maven-repo/master/" }
}
docker {
name "hi"
dockerfile file('src/docker/Dockerfile')
copySpec.from(jar).rename(".*","app.jar")
buildArgs(['JAR_FILE' : "app.jar"])
}
jar {
manifest {
attributes(
'Main-Class': 'Simulator.NewMain'
)
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
dependencies {
//compile project(':shared')
compile files('libs/mdsj.jar')
// https://mvnrepository.com/artifact/org.apache.commons/commons-math3
compile group: 'org.apache.commons', name: 'commons-math3', version: '3.0'
// https://mvnrepository.com/artifact/org.ujmp/ujmp-core
compile group: 'org.ujmp', name: 'ujmp-core', version: '0.3.0'
// https://mvnrepository.com/artifact/com.datumbox/lpsolve
compile group: 'com.datumbox', name: 'lpsolve', version: '5.5.2.0'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
// https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.7.2'
// https://mvnrepository.com/artifact/junit/junit
testCompile group: 'junit', name: 'junit', version: '4.4'
// https://mvnrepository.com/artifact/net.sourceforge/javaml
compile group: 'net.sourceforge', name: 'javaml', version: '0.1.7'
compile group: 'be.abeel', name: 'ajt', version: '2.9'
}
My Dockerfile produces a jar file into my docker image called app.jar.
I then try to run this jar file in the image. However each time I try it I stumble upon this error.
Error: Could not find or load main class NewMain.class
Caused by: java.lang.ClassNotFoundException: NewMain.class
the result of executing my Gradle docker builds successfully, however running docker run DockerImage where DockerImage is the name of my image produces the above error.
I tried to create a jar image myself from the same project and execute it using the java -cp app.jar but i am still getting the same error.
I also went through the jar file's classes and i found the class I am trying to execute.
the NewMain class is a simple println class with the following syntax:
package Simulator;
public class NewMain {
public static void main(String[] args) {
System.out.println("hi");
}
}
Does anyone know how to overcome the classnotfound error? or the reason it happens?
P.s: I suspected the reason might be from my JDK version so i updated to JDK13