cannot add spigot to build path succesfully for 1.18 plugins - java

I've been trying to import spigot/bukkit for minecraft plugins. When trying to create the main class, I entered
public class Main extends JavaPlugin{
}
With an error under JavaPlugin, since their is no import. The tutorial im following told me to click the fix that will import it for me, but
the fix simply does not show up when I attempt to resolve it, and if I manually import it, it gives the error: "the import org.bukkit.plugin cannot be resolved." I've tried restarting the project, deleting and reinstalling, and everything in between. Please let me know if you need more information on how I've added spigot to the build path, or anything else I can help with.

Since the 1.17, it seems to have some changes with jar. Now, if you start server, it will create the bundler/versions folder, with a given jar that -for me- should fix your issue.
Also, you can use more preferable way to import project, such as maven or gradle. They can help you to easier share the project, and make it faster to run (you can also automatically run it with github actions for example.
To use spigot with maven, use this:
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
(Documentation)
To use spigot with gradle, use this:
repositories {
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url = 'https://oss.sonatype.org/content/repositories/central' }
}
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
}
(Documentation)

Related

javax.jcr.RepositoryException trying to follow Adobe example

I'm trying to follow this example from Adobe:
How to programmatically access the AEM JCR
My code looks like this:
package com.example;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Node;
import org.apache.jackrabbit.commons.JcrUtils;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
try {
//Create a connection to the CQ repository running on local host
Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");
} catch (Exception ex){
System.out.println(ex.toString());
ex.printStackTrace();
}
}
}
My pom.xml has these dependencies:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
<version>2.21.7</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-commons</artifactId>
<version>2.21.7</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr2dav</artifactId>
<version>2.21.7</version>
</dependency>
</dependencies>
When I run with this command:
`java -jar .\target\demo-jar-with-dependencies.jar`
I get the following output:
javax.jcr.RepositoryException: Unable to access a repository with the following settings:
org.apache.jackrabbit.repository.uri: http://localhost:4502/crx/server
The following RepositoryFactory classes were consulted:
org.apache.jackrabbit.core.RepositoryFactoryImpl: declined
Perhaps the repository you are trying to access is not available at the moment.
javax.jcr.RepositoryException: Unable to access a repository with the following settings:
org.apache.jackrabbit.repository.uri: http://localhost:4502/crx/server
The following RepositoryFactory classes were consulted:
org.apache.jackrabbit.core.RepositoryFactoryImpl: declined
Perhaps the repository you are trying to access is not available at the moment.
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:224)
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:264)
at com.example.App.main(App.java:20)
I've found a number of articles both here and on other sites but none of the suggestions I've found have done anything to resolve the issue.
Any thoughts on what I'm doing wrong? I'm pretty new to AEM. Yes, the AEM Author server is running and it's on port 4502. In fact if I open this URL in a web browser I get:
Which seems normal.
Update: The consensus seems to be that I'm going about this incorrectly by using Maven and not downloading the Jackrabbit Standalone library from Apache. So I created an entirely new project in Eclipse, without Maven, and added jackrabbit-standalone.jar Version 2.23.0 (which is the latest) as a reference library. The result is exactly the same:
I've setup a Github repository for this code at:
Github Repo
Please feel free to clone it and see what I'm doing wrong.
We usually write our AEM code in OSGi bundles that we deploy in AEM. If you want to use the JCR API to connect to an AEM instance follow the advice here:
To use the JCR API, add the jackrabbit-standalone-2.4.0.jar file to
your Java application’s classpath. You can obtain this JAR file from
the Java JCR API web page at
https://jackrabbit.apache.org/jcr/jcr-api.html.
Once you download that file you have two options:
1/ No Maven - compile your program manually using javac -classpath ... (and specify the jackrabbit-standalone JAR in the classpath), and run it using java -cp ...
2/ With Maven - install the JAR in the Maven repo (or add it as a dependency using <scope>system<scope>, but you also have to run your program using Maven
Note that the Maven dependencies do not affect the program, the jackrabbit-standalone JAR is all you need to run the code you wrote.
So you're trying to access AEM using Jackrabbit WebDV.
It's pretty clear that you don't have the right components in the class path. You likely need all "spi" related components (these can the WebDAV-related client code), plus "jackrabbit-jcr-commons".
You definitively do not need core; as that would a for a local repository instance.

Trying to run libGDX with Maven and Eclipse

Maybe a newbie question...
I've been working on a LWJGL project, where I use Maven to manage dependencies. In it, I want to use some parts of the libgdx library. So I figured I will first run at least a helloworld working with it before I add it to my main project.
So in my pom.xml I have this:
<!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-backend-lwjgl -->
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-backend-lwjgl</artifactId>
<version>1.9.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-platform -->
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-platform</artifactId>
<version>1.9.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx -->
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx</artifactId>
<version>1.9.11</version>
</dependency>
The other contents of the file are the same as in a working project and are 100% working.
I tried creating a separate libgdx project before that and... it didn't work. But, I saw that the code that was supposed to run the program was:
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
new LwjglApplication(new SomeApplicationListenerFile(), config);
}
So I used that in my maven project.
When I do "run as a Java Application", the error is the following:
Exception in thread "main" java.lang.NoClassDefFoundError: com/badlogic/gdx/backends/lwjgl/LwjglApplicationConfiguration
at org.boby.RayTracing.main.Main.main(Main.java:179)
And if I do a Maven Build, it tells me that "package com.badlogic.gdx.backends.lwjgl does not exist"
I looked for that package in the jars Maven downloaded in the "Maven dependencies" folder and I found it in gdx-backend-lwjgl-1.9.11.jar - right where it should be.
The package is apparently there, but Java cannot find it. How can I fix that?
Some additional information:
Windows 10, eclipse oxygen, Maven 3.6.0, JRE 1.8.0_191, JDK 8
Thank you in advance! I've been banging my head on this for hours.
Edit: I made some progress. Looks like the "test" was messing things up so I removed those statements. Now I get the following Error:
Exception in thread "main" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load shared library 'gdx64.dll' for target: Windows 10, 64-bit
at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:125)
at com.badlogic.gdx.utils.GdxNativesLoader.load(GdxNativesLoader.java:33)
at com.badlogic.gdx.backends.lwjgl.LwjglNativesLoader.load(LwjglNativesLoader.java:47)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:83)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:71)
at org.boby.RayTracing.main.Main.main(Main.java:178)
It looks like I need to include gdx-natives.jar in my dependencies, but I can't find a maven repository for it.
I downloaded gdx-natives.jar (saw it in a forum thread). In there, was a file named "gdx-64.dll". As I need "gdx64.dll", I just renamed the dll and now it runs.
You can let Maven do the work if you define the gdx-platform dep like this:
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-platform</artifactId>
<version>1.9.11</version>
<classifier>natives-desktop</classifier>
</dependency>
This will load the natives jar including the gdx64.dll so you don't have to add any external jar to your project in the build path.
A side note is: if you use the standard Maven repo directory structure and you load assets with the Gdx.files.internal("fileName") statement you need to define a folder in the main/repository with the same name as the package you have your code in. (i.e. main/java/myPackage relates to /main/repository/myPackage). I struggled a bit with this because I don't normaly have to define a package folder int the repository dir.

