I'm building a gradle project with a testone.jar dependency
testone.jar is a working.jar with a class Brew that prints stuff.
I want to call testone.Brew from Main.java.
" import testone.Brew; " gives me a compile error
">gradle build" works, ">gradle dependencies" show:
implementation - Implementation only dependencies for source set 'main'. (n)
\--- unspecified (n)
Folder Structure:
GradleTest/
----build/
--------libs/
------------GradleTest.jar
----libs/
--------testone.jar
----src/
--------test/
--------main/net/alexhublon/gradletest/
--------------------------------------Main.java
build.gradle:
apply plugin: 'java'
repositories {
flatDir {
dirs 'libs';
}
}
dependencies {
implementation files("libs/testone.jar")
}
sourceSets {
main.java.srcDir 'src/main'
test.java.srcDir 'src/test'
}
jar {
manifest.attributes 'Main-Class': 'net.alexhublon.gradletest.Main'
}
Here is the code for Main.java:
package net.alexhublon.gradletest;
import java.util.Arrays;
//import libs/testone.jar???
public class Main
{
public static void main (String[] args)
{
System.out.println("Finished");
//testone.Brew brew = new Brew()???
}
}
I would like to import and use the functions from testone.jar
Edit: If you compile the.jar file with the class, it works. I believe the problem is with Gradle
Simply import it as you did with Arrays
:
package net.alexhublon.gradletest;
import java.util.Arrays;
import testone.Brew;
public class Main
{
public static void main (String[] args)
{
System.out.println("Finished");
Brew brew = new Brew()
}
}
https://docs.oracle.com/javase/tutorial/java/package/usepkgs.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.