Hi I'm trying to make a game in java that gives users the option to a joystick or gamepad to control movement. So I found something called "JInput" that is suppose to make it easy to detect all connected game controllers. The problem is that when I run it in Eclipse I get the following error: "java.lang.UnsatisfiedLinkError: no jinput-dx8 in java.library.path".
My code is the following:
import net.java.games.input.*;
public class ListControllers
{
public static void main(String[] args)
{
System.out.println("JInput version: " + Version.getVersion());
ControllerEnvironment ce =
ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
if (cs.length == 0) {
System.out.println("No controllers found");
System.exit(0);
}
// print the name and type for each controller
for (int i = 0; i < cs.length; i++)
System.out.println(i + ". " +
cs[i].getName() + ", " + cs[i].getType() );
} // end of main()
} // end of ListControllers class
I'm currently developing in Windows 7 environment. Any help would be really appreciated.
You should set java.library.path property to point to the directory containing native dlls of JInput.
You can do it by adding -Djava.library.path=x (where x is your path) to the command line or to the "VM arguments" field of "Run configurations" dialog in Eclipse.
Related
I've written a rather simple method for my paper/spigot Minecraft server plugin that detects potential lag machines under construction.
The issue I have is that I want to send a single chat message that, when clicked once, will first run a /vanish command on behalf of the clicker.
Then if (and only if) the vanish was successful, I want to run a teleport command to a location included along with the specific instance of the ClickEvent.
Both of those commands need to be completed from the single user click event.
For reference here is the method that calls notifyOps() and includes the TextComponent in question, msg
if (LagMats.contains(blockType) || mat.contains("MINECART") || mat.contains("DOOR")) {
int counter = 0;
for (Material thisMat: LagMats) {
if (thisMat != Material.GRAVEL) {
counter += Utilities.blockCounter(block.getChunk(), thisMat);
}
}
TextComponent warn = new TextComponent("WARN "); warn.setBold(true);
warn.setColor(ChatColor.RED);
TextComponent msg = new TextComponent("Potential lag-machine at " +
block.getX() + ", " + block.getY() + ", " + block.getZ() + " in " + dimension +
" by " + placer_name + " with UUID: " + placer.getUniqueId());
String cmd = "/execute in " + env + " run tp #s " +
block.getX() + " " + block.getY() + " " + block.getZ();
msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, cmd));
if (counter > 256) {
Utilities.notifyOps(new TextComponent(warn, msg));
}
}
Oh and the actual little code of notifyOps where the TextComponent is used in a message:
// send a message to all online ops and console
public static boolean notifyOps(TextComponent msg) {
if (msg == null) return false;
for (Player thisPlayer: Bukkit.getOnlinePlayers()) {
try {
if (thisPlayer.isOp()) thisPlayer.spigot().sendMessage(msg);
} catch (Exception e) {return false;}
}
System.out.println(msg.getText());
return true;
}
So I want to have the user click just once, run two commands, the second only if the first succeeds, and would be best if it could be done within the try block the message is sent from.
I could write a custom command for this purpose, and then just run that command, but I rather avoid adding classes for such a small addition if it's actually possible and I just have no idea.
Thanks for any advice or help!
There is no way of doing that without writing a custom command...
This is impossible because the ClickEvent and HoverEvent are entirely client-side. That means that there are no packets sent from the Player to the server. Therefore, it is impossible to callback the click of the Player and call a method to perform what you are trying to do.
You may notice that all the ClickEvent.Actions do not affect the server. OPEN_URL, OPEN_FILE, RUN_COMMAND, SUGGEST_COMMAND, CHANGE_PAGE and COPY_TO_CLIPBOARD are all actions taken on the client-side.
The only way here is to make the client send a command to the server which will trigger a method.
I have a newbie problem with taking the Cplex library in Eclipse,
Error: Could not find or load main class Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64
Caused by: java.lang.ClassNotFoundException: Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64
I added cplex.jar from external libraries and also added the native path by editing it,
CPLEX library path error in eclipse
under VMArguments I added,
-Djava.library.path=C:\Program Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64
where cplex12100.dll stands. I managed to work with it before but I couldn't find why it is not working right now.
Everything is 64bit.
Thanks in advance!
Your error message references the following path:
Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64
Notice that it does not start with "C:Program Files". My guess is that you need to put quotes around the path you are providing, like so:
-Djava.library.path="C:\Program Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64"
This should allow Java to handle your path which includes a space character.
thanks for the answer,
Unfortunately, I forgot to add that I already tried that, but it gives another error when I try like that.
Error: Unable to initialize main class model(my package name).model(my class name)
Caused by: java.lang.NoClassDefFoundError: ilog/concert/IloException
Here is part of my code, I cut half of it(after ...) since I guess it is unrelated to the question.
package model;
import ilog.concert.*;
import ilog.cplex.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.*;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
public class model {
public static void main(String[] args) throws Exception {
long startTime = Instant.now().toEpochMilli();
int a = 45; //matrisin boyutu
int b = 45; //matrisin 2. boyutu
int maxdistance = 90; //mesela 90 dan küçük deðerler
int depot = 0;
double alfa = 0.9;
double beta = 0.1;
float[][] distance = new float[a][b]; // bunu scanner dan çektik
int m = 3;
int C = 1200;
System.out.println();
System.out.println("m : " + m + " C : " + C );
System.out.println();
ArrayList<ArrayList> Nlist = new ArrayList<ArrayList>();
Scanner reader = null;
File burdurData = new File("burdur45.txt");
...
try {
long timeElapsed = endTime - startTime;
System.out.println("Execution time in milliseconds: " + timeElapsed);
System.out.println("Execution time in seconds: " + timeElapsed/1000);
} // try'ýn parantezi
catch (IloException exc) {
System.out.println(exc);
System.out.println("sýkýntý");
}
}
}
surely you should edit your question. In fact, for getting error:
java.lang.NoClassDefFoundError: ilog/concert/IloException
I had this error before and I solved it just by importing cplex.jar in ClassPath section of my project Java Build Path not in ModulePath. Also set Native Library Location path to cplex's dlls folder too. Furthermore you can check your details in java configuration->show command line too.
The entire process is working almost properly but I'd like to add some debug for a specific issue.
for (int j = 0; j < end.length; j++) {
String remove = end[j].trim();
if (cName.endsWith(remove)) {
mPhone = cName.substring(0, cName.length() - remove.length()).trim();
}
System.out.println(cName + ", " + remove + ", " + mPhone);
}
Where should I expect to see the output? It is not in the Script Output tab, or the DBMS Output tab, or the General tab.
Its been some time since I've looked into it my self but as per this other post, you may need to execute
set serveroutput on size 10000
exec dbms_java.set_output(10000)
and then try executing.
I have taken a written sample from this link to write my Python + Java integration code.
http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html
The code looks like below.
package org.jython.book.interfaces;
import org.jython.book.interfaces.JythonObjectFactory;
import org.python.core.Py;
import org.python.core.PyString;
import org.python.core.PySystemState;
public class Main {
public static void main(String args[]) {
String projDir = System.getProperty("user.dir");
String rootPath = projDir + "/src/org/jython/book/interfaces/";
String modulesDir = projDir + "/src/org/jython/book/interfaces/";
System.out.println("Project dir: " + projDir);
PySystemState sysSt = Py.getSystemState();
JythonObjectFactory factory = new JythonObjectFactory(sysSt, BuildingType.class, "Building", "Building");
BuildingType building = (BuildingType) factory.createObject();
building.setBuildingName("BUIDING-A");
building.setBuildingAddress("100 MAIN ST.");
building.setBuildingId(1);
System.out.println(building.getBuildingId() + " " +
building.getBuildingName() + " " +
building.getBuildingAddress());
}
}
When I run this code, it throws an error that it did not find the python module. I have kept the .py and .pyc files under the path provided as 'modulesDir'.
The literature says that "the requested module must be contained somewhere on the sys.path"; however, I did not understand how this can be set from this Java program. Can someone please provide some help?
Project dir: /Users/eclipsews/PythonJava
Exception in thread "main" ImportError: No module named Building
Hi found the answer to this issue!
Added the PySystemState.initialize method where I explicitly provide the "python.path" property, which is initialized to my project's path, where python modules are available.
private static Properties setDefaultPythonPath(Properties props) {
String pythonPathProp = props.getProperty("python.path");
String new_value;
if (pythonPathProp == null) {
new_value = System.getProperty("user.dir") + "/src/org/jython/book/interfaces/";
}
props.setProperty("python.path", new_value);
return props;
}
Properties props = setDefaultPythonPath(System.getProperties());
PySystemState.initialize( System.getProperties(), props, null );
This produces the correct output as follows:
module=<module 'Building' from '/Users/eclipsews/PythonJava/src/org/jython/book/interfaces/Building$py.class'>,class=<class 'Building.Buildin
g'>
1 BUIDING-A 100 MAIN ST.
Does anyone know how to modify the Jenkins/Hudson node labels in a non-manually way? I mean, thorough an API like the CLI API that this tool offers (without restarting Jenkins/Hudson of course).
My guess is that the best option is using a Groovy script to enter into the Jenkins/Hudson guts. Executing something like:
java -jar -s HUDSON_URL:8080 groovy /path/to/groovy.groovy
Being the content of that script something like:
for (aSlave in hudson.model.Hudson.instance.slaves) {
labels = aSlave.getAssignedLabels()
println labels
**aSlave.setLabel("blabla")** // this method doesn't exist, is there any other way???
}
Thanks in advance!
Victor
Note: the other answers are a bit old, so it could be that the API has appeared since then.
Node labels are accessed in the API as a single string, just like in the Configure screen.
To read and write labels: Node.getLabelString() and Node.setLabelString(String).
Note that you can get the effective labels as well via: Node.getAssignedLabels(), which returns a Collection of LabelAtom that includes dynamically computed labels such as the 'self-label' (representing the node name itself).
Last, these methods on the Node class are directly accessible from the slave objects also, e.g. as a System Groovy Script:
hudson = hudson.model.Hudson.instance
hudson.slaves.findAll { it.nodeName.equals("slave4") }.each { slave ->
print "Slave $slave.nodeName : Labels: $slave.labelString"
slave.labelString = slave.labelString + " " + "offline"
println " --> New labels: $slave.labelString"
}
hudson.save()
I've found a way to do this using the Groovy Postbuild Plugin.
I have a Jenkins job that takes a few parameters (NodeToUpdate, LabelName, DesiredState) and executes this content in the Groovy Postbuild Plugin:
nodeName = manager.envVars['NodeToUpdate']
labelName = manager.envVars['LabelName']
set = manager.envVars['DesiredState']
for (node in jenkins.model.Jenkins.instance.nodes) {
if (node.getNodeName().equals(nodeName)) {
manager.listener.logger.println("Found node to update: " + nodeName)
oldLabelString = node.getLabelString()
if (set.equals('true')) {
if (!oldLabelString.contains(labelName)) {
manager.listener.logger.println("Adding label '" + labelName + "' from node " + nodeName);
newLabelString = oldLabelString + " " + labelName
node.setLabelString(newLabelString)
node.save()
} else {
manager.listener.logger.println("Label '" + labelName + "' already exists on node " + nodeName)
}
}
else {
if (oldLabelString.contains(labelName)) {
manager.listener.logger.println("Removing label '" + labelName + "' from node " + nodeName)
newLabelString = oldLabelString.replaceAll(labelName, "")
node.setLabelString(newLabelString)
node.save()
} else {
manager.listener.logger.println("Label '" + labelName + "' doesn't exist on node " + nodeName)
}
}
}
}
I've not seen a way yet to change the slave label either.
I've taken to editing the main config.xml file and issuing a reload from the CLI.
This has it's own problems though - any jobs currently running are lost until the next jenkins restart - see https://issues.jenkins-ci.org/browse/JENKINS-3265