reference my own class in a pom file

I am using "spring MVC" to build something(project “A”). I use maven to get the jar I need.
But I have a question, if I have a Java file(a separate file), a class in it, how can I use it in project “A” just like the other in pom.xml?
maybe it like this: when i use JSONObject i must edit pom.xml like:
<dependency>
<groupId>net.sf.json-lib<groupId>
.........
</dependency>
I mean i want my java file like JSONObject,i put it in pom file when it want use it in some project:
test.java:
class bc {
public String test() {
return "bc->test";
}
}
pom.xml
<dependency>
<groupId>test<groupId>
.........
</dependency>
controller file (in springMVC)
import ...
#controller
#requestMapping(value="/api")
public class apiController {
#RequestMapping.....................
public #ResponseBody String testMyMavenClass() {
return new bc().test()
}
}
Im not sure about how to use .class in maven pom file but Im sure you can define your own jar file.
First, combine your classes into jar file.
Then, Define it inside pom.xml as external library.
Reference: https://www.tutorialspoint.com/maven/maven_external_dependencies.htm
One more note, you can add below line to make sure maven knows where is external repository:
<repositories>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file:/${project.basedir}/libs</url>
</repository>
</repositories>
Method 1: Install jar file to local maven repository:
Export your project to jar file, then
http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/
Method 2: Use a repository manager. This is more advanced and requires some server skills. I can give you the name & link only, and you should do your research your self: https://www.sonatype.com/download-oss-sonatype

