I'm following Atlassian's Tutorial - Custom message (mail) handler for JIRA
I've hit a brick wall with the second to last step:
3) Create a new file named EditDemoHandlerDetailsWebAction.java in src/main/java/com/example/plugins/tutorial/jira/mailhandlerdemo directory, and give it the following contents:
package com.example.plugins.tutorial.jira.mailhandlerdemo;
import com.atlassian.configurable.ObjectConfigurationException;
import com.atlassian.jira.plugins.mail.webwork.AbstractEditHandlerDetailsWebAction;
import com.atlassian.jira.service.JiraServiceContainer;
import com.atlassian.jira.service.services.file.AbstractMessageHandlingService;
import com.atlassian.jira.service.util.ServiceUtils;
import com.atlassian.jira.util.collect.MapBuilder;
import com.atlassian.plugin.PluginAccessor;
import java.util.Map;
public class EditDemoHandlerDetailsWebAction extends AbstractEditHandlerDetailsWebAction {
private final IssueKeyValidator issueKeyValidator;
public EditDemoHandlerDetailsWebAction(PluginAccessor pluginAccessor, IssueKeyValidator issueKeyValidator) {
super(pluginAccessor);
this.issueKeyValidator = issueKeyValidator;
}
private String issueKey;
public String getIssueKey() {
return issueKey;
}
public void setIssueKey(String issueKey) {
this.issueKey = issueKey;
}
// this method is called to let us populate our variables (or action state)
// with current handler settings managed by associated service (file or mail).
#Override
protected void copyServiceSettings(JiraServiceContainer jiraServiceContainer) throws ObjectConfigurationException {
final String params = jiraServiceContainer.getProperty(AbstractMessageHandlingService.KEY_HANDLER_PARAMS);
final Map<String, String> parameterMap = ServiceUtils.getParameterMap(params);
issueKey = parameterMap.get(DemoHandler.KEY_ISSUE_KEY);
}
#Override
protected Map<String, String> getHandlerParams() {
return MapBuilder.build(DemoHandler.KEY_ISSUE_KEY, issueKey);
}
#Override
protected void doValidation() {
if (configuration == null) {
return; // short-circuit in case we lost session, goes directly to doExecute which redirects user
}
super.doValidation();
issueKeyValidator.validateIssue(issueKey, new WebWorkErrorCollector());
}
}
The class inherits from AbstractEditHandlerDetailsWebAction which allows us to concentrate on parameter validation. It takes care of the add, edit, and cancel handler lifecycle itself.
This tutorial is supposed to support JIRA 5.0+ including the newest version up to 7.2
I am using JIRA 7.1.8
My problem is that maven is unable to locate the dependency for
import com.atlassian.jira.plugins.mail.webwork.AbstractEditHandlerDetailsWebAction;
After a TON of digging, I have found that com.atlassian.jira.plugins.mail exists in the specs for up to JIRA 5.1.8
However, in the specs for 5.2-m03 onward, this folder is not present, which is why maven cant find it.
Moreover, I can't find any information stating that these classes were deprecated nor any suggestion as to what I should replace this code with for my version of JIRA.
So, what can I use in place of the seemingly deprecated com.atlassian.jira.plugins.mail.webwork.AbstractEditHandlerDetailsWebAction; in the above class?
For whatever reason, the version numbers of the JIRA mail plugin became dissociated from the version numbers of JIRA itself. You will be able to build the project once you ensure that you are referencing the correct version of the mail plugin.
I was able to get it to build as follows:
Clone the repo from the tutorial
git clone https://bitbucket.org/atlassian_tutorial/jira-add-email-handler.git
Figure out which version of the JIRA mail plugin is in use
You can do this easily by looking in the JIRA install directory. In my JIRA 7.1 install, the mail plugin was v9.0.3:
$ find <PATH_TO_JIRA_INSTALL>/atlassian-jira -name '*jira-mail-plugin*.jar'
<your path here>/atlassian-jira/WEB-INF/atlassian-bundled-plugins/jira-mail-plugin-9.0.3.jar
Adjust the POM to correspond to the correct version of the mail plugin
Here is the patch I applied against the pom.xml:
diff --git a/pom.xml b/pom.xml
index f493ef2..a3bbb8f 100644
--- a/pom.xml
+++ b/pom.xml
## -54,7 +54,7 ##
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-mail-plugin</artifactId>
- <version>${jira.version}</version>
+ <version>${jira.mail.plugin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
## -104,8 +104,9 ##
</build>
<properties>
- <jira.version>6.0.4</jira.version>
- <amps.version>4.2.0</amps.version>
+ <jira.version>7.1.8</jira.version>
+ <jira.mail.plugin.version>9.0.3</jira.mail.plugin.version> <!-- the version of the mail plugin shipped with your version of JIRA -->
+ <amps.version>5.0.4</amps.version> <!-- Adjust this to the specific version of the plugin SDK you have installed -->
<plugin.testrunner.version>1.1.1</plugin.testrunner.version>
<!-- TestKit version 5.x for JIRA 5.x, 6.x for JIRA 6.x -->
<testkit.version>5.2.26</testkit.version>
Fix other type issues
There is one other reference in DemoHandler that you'll have to change from User to ApplicationUser.
After that, it builds for me.
Related
Im using apache-jena-libs library version 4.3.2(tried various versions). I've imported it as maven pom dependecny
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<version>4.3.2</version>
<type>pom</type>
</dependency>
And it has successfuly loaded(no errors)
(https://i.stack.imgur.com/h29Gp.png)
imports are fine as well, no errors there
import org.apache.jena.riot.*;
import org.apache.jena.graph.*;
but when I actually use library in code as such:
#Override
public synchronized void add(Reader reader, String fullFilePath, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException {
this.verifyIsOpen();
this.flushDelayAdd();
// final boolean useStatementContext = contexts != null && contexts.length == 0;
IRI graphIri = (IRI) Arrays.stream(contexts).findFirst().get();
try {
Graph gf = Factory.createDefaultGraph();
org.apache.jena.riot.RDFParser.create()
.source(fullFilePath)
.forceLang(org.apache.jena.riot.Lang.JSONLD11)
.base(graphIri.stringValue())
.parse(gf);
gf.close();
...
Everything looks fine but during maven clean-install I get error "cannot access org.apache.jena.graph.Graph".
This method is a part of the standart public class(no bean).
Im using Intelij Idea 2022.2.3 (Ultimate Edition) with JDK 1.8 and maven 3.8.1.
This problem I am encountering is only with this library, tried to search for answers but havent found anything exactly like this. Does anyone have any clue what could be wrong please?
I'm trying to upgrade dependencies for a java application that uses com.vividsolutions.jts. I have removed all the references to this library from pom.xml and replaced them by the ones from org.locationtech.jts.
I have updated all the imports to use org.locationtech version. However, in my function I'm still getting an error related to com.vividsolutions object not being imported.
import org.locationtech.spatial4j.context.jts.JtsSpatialContext;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LinearRing;
import org.locationtech.spatial4j.shape.jts.JtsGeometry;
// ... other stuff
public static myFunc() {
GeometryFactory gf = new GeometryFactory();
LinearRing linear = gf.createLinearRing(coordinates);
JtsGeometry poly = new JtsGeometry(fact.createPolygon(linear), JtsSpatialContext.GEO, true, true);
}
Here's the error that I get for the last line of the above code: [ERROR] cannot access com.vividsolutions.jts.geom.Geometry [ERROR] class file for com.vividsolutions.jts.geom.Geometry not found
I'm clearly importing JtsGeometry from the new library at org.locationtech, however, it's still thinking the old library should be used.
The old library isn't in the dependency tree or the code anymore, as the followings don't return anything:
mvn dependency:tree | grep vivid
rg vivid
Any idea what I'm missing here or how I should troubleshoot this?
I'm not too sure what was wrong with the vividsolutions library inclusion. However, I was able to resolve my issue by including both of these in pom.xml:
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.18.2</version>
</dependency>
<dependency>
<groupId>org.locationtech.spatial4j</groupId>
<artifactId>spatial4j</artifactId>
<version>0.8</version>
</dependency>
Initially I didn't have the second dependency in the pom.xml file.
Is there any way to get OpenCV from repository? Which artifact should I add to pom.xml? Every tutorial I'd found is from '14 and it seems like something changed - they say it is'nt in official Maven repository yet, but I've found entry:
<!-- https://mvnrepository.com/artifact/nu.pattern/opencv -->
<dependency>
<groupId>nu.pattern</groupId>
<artifactId>opencv</artifactId>
<version>2.4.9-7</version>
</dependency>
Sadly, I get error
Caused by: java.lang.UnsatisfiedLinkError: no opencv_java249 in java.library.path
when I'm using System.loadLibrary(Core.NATIVE_LIBRARY_NAME). Can I add this library in a way that would make my project include it and 'forget' about manually adding it to classpath?
Add the following dependency in your POM file:
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-0</version>
</dependency>
and replace the following lines:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
with
nu.pattern.OpenCV.loadShared();
This should solve the problem in WINDOWS also. Happy Coding.
This worked for me.
nu.pattern.OpenCV.loadLibrary();
I'm using following maven dependency
<dependency>
<groupId>nu.pattern</groupId>
<artifactId>opencv</artifactId>
<version>2.4.9-4</version>
</dependency>
Try this, see if it works:
nu.pattern.OpenCV.loadShared();
System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
More info here in API section: https://github.com/patternconsulting/opencv
Also have 2.4.9-7 opencv dependency.
There is currently no official way to use the official Java bindings for OpenCV as a Maven dependency (as already mentioned in the comments, the Maven artifact was already requested in #4588, but is still unattended). Nevertheless, there are 3 possible approaches to your problem:
java.lang.UnsatisfiedLinkError was thrown because you need to install the binding's binaries (that is "opencv_java") separately. Most likely, that unofficial artifact does not include them (or not the ones compatible with your system). In order to build the bindings:
git clone the OpenCV repository.
git checkout the intended version (it appears that you are using version 2.4.9, although more recent versions are available)
Follow the instructions here to build OpenCV and its Java bindings, thus yielding a dynamically linked library ("opencv_java249.dll", "libopencv_java249.so", or something else depending on your OS).
Copy the shared library file to your java.library.path (again, this variable is system-dependent, but can be defined when running your application). At this point you should be ready to use that artifact.
An alternative is to use other bindings: the JavaCPP presets for OpenCV seem to work just as nicely as the official ones, and these are registered in maven (binaries for various platforms included!). Just remember that the API may not be exactly the same.
This solution may sound too far out, but it has legitimately worked for me in the past. Basically, you can avoid using the bindings: implement your solution in C++, then either link it with the JVM via JNI or make it a separate application, used by the main application via other mechanisms of your system (process spawning, I/O channels, you name it). For instance, I have once made a service component for feature extraction that other programs would connect to via ZeroMQ sockets.
Just use it
nu.pattern.OpenCV.loadShared();
write a class with this static void method
class Test {
public static void loadOpenCVNativeLibrary() {
nu.pattern.OpenCV.loadShared();
}
}
and after call it in your application class (with static main) for web application (spring boot for example) like this
static {
Test.loadOpenCVNativeLibrary();
}
...
public static void main(String[] args) throws UnknownHostException {
}
All you need:
install jar in local maven repository with:
mvn install:install-file -Dfile=C:\opencv411\build\java\opencv-411.jar -DgroupId=org -DartifactId=opencv -Dversion=4.1.1 -Dpackaging=jar
create a dependency in pom.xml:
<dependency>
<groupId>org</groupId>
<artifactId>opencv</artifactId>
<version>4.1.1</version>
</dependency>
Now that jar is on, we need to somehow add the OpenCV libraries. I did this by adding the lib folder in java.library.path to the maven-surefire plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Djava.library.path=${project.build.outputDirectory}/lib</argLine>
</configuration>
</plugin>
public static void main(String[] arges) throws MalformedURLException,
IOException, Exception {
loadLibraries();
// create and print on screen a 3x3 identity matrix
System.out.println("Create a 3x3 identity matrix...");
Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("mat = " + mat.dump());
// prepare to convert a RGB image in gray scale
String location = "resources/Poli.jpg";
System.out.print("Convert the image at " + location + " in gray scale... ");
// get the jpeg image from the internal resource folder
Mat image = Imgcodecs.imread(location);
// convert the image in gray scale
Imgproc.cvtColor(image, image, Imgproc.COLOR_RGB2GRAY);
// write the new image on disk
Imgcodecs.imwrite("resources/Poli-gray.jpg", image);
System.out.println("Done!");
}
private static void loadLibraries() {
try {
InputStream in = null;
File fileOut = null;
String osName = System.getProperty("os.name");
// String opencvpath = System.getProperty("user.dir");
String opencvpath = "C:\\opencv411\\build\\java\\";
if (osName.startsWith("Windows")) {
int bitness = Integer.parseInt(System.getProperty("sun.arch.data.model"));
if (bitness == 32) {
opencvpath = opencvpath + "\\x86\\";
} else if (bitness == 64) {
opencvpath = opencvpath + "\\x64\\";
} else {
opencvpath = opencvpath + "\\x86\\";
}
} else if (osName.equals("Mac OS X")) {
opencvpath = opencvpath + "Your path to .dylib";
}
System.out.println(opencvpath);
// System.out.println("Core.NATIVE_LIBRARY_NAME = " + Core.NATIVE_LIBRARY_NAME);
System.out.println("Core.NATIVE_LIBRARY_NAME = " + "opencv_java411.dll");
// System.load(opencvpath + Core.NATIVE_LIBRARY_NAME + ".dll");
System.load(opencvpath + "opencv_java411.dll");
} catch (Exception e) {
throw new RuntimeException("Failed to load opencv native library", e);
}
}
For those who wants to use OpenCV 3.2 in MacOs environment, you can use following repository definition:
<repositories>
<repository>
<id>kodfarki</id>
<url>https://raw.githubusercontent.com/kodfarki/repository/master/</url>
</repository>
</repositories>
There is also an example project in https://github.com/kodfarki/opencv-example.
To use this example project, you still need to install OpenCV binaries
brew tap homebrew/science
brew install opencv3 --with-java --with-contrib
For windows there was a problem with #Sachin Aryal's answer. The answer by #Anirban Chakraborty is a very good hint. But, there was still issues at runtime as described in this thread.
Finally replacing OpenCV.loadShared(); with OpenCV.loadLocally(); worked for me.
How can I set up my project in Intellij to use the ROME library to read a RSS Feed?
So far, I've developed the following:
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
import java.net.URL;
public class ReadRSS {
public static void main(String[] args) {
String urlString = "http://news.ycombinator.com/"
boolean ok = false;
if (args.length==1) {
try {
URL feedUrl = new URL(urlString);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
System.out.println(feed);
ok = true;
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("ERROR: "+ex.getMessage());
}
}
if (!ok) {
System.out.println();
System.out.println("FeedReader reads and prints any RSS/Atom feed type.");
System.out.println("The first parameter must be the URL of the feed to read.");
System.out.println();
}
}
}
But, I get multiple errors when running my code, mainly of the variant:
.. java:package com.sun.syndication.feed.synd does not exist..
How do I import the package in Intellij? Managed to import this my adding jar in my project structure.
But the next problem is: I can't access org.jdom.Document - though I have installed jdom in my project structure. The error I get is
Error:(16, 38) java: cannot access org.jdom.Document class file for
org.jdom.Document not found
How can I resolve this?
If you're using Maven or gradle add the dependency in your configuration file (ex. pom.xml in Maven) and do a build/install to download your dependencies. It should work fine after that. Dependency info is here: http://mvnrepository.com/artifact/rome/rome/0.9
Otherwise add the jar (downloadable from the link above) manually to your project. Look at the first answer in this question to see how to do this: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
I'm a developer of the ROME team. The latest version is ROME 1.5. It can be obtained from the central maven repository: http://search.maven.org/#artifactdetails%7Ccom.rometools%7Crome%7C1.5.1%7Cjar
The groupId has changed to com.rometools in v1.5.0.#
I highly recommend you to use Maven, Gradle or another build tool that is able to resolve transitive dependencies so you won't have to collect all dependencies manually.
i want to query existdb from Java. i know there are samples but where can i get the necessary packages to run the examples?
in the samples :
import javax.xml.transform.OutputKeys;
import org.exist.storage.serializers.EXistOutputKeys;
import org.exist.xmldb.EXistResource;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Database;
import org.xmldb.api.modules.XMLResource;
where can i get these ?
and what is the right standard connection string for exist-db? port number etc
and YES, i have tried to read the existdb documentation, but those are not really understandable for beginners. they are confusing.
All i want to do is write a Java class in eclipse that can connect to a exist-db and query an xml document.
Your question is badly written, and I think you are really not explaining what you are trying to do very well.
If you want the JAR files as dependencies directly for some project then you can download eXist and get them from there. Already covered several times here, which JAR files you need as dependencies is documented on the eXist website and links to that documentation have already been posted in this thread.
I wanted to add, that if you did want a series of simple Java examples that use Maven to resolve the dependencies (which takes away the hard work), then when we wrote the eXist book we provided just that in the Integration Chapter. It shows you how to use each of eXist's different APIs from Java for storing/querying/updating etc. You can find the code from that book chapter here: https://github.com/eXist-book/book-code/tree/master/chapters/integration. Included are the Maven project files to resolve all the dependencies and build and run the examples.
If the code is not enough for you, you might also want to consider purchasing the book and reading the Integration Chapter carefully, that should answer all of your questions.
i ended up with a maven project and imported some missing jars (like ws.commons etc) by manually installing them on maven.
the missing jars i copied from the existdb installation path on my local system.
then i got it to work.
from: http://exist-db.org/exist/apps/doc/devguide_xmldb.xml
There are several XML:DB examples provided in eXist's samples
directory . To start an example, use the start.jar jar file and pass
the name of the example class as the first parameter, for instance:
java -jar start.jar org.exist.examples.xmldb.Retrieve [- other
options]
Example: Retrieving a Document with XML:DB
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
import javax.xml.transform.OutputKeys;
import org.exist.xmldb.EXistResource;
public class RetrieveExample {
private static String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";
/**
* args[0] Should be the name of the collection to access
* args[1] Should be the name of the resource to read from the collection
*/
public static void main(String args[]) throws Exception {
final String driver = "org.exist.xmldb.DatabaseImpl";
// initialize database driver
Class cl = Class.forName(driver);
Database database = (Database) cl.newInstance();
database.setProperty("create-database", "true");
DatabaseManager.registerDatabase(database);
Collection col = null;
XMLResource res = null;
try {
// get the collection
col = DatabaseManager.getCollection(URI + args[0]);
col.setProperty(OutputKeys.INDENT, "no");
res = (XMLResource)col.getResource(args[1]);
if(res == null) {
System.out.println("document not found!");
} else {
System.out.println(res.getContent());
}
} finally {
//dont forget to clean up!
if(res != null) {
try { ((EXistResource)res).freeResources(); } catch(XMLDBException xe) {xe.printStackTrace();}
}
if(col != null) {
try { col.close(); } catch(XMLDBException xe) {xe.printStackTrace();}
}
}
}
}
On the page http://exist-db.org/exist/apps/doc/deployment.xml#D2.2.6 a list of dependencies is included; unfortunately there is no link to this page on http://exist-db.org/exist/apps/doc/devguide_xmldb.xml (should be added);
The latest xmldb.jar documentation can be found on http://xmldb.exist-db.org/
All the jar files can be retrieved by installing eXist-db from the installer jar; the files are all in EXIST_HOME/lib/core
If you work with a maven project, try adding this to your pom.xml
<dependency>
<groupId>xmldb</groupId>
<artifactId>xmldb-api</artifactId>
<version>20021118</version>
</dependency>
Be aware that the release date is 2002.
Otherwise you can query exist-db via XML-RPC