I've been searching for two days now trying to get PyDev to recognize my external .JAR (It's obfuscated for protection), however no matter what I do it doesn't want to work. I've read over the documentation for nearly a hour straight trying to get it to work.
I'm helping to work on an emulation server which uses Jython for scripting. I can compile and run the emulation server with the scripts working just fine however, without using autocompletion for the methods inside the engine part of the server which is obfuscated in a external .jar.
Here is an example code of a script which uses methods from the obfuscated .JAR (which isn't working with autocomplete, so I have to navigate through the package explorer to find the method I want to use):
import sys
def CreateStartingCharacter(core, object):
testObject = core.objectService.createObject('object/weapon/ranged/rifle/shared_rifle_t21.iff', object.getPlanet())
testObject.setCustomName('This is a Jython Rifle')
testObject.setStringAttribute('crafter', 'Light')
inventory = object.getSlottedObject('inventory')
inventory.add(testObject)
testClothing = core.objectService.createObject('object/tangible/wearables/cape/shared_cape_rebel_01.iff', object.getPlanet())
testClothing.setCustomName('Test Cape')
testCloak = core.objectService.createObject('object/tangible/wearables/robe/shared_robe_jedi_dark_s05.iff', object.getPlanet())
testCloak.setCustomName('Test Cloak')
inventory.add(testClothing)
inventory.add(testCloak)
return
This script is executed by the following command in Java (core is the class inside the external JAR, obfuscated)
core.scriptService.callScript("scripts/", "demo", "CreateStartingCharacter", object);
object is...
CreatureObject object = (CreatureObject)core.objectService.createObject(sharedRaceTemplate, core.terrainService.getPlanetList().get(0));
Like I said above, all of those methods that I used in the script were from the obfuscated JAR which isn't working with autocomplete. However, I can use a method that isn't in that JAR just fine such as:
from resources.common import RadialOptions
from services.sui import SUIWindow
from services.sui.SUIWindow import Trigger
from java.util import Vector
import sys
def createRadial(core, owner, target, radials):
radials.clear()
bank = owner.getSlottedObject('bank')
if bank:
radials.add(RadialOptions(0, 21, 1, ''))
radials.add(RadialOptions(0, 7, 1, ''))
radials.add(RadialOptions(1, RadialOptions.bankTransfer, 3, '#sui:bank_credits'))
radials.add(RadialOptions(1, RadialOptions.bankitems, 3, '#sui:bank_items'))
if owner.getBankCredits() > 0:
radials.add(RadialOptions(1, RadialOptions.bankWithdrawAll, 3, '#sui:bank_withdrawall'))
if owner.getCashCredits() > 0:
radials.add(RadialOptions(1, RadialOptions.bankDepositAll, 3, '#sui:bank_depositall'))
return
... and using RadialOptions. control+space will show me all the methods.
Help would be much appreciated. At this point I feel that it's not working because the JAR file is obfuscated or something like that. And yes, I've already added it to my PYTHONPATH and updated the interpreter, just like with the bin folder for my project.
Related
To start things off, I am entirely new to Java. I'm a C#/Powershell guy. A client at my IT Firm had an issue with a java program that they were executing on a daily basis that was having issues. According to Windows, the original program was written in April of 2011. I was able to unzip the file and pulled out all of the java files. I then rebuilt the program's structure in NetBeans and am getting ready to start editing. However, each *Test.java file is unable to import junit.framework.TestCase. In the original program file, each of these files were in the same folders as their associated files. From what I can tell, that is not best practices but it was the folder structure I found in the *.jar file I pulled them from. i.e.:
+ Source Packages
|
+--+ Folder
|
+--Example.java
|
+--ExampleTest.java
This leads me to 2 potential issues:
Reading similar threads regarding junit.framework "does not exist", there is mention of adding the junit.jar to the POM or adding the dependency to maven. For NetBeans, how do I do this? Using the "Add Dependency" menu, I am unable to find a "junit.framework" and there is 125,000 results for junit that I am unsure which one I need. Any insights? At the time of the original program's writing, v3 and v4 were both released, although v3.8.1 remained in use for some time beyond the adoption of v4.
For its use-case, see below. I assume all the errors are related to the junit import, so I included them as comments.
package com.example.program;
import java.util.Properties;
import junit.framework.TestCase;
/* Import files specific to program */
public class ExampleTest extends TestCase { //Cannot find symbol (class) "TestCase"
private Properties config = null;
#Override //Error: method does not override or implement a method from a supertype
/* SetUp function/method w/out any issues, creates config Properties object */
public void testExample(){
String line = "*"; // some csv line being parsed
CSVLine csvLine = new CSVLine(line, config);
assertEquals(/* does stuff */); // Error: cannot find "symbol" (method) "assertEquals"
assertTrue(/* does stuff */); // Error: cannot find "symbol" (method) "assertTrue"
assertTrue(/* does stuff*/); // Error: cannot find "symbol" (method) "assertTrue"
}
}
Do I need to move these Test.java files into a folder under the Test Packages section of the POM? Why would the original program have them in the same directory as their counterparts? Does some aspect of compiling/building move them to the same location?
Due to some restrictions at my place of employment and lots of red tape, I am currently trying to access a JAR I've uploaded as a Java Resource in Oracle in order to call methods in my own Java source that runs out of the DB JVM.
I've uploaded the JAR and I can see the resource, the DB object is named "Trireme". My Java source is attempting to import this resource traditionally
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Test" AS
// select * from user_errors;
package x.x.x.node;
import io.apigee.trireme.core.NodeEnvironment;
import io.apigee.trireme.core.NodeScript;
...
NodeEnvironment env = new NodeEnvironment();
NodeScript script = env.createScript("my-test-script.js",
new File("my-test-script.js"), null);
....
But it is unable to do so. Is this even possible? Is there a different way to use the classes within the resource, and if so, how is it done? I'm unable to find a good example
EDIT:
To add to this, I've added noticed that if I comment out the code in the class and I do import io.apigee.trireme.core.* and I comment out the lines in the code, it does not fail. Not referencing a specific class lets it compile, but either way, I still get the missing symbol once new NodeEnvironment is called, or NodeEnvironment is mentioned in the import instead of *
I recently used decode_qr from this FEX submission to decode my QR code. It ran quite well one or two weeks ago, but today it generate an error for me:
Undefined function or variable 'BufferedImageLuminanceSource'
Error in decode_qr (line 34);
source = BufferedImageLuminanceSource(jig);
I just checked the zxing repository and found that some files were updated several days ago. So I guess the path of some imported file from the package has been changed.
Here is the importing code from the decode_qr function:
import com.google.zxing.qrcode.*;
import com.google.zxing.client.j2se.*;
import com.google.zxing.*;
import com.google.zxing.common.*;
import com.google.zxing.Result.*;
How can I get it to work again? Do I need to change the import paths?
Here's what I did to get it to work (Win 10 x64, R2017b, ZXing 3.3.1):
Downloaded the latest prebuilt .jar artifacts from Sonatype:
core.
javase.
Added the files to my dynamic java classpath using javaaddpath:
javaaddpath('G:\core-3.3.1.jar');
javaaddpath('G:\javase-3.3.1.jar');
% Verify using: javaclasspath('-dynamic');
Note:
To add folders to the static path, which MATLAB loads at startup, create a javaclasspath.txt file, as described in Static Path.
Generated some example QR code using unitag.io:
Tried to decode it using Lior Shapira's decode_qr:
>> out = decode_qr(qr)
out =
'https://stackoverflow.com/users/3372061/dev-il'
Full code:
function out = q47223578()
javaaddpath('G:\core-3.3.1.jar');
javaaddpath('G:\javase-3.3.1.jar');
% Verify using: javaclasspath('-dynamic');
qr = imread('https://i.stack.imgur.com/mA4eP.png');
out = decode_qr(qr);
Installation instructions: http://docs.opencv.org/doc/tutorials/introduction/desktop_java/java_dev_intro.html
I have downloaded everything. Everything seems to be working except when I run this sample program:
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to OpenCV " + Core.VERSION);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("m = " + m.dump());
}
}
I get the output:
m = [1, 0, 0;
0, 1, 0;
0, 0, 1]
(which I hope is right).
But I also get these error messages:
objc[63784]: Class CVWindow is implemented in both /Users/.../cv2.so and /Users/... /libopencv_java246.dylib. One of the two will be used. Which one is undefined.
objc[63784]: Class CVView is implemented in both /Users/.../cv2.so and /Users/.../libopencv_java246.dylib. One of the two will be used. Which one is undefined.
objc[63784]: Class CVSlider is implemented in both /Users/.../cv2.so and /Users/.../libopencv_java246.dylib. One of the two will be used. Which one is undefined.
objc[63784]: Class CaptureDelegate is implemented in both /Users/... /cv2.so and /Users/jsuit/opencv/lib/libopencv_java246.dylib. One of the two will be used. Which one is undefined.
I have tried moving the cv2.so file to another folder, but then the program won't compile.
The problem has to do, as far as I can make out, with a reference to the Python libraries (the .so version) that ends up included within the Java libraries themselves. This would seem to be a build configuration error (following the instructions does produce it).
I was able to eliminate the double-definition error by re-building the Java version without support for the Python libraries in it, using the following in the cmake step (all else the same):
cmake -D BUILD_SHARED_LIBS=OFF -D BUILD_NEW_PYTHON_SUPPORT=NO ..
The newly produced Java libraries and .jar work just as before, but without the error message.
(Note that I can't guarantee this won't cause other problems, especially if you want to do some sort of mixed-language programming, but it does produce libraries useful for Java and Eclipse. You can always build multiple versions of OpenCV, too, some with support for Python, some without, and use whichever one you like if you switch languages at some point.)
Hat tip: http://answers.opencv.org/question/16015/mac-opencv-246-java-exception/
I'm working on a server that is made off of Java. At certain points of time (ie someone clicks on a object in the game for example), the server will load a script made using Jython. I'm having trouble getting the script to work, mainly because one imports the module random. Here is the script:
from resources.common import RadialOptions
import sys
import random
def createRadial(core, owner, target, radials):
radials.add(RadialOptions(0, 21, 1, '')) #Use
radials.add(RadialOptions(0, RadialOptions.diceRoll, 3, '#dice/dice:dice_roll_single'))
return
def handleSelection(core, owner, target, option):
if option == RadialOptions.diceRoll or 21:
stringOptions = ['red', 'blue']
owner.sendSystemMessage('Your chance cube rolled the color ' + random.choice(stringOptions) , 0)
return
When the server is loaded up and the script is called, I receive an import error saying there is no module named "random". It doesn't matter what module I call that exists within Jython/Python, it won't except anything but sys and java classes.
I then went ahead and opened up a PyDev console and tried to see if I was able to import random. It was successful.
How come the PyDev console will let me import random or any other module, but not the server when it calls the script?
Try in PyDev entering:
import sys
print sys.path
then add the same to your script - before the problem and compare the two, if they are the same in both cases search the elements of both for random on your local machine and the one your server runs on.