how to properly translate maven to gradle

I'm trying to implement the example here
https://github.com/bytedeco/sample-projects/tree/master/opencv-stitching to my android project.
but I get all kinds of different errors...no luck at all.
I want to first make sure I'm referencing the correct lib. this example uses maven and its pom.xml can be found here. https://github.com/bytedeco/sample-projects/blob/master/opencv-stitching/pom.xml
this is a bit more complicated that what I can translate to gradle. I keep getting errors. Can someone please tell me what I should do to reference the same lib as the example? Thanks a lot!!
Since this project is so small, you try doing gradlew --init. It will convert a maven project to a gradle project if it detects it.
Lets take the pom.xml files:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.bytedeco.javacpp-presets.opencv</groupId>
<artifactId>opencv-stitching</artifactId>
<version>0.11</version>
<dependencies>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv</artifactId>
<version>2.4.11-0.11</version>
</dependency>
</dependencies>
</project>
This is the same as a basic build.gradle:
group = "org.bytedeco.javacpp-presets.opencv"
version = "0.11"
dependencies {
compile "org.bytedeco.javacpp-presets:opencv:2.4.11-0.11"
}

Using imported module in intellij

I'm having trouble figuring out how to actually use an imported module inside of intellij.
I'm trying to make use of maryTTS. More exactly MaryInterface. https://github.com/marytts/marytts/wiki/MaryInterface
Readme says use maven or gradle. I've never used maven, not that that means I can't, but my current project is not a maven project. Just a plain java project. Same with gradle. I'll try maven.
I started just a plain new project called test.
Then I imported the module via:
File->New->Module from existing sources.
Which left me with a module that I could not/did not know how to access. So basically two separate modules in my project.
That meaning if I use this test code:
import javax.sound.sampled.AudioInputStream;
import marytts.LocalMaryInterface;
import marytts.MaryInterface;
import marytts.exceptions.MaryConfigurationException;
import marytts.exceptions.SynthesisException;
import marytts.util.data.audio.AudioPlayer;
public class Voice
{
private MaryInterface marytts;
private AudioPlayer ap;
public Voice(String voiceName)
{
try
{
marytts = new LocalMaryInterface();
marytts.setVoice(voiceName);
ap = new AudioPlayer();
}
catch (MaryConfigurationException ex)
{
ex.printStackTrace();
}
}
public void say(String input)
{
try
{
AudioInputStream audio = marytts.generateAudio(input);
ap.setAudio(audio);
ap.start();
}
catch (SynthesisException ex)
{
System.err.println("Error saying phrase.");
}
}
}
All of the marytts imports fail from my main module. Obviously they are fine in the marytts module.
I also tried creating a blank maven project, then adding the example code to the pom.xml . I changed the artifactId to marytts. It then just gave a path error under dependencies for files in ~/.m2 that were there.
Example here. https://github.com/marytts/marytts
<repositories>
<repository>
<id>central</id>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>de.dfki.mary</groupId>
<artifactId>marytts</artifactId>
<version>5.2</version>
</dependency>
</dependencies>
I've looked through intellj's docs. The module import seems pretty straightforward. Obviously I'm not getting part of the process or doing something wrong.
So my question then is what are the correct steps to be able to call that interface from my main module? Should I use/learn maven?
I'm not sure why this is the answer but it seems to work.
I used the exact verbage from the README but had to ad an id.
<repositories>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>de.dfki.mary</groupId>
<artifactId>voice-cmu-slt-hsmm</artifactId>
<version>5.2</version>
</dependency>
</dependencies>
This seemed to work in as much as I can use all the import statements and create a MaryInterface.
What I do not understand is why it would not have worked this way. I just assumed I needed the marytts artifact.
http://cs.unk.edu/~mcconvilletl/?p=59

Categories

Resources