./gradlew run BUILD FAILED - java

I have my build.gradle file set up and my project is working good so far. The problem now is when i run ./gradlew run, it fails with the error :
What went wrong:
Execution failed for task ':run'.
Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 1
./gradlew build BUILD SUCCESSFULLY, Any clue as to why, Have also tried to check previous thread but all to no avail.Below is my gradle.build file:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
mainClassName = 'src.main.java.Functional.TestRun'
repositories {
mavenCentral()
}
sourceSets {
selenium
}
jar {
baseName = 'gs-gradle'
version = '0.1.0'
manifest {
attributes 'Main-Class': 'main.java.Functional.TestRun'
}
}
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
dependencies {
seleniumCompile 'junit:junit:4.11'
seleniumCompile 'org.seleniumhq.selenium:selenium-java:2.45.0'
seleniumCompile 'org.seleniumhq.selenium:selenium-server:2.45.0'
compile fileTree(dir: 'libraries', include: '*.jar')
}
task jettyDaemon(type: org.gradle.api.plugins.jetty.JettyRun) {
daemon = true
}
task selenium(type: Test, dependsOn: jettyDaemon) {
testClassesDir = sourceSets.selenium.output.classesDir
classpath = sourceSets.selenium.runtimeClasspath
}
eclipse {
classpath {
plusConfigurations += configurations.seleniumCompile
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
ERROR:
ola#ola-VirtualBox:~/workspace/mainsite_automation$ ./gradlew run
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:run
Error: Could not find or load main class src.main.java.Functional.TestRun
:run FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished
with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --
debug option to get more log output.
BUILD FAILED
Total time: 2.185 secs

Replace mainClassName = 'src.main.java.Functional.TestRun' in your build.gradle by mainClassName = Functional.TestRun'. You should also fix your manifest entry.

Related

I am having issue building my first flutter app with android studio getting few errors can someone help me?

Building with sound null safety
FAILURE: Build failed with an exception.
Where:
Build file 'C:\WordpressApp\main_files\source\wordpress_app\android\app\build.gradle' line: 24
What went wrong:
A problem occurred evaluating project ':app'.
Plugin with id 'com.android.application' not found.
Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1s
Running Gradle task 'assembleRelease'... 2,412ms
Gradle task assembleRelease failed with exit code 1
I am using following tools for flutter app development *
Android Studio Chipmunk | 2021.2.1 Patch 1
Build #AI-212.5712.43.2112.8609683, built on May 18, 2022
Runtime version: 11.0.12+7-b1504.28-7817840 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1536M
Cores: 4
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.intellij.scripting-javascript (1.0), com.intellij.javafx (1.0.4), org.jetbrains.kotlin (212-1.6.21-release-334-AS5457.46), Dart (212.5744), idea.plugin.protoeditor (212.5080.8), io.flutter (68.1.2)
buildscript {
ext.kotlin_version = '1.6.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.5'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
hello i think the problem that you have 2 subprojects block try to delete one and the other like this :
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
Please check android/app/build.gradle
and see if this is existing there.
apply plugin: 'com.android.application'

Alpine Docker Image to run JLink executable

My current Docker image is approximately 200MB. My goal is to reduce that as much as possible, so I thought the alpine image would be a great way to achieve that. However, I keep encountering roadblocks.
It's a multi-module libGDX project that uses Java 14 and its preview features, along with JLink (from JPackage) to produce a custom (lightweight) JRE.
I only care to deploy the server module, which depends on the common module (which the client module also uses).
I'll be providing all the necessary files below, but in case I'm missing something, here is a link to the repo: https://github.com/payne911/marvelous-bob/tree/dev
Current problem
I either get:
when executing ./server: file not found for an executable file which I know exists and is executable where I'm trying to run it in the Docker Image
when executing apk add --no-cache someLibrary: a segfault: core dumped when trying to download libraries in my ENTRYPOINT which I thought were required to execute that file (libstdc++ and libc6-compat)
Goal
Reusable lightweight Docker Image which contains everything to run libGDX executables generated by JLink.
Current files which are in a working state and I'm trying to refactor
Dockerfile
FROM openjdk:14-jdk-alpine
COPY server/build/libs/server-all.jar /app.jar
COPY utils/deploys/bootstrap.sh /bootstrap.sh
RUN chmod +x /bootstrap.sh
EXPOSE 80
ENTRYPOINT ["./bootstrap.sh"]
bootstrap.sh
#!/usr/bin/env sh
echo "========== LAUNCHING SERVER APP ========="
apk add --no-cache libstdc++
java --enable-preview -jar /app.jar
build.gradle files
root
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
}
}
// to force download of sources and JavaDoc
plugins {
id 'java'
id 'idea'
}
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
allprojects {
version = '1.0'
ext {
appName = "marvelous-bob"
gdxVersion = '1.9.10'
roboVMVersion = '2.3.7'
box2DLightsVersion = '1.5'
ashleyVersion = '1.7.0'
aiVersion = '1.8.2'
slf4j = '1.7.26'
logback = '1.2.3'
lombok = '1.18.12'
kryonet = '2.22.6'
reflectionsVersion = '0.9.12'
pieMenuVersion = '4.2.0'
shapeDrawer = '2.3.0'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
maven { url 'https://jitpack.io' }
}
}
project(":desktop") {
apply plugin: "java-library"
dependencies {
api project(":client")
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
}
}
project(":client") {
apply plugin: "java-library"
dependencies {
api project(":common")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "space.earlygrey:shapedrawer:$shapeDrawer"
api "com.github.payne911:PieMenu:$pieMenuVersion"
}
}
project(":server") {
apply plugin: "java-library"
dependencies {
api project(":common")
api "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
}
project(":common") {
apply plugin: "java-library"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
api "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
api "com.badlogicgames.gdx:gdx-ai:$aiVersion"
// todo: do we need both logging libraries? p.s. kryonet uses Minlog
api "org.slf4j:slf4j-api:$slf4j"
api "ch.qos.logback:logback-classic:$logback"
api "com.github.crykn:kryonet:$kryonet"
api "org.reflections:reflections:$reflectionsVersion"
}
}
common
plugins {
id 'java'
id 'io.freefair.lombok' version '5.1.0'
}
sourceCompatibility = 14
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.compilerArgs += "--enable-preview"
}
tasks.withType(Test) {
jvmArgs += "--enable-preview"
}
tasks.withType(JavaExec) {
jvmArgs += '--enable-preview'
}
sourceSets.main.java.srcDirs = [ "src/" ]
jar {
from('src') {
include '**/*.properties'
}
}
server
plugins {
id 'java'
id 'io.freefair.lombok' version '5.1.0'
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
sourceCompatibility = 14
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.compilerArgs += "--enable-preview"
}
tasks.withType(Test) {
jvmArgs += "--enable-preview"
}
tasks.withType(JavaExec) {
jvmArgs += '--enable-preview'
}
sourceSets.main.java.srcDirs = [ "src/" ]
jar {
project.version="" // to remove version number from the built jar's name
manifest {
attributes 'Main-Class': 'com.marvelousbob.server.BobServerLauncher'
}
}
GitHub Actions yml file
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup with Java 14
id: java-setup
uses: actions/setup-java#v1
with:
java-version: 14
- name: Allow GitHub Actions to run Gradlew
run: chmod u+x gradlew
- name: Run Gradle build
id: gradle-build
uses: eskatos/gradle-command-action#v1
with:
arguments: shadowJar
# more stuff ...
What I've tried
So many things, for days! Here was the state of my last attempt.
Dockerfile
FROM alpine:3.7
COPY server/build/jpackage/server /server
FROM openjdk:14-jdk-alpine
COPY server/build/libs/server-all.jar /app.jar
COPY utils/deploys/bootstrap.sh /bootstrap.sh
RUN chmod +x /bootstrap.sh
EXPOSE 80
ENTRYPOINT ["./bootstrap.sh"]
bootstrap.sh
#!/bin/sh
echo "========== LAUNCHING SERVER APP ========="
cd /server/bin
chmod +x server
./server
build.gradle
root
Same as other one.
common
Same as other one.
server
plugins {
id 'java'
id 'io.freefair.lombok' version '5.1.0'
id 'org.beryx.runtime' version '1.8.4'
}
sourceCompatibility = 14
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.compilerArgs += "--enable-preview"
}
tasks.withType(Test) {
jvmArgs += "--enable-preview"
}
tasks.withType(JavaExec) {
jvmArgs += '--enable-preview'
}
sourceSets.main.java.srcDirs = [ "src/" ]
mainClassName = "com.marvelousbob.server.BobServerLauncher"
task dist(type: Jar) {
project.version="1" // adjust the CI/CD if you change this
manifest {
attributes 'Main-Class': project.mainClassName
}
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
destinationDirectory = file("$buildDir/lib")
}
jpackageImage.dependsOn dist
dist.dependsOn classes
// JLink configuration to minimize size of generated jar
runtime {
options = ['--strip-debug',
'--compress', '2',
'--no-header-files',
'--no-man-pages',
'--strip-native-commands',
'--vm', 'server']
modules = ['java.base' ,
'java.desktop',
'jdk.unsupported']
distDir = file(buildDir)
jpackage {
//jpackageHome = '/usr/lib/jvm/open-jdk'
mainJar = dist.archiveFileName.get()
}
}
Github Actions yml file
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup with Java 14
id: java-setup
uses: actions/setup-java#v1
with:
java-version: 14
- name: Building with Gradlew
run: |
chmod u+x gradlew
./gradlew server:jpackageImage
# more stuff ...
#deduper seems to have figured it out (see https://chat.stackoverflow.com/rooms/222569/discussion-between-deduper-and-payne), but I didn't have time to go back and make sure his analysis is right.
In theory, it does make a lot of sense, so I'm posting it nonetheless as an answer:
I'm pretty sure the main cause of the errors you describe in your question is because you built the runtime on either Windows 10 or Ubuntu; then tried to deploy and run the runtime on Alpine.
I won't accept my answer because I haven't made a confirmation of this yet, but I'm nonetheless posting it in case others encounter this problem and want a probable clue.

