I am trying to make use of the pre-trained model with the code given here https://github.com/uwnlp/EasySRL.
For the basic usage of the code it says one should use
java -jar easysrl.jar --model modelFolder
The issue is there does not seem to be a an easysrl.jar anywhere. I'm new to java and am unsure as to how I should proceed. As an attempt I tried to convert one of the folders called easySRL into a jar fie but this failed - I'm not really convinced this was what was intended anyway.
Related
I have Jar file which dependency on another project jar. Both are thin jars and are at same location. 1st jar has manifest file which list second jar in its class-path property.
In 1st jar I am launching second jar as a process using ProcesBuilder class in java. To do so I need absolute path of second jar. In 1st jar i have class XClient
If I do XClient.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
i am getting absolute path of 1st jar. Then I can split and add the name of second jar(hard-coded) to build the absolute path
In second jar I have class XServer
If I do
XServer .class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
Its throws exception
I am not sure if I am doing the right approach but my goal is very clear I wanted to get the absolute path to the dependent jar.
Please help
I tried to use the same approach (but used File file=new File(this.getClass().getProtectionDomain().getCodeSource().toUri()) instead of getPath()) but this can fail in different ways:
when the class is inside a jar the File object points to the jar instead the folder the jar is in - so an if(file.isFile()) file=file.getParentFile(); is needed to get the directory instead of the jar file
when the jar file is loaded by something other than the usual URLClassLoader (last time I tried was back in 1.8 - and I only know that since Jigsaw the main classloader can't be cast to an URLClassLoader anymore) this may will return some unspecified result, if at all, so actual behaviour depends on the very system setup - wich can make it difficult to debug when used on a remote system not under your control
UNC paths (Windows shares) are error prone by themselfs - adding another layer on top of it (java) just add a lot of potential other pitfalls you all have to test and debug - wich often ends up you tell the client what to use and how to setup instead of design your code to follow the java principle: "write once, compile once, run everywhere" (btw: this also applies even if you "mount" a network share so you can address it by a local drive letter instead of a remote network path - but this even causes problems when you try to link two machines where one is a clone of the other)
as already mentioned as comment: "it doesn'T work" is not a usefull or meaningfull description - if you get an error message (in this case as you mentioned an exception stacktrace) post it along with the code wich produced it (if accessible)
How I solved my problem? I just ask the user for the directory / file by a swing JFileChooser. Yes, this isn't fool proof and maybe not the best way - but it works as swing still ships with SE JVM (instead of FX).
If you want to find a path use Class.getResource() and let java do the work, pretty much like crypto: don'T do your own.
Aside from all that: Your mentioned "usecase" doesn'T require what you try to do. You said that the server is already in the classpath - so it gets loaded on startup and you can access the XServer class. The easiest way instead of forking another process is to just run it in another thread. If you know wich class has the main (the manifest of the server.jar will tell you) and you can access it in classpath just do something like this:
Thread serverThread=new Thread(new Runnable()
{
public void run()
{
String[] args=Arrays.asList("required", "parameters");
XServer.main(args);
}
});
serverThread.start();
If no paramters required you can just pass an empty String array. As main() should not throw Exceptions (at least no checked ones) no exception should be needed.
Before all those comments are thrown at me: Yes, I am very well aware of possible issues with such approach like classpath issues (same classname in same packagename but different versions) and such it may be more feasible than try to figure out the absolute path and launch a fork / sub process.
Also: Starting another process may require to interact with its streams (provide required input into child process inputstream and read the child process outputstream and errorstream - otherwise the forked process may can "hang" as it waits for the pipelines to get cleared. It's a pain in the but to debug that kind of issue if it's not your own code and you can have a profiler and debugger attached to it to figure out why all just suddenly stopped to work.
If you really want to (I don't think there's any requirement forcing a "you need to") launch your server along with the client do it with a launch script outside of java but with os level stuff.
In this previous question, I was trying to rework some Matlab code and figure out a package called javaplex to be compatible with Octave; it uses Java, but is tooled for Matlab, hence that issue. Now in an interval of time, I was busy/running simulations, and hadn't gotten around to a final step - actually using the package, with most all of the difficulties worked out. It turns out that another step exists: I need to convert an Octave array to a Java array (although I'm not sure why this issue didn't come up in Matlab).
To do so, I have turned to this script, in which the comments indicate that when using it, it
Assumes the JIDT [Java Information Dynamics Toolkit] jar is already on the java classpath - you will get a java classpath error if this is not the case.
So I go to the JIDT GitHub page and download this package. Now I am not a very avid user of java, so I believe I am failing to see something fairly straightforward: I am not sure where the "JIDT jar" is that is referenced in the above block quote! I can't find such a particular jar file to put in Octave's java classpath. In this tutorial for JIDT, they say you need the "infodynamics.jar" file in the classpath (page 9). I'm not sure what jar file I should be looking for, and where. Any help understanding the nature, name and location of this jar file (within the infodynamics toolkit folder) would be appreciated!
As an inevitable follow-up question, because this will come up upon resolving this issue, I would like to clarify the following procedure is how to add a jar file to the Octave (static) java classpath (following this answer here, I wasn't sure if I was implementing correctly):
I create a file called "javaclasspath.txt" inside of the directory I use in Octave.
I enter the name of files as follows: "./path/to/your-file.jar"
I suppose my main issue here is where do I start the path (all the way back with "C:/..."?), and do I put this "javaclasspath.txt" file in the directory folder I will be using most of the time in Octave?
Edit: I cannot find "infodynamics.jar" as shown here:
The JIDT jar is named infodynamics.jar and it is located in the root of the downloads infodynamics-dist-1.4.zip file.
We bought a solution from a provider a couple of years ago, droped the .jar file in the standard location in IFS /QIBM/UserData/Java400/ext/ and we have been working correclty ever since with this.
However a couple of months ago the provider released a new .jar with some new functions we would like to use. However they also changed the names of several classes and methods that we are using.
So what we were thinking of doing, if possible, is define a path on which the old programs when they need to use that .jar look for that .jar in the defined path. And for the new programs that we want to use the new .jar file we wanted to have different path for that.
At this point I don't know if this is possible to do. I have been searching everywhere for this information without luck. So if someone around here as some clue it would be fantastic.
Thank you for your time.
Edit: So I was reading through your advices and I have these coments.
I already asked the supplier for assistance but since this wasn't designed for AS400 they don't provide support.
I tested the possibility of the classpath. I deleted the files from the /QIBM/UserData/Java400/ext/ and put them in /QIBM/JARS/old/ then I created a CL that did this:
ADDENVVAR ENVVAR(CLASSPATH) VALUE('/QIBM/JARS/old') REPLACE(*YES)
After I first executed this new CL then I tried a program that would use the .jar that I had in the location /QIBM/JARS/old and I got the error of the class not found. So either I did something wrong or this isn't actually a solution.
HotLicks do you mean that it is not possible to have users A1 and B1, and A1 using /QIBM/JARS/old/A.jar and B1 using /QIBM/JARS/new/A.jar at the same time?
You can adjust the Java classpath.
You probably want to redefine your extensions classpath when running with the new version of the jar.
Create a new directory -- i.e. /QIBM/UserData/MyJava/ext
Copy the jars files you need from /QIBM/UserData/Java400/ext to /QIBM/UserData/MyJava/ext
Add your new jar file to /QIBM/UserData/MyJava/ext.
When starting the Java program, use the following define to set the extensions directory: -Djava.ext.dirs=/QIBM/UserData/MyJava400
Note: You may need to adjust the directory based on the current settings of java.ext.dirs. You can find the current settings by running the following from QSHELL.
echo '!callmethod java.lang.System.getProperty(java.ext.dirs)' | java -cp /qibm/proddata/http/public/jt400/lib/jt400.jar com.ibm.as400.access.jdbcClient.Main jdbc:db2:localhost
Call returned /QOpenSys/QIBM/ProdData/JavaVM/jdk50/32bit/jre/lib/ext:/QIBM/UserData/Java400/ext
In my case, I would then set -Djava.extdirs=/QOpenSys/QIBM/ProdData/JavaVM/jdk50/32bit/jre/lib/ext:/QIBM/UserData/MyJava/ext
I have been searching the web trying to find the answer to my question, but everywhere I look seems to have too complex of a solution for a beginner like me. I have been working on this project, and just now realized that I should've made a package, or something like that. The thing is though, my program was working fine until I started dabbling with it, and now it won't work at all. I am getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: BubbleSort. class
Caused by: java.lang.ClassNotFoundException: BubbleSort.class
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at java.lang.ClassLoader.loadClass(ClassLoader.java:672)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at ``java.lang.ClassLoader.loadClass(ClassLoader.java:638)
Could not find the main class: BubbleSort.class. Program will exit.
Here's how my "path" looks, if I am not mistaken. I am connected to my school's Z: drive through a remote connection, and from there I have a folder called myFirstname_Lastname_A4,
which then leads me to another folder called sortingzz which I believe is supposed to have only my source files, but it also ended up with my class files in there whenever I compiled. So here's what I am doing to compile.
cd myFirstname_Lastname_A4/sortingzz
javac *.java (Works fine, this is where I end up with my Class files inside of my sortingzz folder)
java * (This is where I get the error)
I am pretty sure I am just trying to run the program wrong. Before I started messing around with stuff I wasn't ready for, I used to just run the file with my main function in it, like this
javac SortingImplementation.java
java SortingImplementation
And that for the most part worked fine, but I started having trouble calling certain classes from other classes, so thats when I found out I was suppose to do the packaging and importing stuff.
In case that is the issue, I have on the top line of every source file:
package sortingzz;
and I am importing like this:
import sortingzz.*;
This is correct, right?
UPDATE:
I decided to give up on class pathing and trying to package everything, because as usual, I am getting responses that are way over my head, and to be honest I don't think it is necessary.
After removing package and importing from everything, and once again compiling using javac *., it actually compiles this time. However whenever I try to run my class with the main in it, SortingImplementation, it tells me that
Could not find the main class: SortingImplementation. Program will exit.
I don't get it, I am looking at the SortingImplementation.class right now, with all the other classes and java files, so I am not sure what it's trying to do.
javac *.java is fine. This will compile your files. However, you only need to run the file with your main method in it: java MainClass
You say that you are using packages to organize the classes. In this case you need to set the class path using the -cp flag.
javac -cp /path/to/parent/of/package classname.java
and
java classname
Also, your main class should be declared public and should have a main()
NoClassDefFoundError occures when a class was recognised in compile time but was not available during runtime.
So the JVM can't find your class in the classpath.
using -cp flag to specify where your package is should work.
the commanc javac *.java compiles all found java files to corresponding .class files. If you all your classfiles are in the same folder, which they should, you just run your regular java SortingImplementation command.
java * would, a bit depending on your OS, yield in an undesired command. For instance, on Linux it would be expanded by the OS to java SortingImplementation.java SortingImplementation.class BubbleSort. The last one is a directory, which ofcourse is not an executable class.
My first attempt at jython is a java/jython project I'm writing in eclipse with pydev.
I created a java project and then made it a pydev project by the RightClick project >> pydev >> set as... you get the idea. I then added two source folders, one for java and one for jython, and each source folder has a package. And I set each folder as a buildpath for the project. I guess I'm letting you know all this so hopefully you can tell me wether or not I set the project up correctly.
But the real question is: how do I get my jython code made into a class file so the java code can use it? The preferred method would be that eclipse/pydev would do this for me automatically, but I can't figure it out. Something mentioned in the jython users guide implies that it's possible but I can't find info on it anywhere.
EDIT: I did find some information here and here, but things are not going too smooth.
I've been following the guide in the second link pretty closely but I can't figure out how to get jythonc to make a constructor for my python class.
Jythonc doesn't exist anymore, it has been forked off to another project called Clamp, but with that said...
...you can pre-compile
your python scripts to .class files
using:
jython [jython home]/Lib/compileall.py
[the directory where you keep your
python code]
Source - Jython Newsletter, March 2009
When I fed it a folder with Python 2.7 code (knowing it would fail in Jython 2.5) it did output a .class file, even though it doesn't function. Try that with your Jython scripts. If it works, please let us know, because I'll be where you are soon enough.
Once you're that far, it isn't hard to convert your command line statement to an External Tool in PyDev that can be called as needed.
Following the "Accessing Jython from Java Without Using jythonc" tutorial it became possible to use the jython modules inside java code. The only tricky point is that the *.py modules do not get compiled to *.class files. So it turns out to be exotic scripting inside java. The performance may of course degrade vs jythonc'ed py modules, but as I got from the jython community pages they are not going to support jythonc (and in fact have already dropped it in jython2.5.1).
So if you decide to follow non-jythonc approach, the above tutorial is perfect. I had to modify the JythonFactory.java code a bit:
String objectDef = "=" + javaClassName + "(your_constructor_params here)";
try {
Class JavaInterface = Class.forName(interfaceName);
System.out.println("JavaInterface=" + JavaInterface);
javaInt =
interpreter.get("instance name of a jython class from jython main function").__tojava__(JavaInterface);
} catch (ClassNotFoundException ex) {
ex.printStackTrace(); // Add logging here
}