build.gradle
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
implementation("net.dv8tion:JDA:5.0.0-alpha.8")
}
test {
useJUnitPlatform()
}
bot.java
package Main;
import net.dv8tion.jda.api.JDABuilder;
;
public class testbotgradle {
public static void main(String[] args) throws LoginException {
JDABuilder jda = new JDABuilder.createDefault("my tocen");
jda.setActivity(Ativity.playing("test"));
jda.setStatus(OnlineStatus.ONLINE);
jda.build();
}
}
throws
java.lang.ClassNotFoundException: bot
Also seams like Java cant import the JDA package but I have no idea why. I have installed the dependencies. They are in the same project. Im using IntellijIDEA
It's probably a little late but for me the error can come from two places:
Either you did not launch your gradle.build after putting the code
Either the alpha 8 is no longer available and in this case
implementation("net.dv8tion:JDA:5.0.0-alpha.9")
Related
I created a new Spring application from https://start.srping.io
My build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '19'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
tasks.named('test') {
useJUnitPlatform()
}
File DemoApplication.java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
I press button Run, the program error. How to fix it?
Looks like project dependencies mentioned in build.gradle file not downloaded properly because I can see some compilation errors as well.
Please run this command and try again.
gradle build
I'm trying run with code with gradle and without it.
public class Example {
public static void main(String[] args) throws RuntimeException {
throw new RuntimeException();
}
}
With gradle it's not working.
[Exception when i run code with gradle][1]
[1]: https://i.stack.imgur.com/kJtyL.png
Without gradle it works.
I tried to run this code on java 8 - java 18 versions and used different versions of gradle.
My gradle file
plugins {
id 'java'
}
group 'org.example'
version '0.0.1'
repositories {
mavenCentral()
}
sourceCompatibility = JavaVersion.VERSION_18
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
test {
useJUnitPlatform()
}
How can I fix it?
Thank you!
I started a Gradle project with java and I wanted to add JavaFx Library but when I run my application I'd got "JavaFX runtime components are missing, and are required to run this application".
This is my Gradle file:
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.9'
}
group 'org.personal'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
javafx {
version = "15.0.1"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
test {
useJUnitPlatform()
}
And this is the main class:
package client;
import javafx.application.Application;
import javafx.stage.Stage;
public class ClientApp extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
}
}
And this is my "Edit Configuration": Edit Configuration here
you need to add the JavaFX JDK libs to the path. Otherwise, you need to use JDK 8 (JDK1.8) which integrates the JavaFX SDK
I am new to spring-boot. I have created a simple spring-boot version 2.2.6 project with gradle build. I have created a welcome jsp just to print a header. I get 404 status when i run it on my server with http://localhost:8081/welcome.html Following is my build.gradle, application class, controller class and application.properties file:
//build.gradle
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.banuprojects'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
implementation 'javax.servlet:jstl'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
//application class
package com.banuprojects.lmsdemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class LmsdemoApplication {
public static void main(String[] args) {
SpringApplication.run(LmsdemoApplication.class, args);
}
}
//controller class
package com.banuprojects.lmsdemo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class TestController {
#RequestMapping("/welcome.html")
public ModelAndView firstPage() {
return new ModelAndView("welcome");
}
}
//application.properties
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp
I am not sure where I have one wrong with the implementation. Any help will be appreciated.
Thank you
As discussed over the comments. After seeing the application properties file, found that wrong port was passed in the URL.
No other technical error found.
I am currently working through the example on scheduling tasks using Spring 4, Java 1.8, and Gradle (https://spring.io/guides/gs/scheduling-tasks/).
However, when running this example, I receive the following error:
Error:(11, 8) java: cannot access org.springframework.web.WebApplicationInitializer
class file for org.springframework.web.WebApplicationInitializer not found
The source code to my Application.java is as follows:
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableScheduling;
#SpringBootApplication
#EnableScheduling
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class);
}
}
My gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
jar {
baseName = 'gs-scheduling-tasks'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter")
testCompile("org.springframework.boot:spring-boot-starter-test")
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}
Why is org.springframework.web.WebApplicationInitializer causing this error when it is not even mentioned in the guide?
Thanks.
Add this dependency to fix this problem. I perfectly worked for me.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
The guide does not extend SpringBootServletInitializer, remove it or add spring-boot-starter-web as a dependency if you want to start a Tomcat webserver inside you application.
You are extending SpringBootServletInitializer which implements WebApplicationInitializer
check http://grepcode.com/file/repo1.maven.org/maven2/org.springframework.boot/spring-boot/1.0.2.RELEASE/org/springframework/boot/context/web/SpringBootServletInitializer.java
Use this Application class instead as the guide is showing
#SpringBootApplication
#EnableScheduling
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class);
}
}