How do I run a main method in a Java Gradle project from command line?

I have a Gradle project (say, MyProject) that has a main method that I only want to use to run a small Java app. Say, the script is in a class and package as follows:
MyScript.Java
package com.car.ant;
import com.3rdparty.library.LibraryException;
public class MyScript {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
I build the project with $ ./gradlew clean build, no problem. I am trying to run this via command line, but when I do, I get an Exception when trying to run:
$ pwd
~/workspace/MyProject/build/classes/java/main
$ java com.car.ant.MyScript
Exception in thread "main" java.lang.NoClassDefFoundError: com/3rdparty/library/exception/LibraryException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
... 7 more
This script is not the main part of the app, but I just want it in there to run every once in a while, and I'd like to figure out how to run it by itself command line. Is there a way to do this without importing anymore libraries? I've seen this done with one-jar, but I thought I could do this without one-jar.
UPDATE:
Tried to add a classpath after reading this, but now I'm getting a different error:
$ java -cp com/3rdparty/library/exception/LibraryException com.car.ant.MyScript
Error: Could not find or load main class com.car.ant.MyScript
You can read about how to do this at the Gradle Docs.
apply plugin: 'application'
mainClassName = "com.mycompany.myapplication.MyScript"
applicationDefaultJvmArgs = [
"-Djava.util.logging.config.file=src/main/resources/logging.properties"
]
Then simply use gradlew run to run your application.
As an added benefit, this plugin helps you to package your app for distribution. Use the gradle distZip command for that.
Try this.
plugins {
id 'java-library'
id 'application'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
/*
sourceCompatibility is "Java version compatibility to use when compiling Java source."
targetCompatibility is "Java version to generate classes for."
*/
repositories {
jcenter()
}
dependencies {
}
//To run the class name from command line using gradle run
mainClassName = 'com.sam.home.HelloWorld'
//To create a runnable jar in GradleJavaProject\build\libs then java -jar GradleJavaProject.jar
jar {
manifest {
attributes 'Main-Class': 'com.sam.home.HelloWorld'
}
}
//Beyond this line evertyhing is optional
//Alternatively you can run it as a task too gradle -q runWithJavaExec
task runWithJavaExec(type: JavaExec) {
group = "Execution"
description = "Run the main class with JavaExecTask"
classpath = sourceSets.main.runtimeClasspath
main = 'com.sam.home.HelloWorld'
}
wrapper {
gradleVersion = '5.5'
distributionType = Wrapper.DistributionType.BIN
}
In command line type either gradle run or gradle -q runWithJavaExec

Error when compiling JavaFx to android using Gluon

I have a Javafx application and I am trying to port to android using the gluon plugin for netbeans. I am currently getting this error:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':createMainDexList'.
Exception in thread "main" com.android.dx.cf.iface.ParseException: InvokeDynamic not supported
at com.android.dx.cf.cst.ConstantPoolParser.determineOffsets(ConstantPoolParser.java:226)
at com.android.dx.cf.cst.ConstantPoolParser.parse(ConstantPoolParser.java:132)
at com.android.dx.cf.cst.ConstantPoolParser.parseIfNecessary(ConstantPoolParser.java:124)
at com.android.dx.cf.cst.ConstantPoolParser.getPool(ConstantPoolParser.java:115)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:491)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToEndIfNecessary(DirectClassFile.java:397)
at com.android.dx.cf.direct.DirectClassFile.getAttributes(DirectClassFile.java:311)
at com.android.multidex.MainDexListBuilder.hasRuntimeVisibleAnnotation(MainDexListBuilder.java:191)
at com.android.multidex.MainDexListBuilder.keepAnnotated(MainDexListBuilder.java:167)
at com.android.multidex.MainDexListBuilder.(MainDexListBuilder.java:121)
at com.android.multidex.MainDexListBuilder.main(MainDexListBuilder.java:91)
at com.android.multidex.ClassReferenceListBuilder.main(ClassReferenceListBuilder.java:58)
...while preparsing cst 000e at offset 00000047
...while parsing de/jensd/fx/glyphs/control/skin/GlyphCheckBoxSkin.class
Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED
I have the jdk 8 (64bit) running and this is my build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.0.9'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.mypackage.MyMainClass'
ext.CHARM_DOWN_VERSION = "1.0.0"
dependencies {
compile 'com.gluonhq:charm:3.0.0'
compile 'com.jfoenix:jfoenix:1.6.0'
compile 'de.jensd:fontawesomefx-emojione:2.2.7-2'
compile 'de.jensd:fontawesomefx-fontawesome:4.7.0-5'
compile 'de.jensd:fontawesomefx-icons525:3.0.0-4'
compile 'de.jensd:fontawesomefx-materialdesignfont:1.7.22-4'
compile 'de.jensd:fontawesomefx-materialicons:2.2.0-5'
compile 'de.jensd:fontawesomefx-octicons:4.3.0-5'
compile 'de.jensd:fontawesomefx-weathericons:2.0.10-5'
compile 'de.jensd:fontawesomefx-controls:8.15'
compile 'org.controlsfx:controlsfx:8.40.11'
compile 'org.xerial:sqlite-jdbc:3.8.6'
compile group: 'org.json', name: 'json', version: '20090211'
runtime files('lang')
androidRuntime 'com.gluonhq:charm-android:3.0.0'
iosRuntime 'com.gluonhq:charm-ios:3.0.0'
desktopRuntime 'com.gluonhq:charm-desktop:3.0.0'
compile "com.gluonhq:charm-down-common:$CHARM_DOWN_VERSION"
desktopRuntime "com.gluonhq:charm-down-desktop:$CHARM_DOWN_VERSION"
androidRuntime "com.gluonhq:charm-down-android:$CHARM_DOWN_VERSION"
iosRuntime "com.gluonhq:charm-down-ios:$CHARM_DOWN_VERSION"
}
jfxmobile {
android {
manifest = 'src/android/AndroidManifest.xml'
androidSdk='C:\\AndroidSDK'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'io.datafx.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
Please help!
I have the 64bit of jdk8 running and not 32bit.
I changed my gluon classpath from
classpath 'org.javafxports:jfxmobile-plugin:1.0.9'
To
classpath 'org.javafxports:jfxmobile-plugin:1.3.3'
And I was able to build the apk.

gradle refers java 6 even though my java home is aim to java 8

I run ./gradlew clean build
and i get this error:
warning: [options] bootstrap class path not set in conjunction with -source 1.6
/Users/eladb/WorkspaceQa/java/UsersServer/src/test/java/linqmap/users/jms/UsersServerAccessPropUserNameTest.java:163: error: diamond operator is not supported in -source 1.6
Map<String, String> properties = new HashMap<>();
^
(use -source 7 or higher to enable diamond operator)
1 error
1 warning
:compileTestJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestJava'.
> Compilation failed; see the compiler error output for details.
BUILD FAILED
even though I see my java home is java 8.
where else do i need to configure java 8 ?
➜ myServer echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
my gradle.build:
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'jacoco'
sourceCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
jcenter()
}
dependencies {
//
// configurations.all*.exclude(group: 'com.sun.jersey', module: 'jersey-bundle')
// configurations.all*.exclude(group: 'com.fasterxml.jackson.core', module:'jackson-databind')
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
compile 'com.google.inject:guice:4.0-beta5'
compile 'com.sun.jersey:jersey-core:1.18.3'
compile 'com.sun.jersey:jersey-client:1.18.3'
It looks like you've explicitly set the source compatibility.
Try adding:
sourceCompatibility = 1.8

Categories

Resources