profesorfalken / jhardware Goto Github PK
View Code? Open in Web Editor NEWGet crossplatform hardware details with Java
License: Apache License 2.0
Get crossplatform hardware details with Java
License: Apache License 2.0
Whenever i try to use this to my Minecraft plugin server i get this error:
java.lang.NoClassDefFoundError: org/jutils/jhardware/HardwareInfo
Hello,
Thanks for a interesting project!
I have some question about how jHardware works.
I noticed that JNA is in the Maven dependencies of the project (transitively though jSensors). But at the same time the read-me file says that JNA is not used. So can I use jHardware without having JNA on my classpath? Can I use some functionality from jHardware without JNA?
I also noticed jPowerShell in the dependencies. Does that mean that PowerShell must be installed on a Windows system for jHardware to work?
Is PowerShell and JNA the tools that jHardware uses to read hardware information? How does it work on Linux? Does it invoke other native commands to get information?
The read-me text says that jHardware is "using pure Java". I don't think this is accurate if you are in fact using JNA and calling native programs such as PowerShell to get information.
I think this information would be useful have in the read-me text!
Thank you!
When I run this code:
MemoryInfo memory = HardwareInfo.getMemoryInfo();
System.out.println("Total memory: " + memory.getTotalMemory());
System.out.println("Free memory: " + memory.getFreeMemory());
I get this:
Total memory: null
Free memory: 1177064
Running on Windows 10 Enterprise 2016 LTSB (64 bits)
java.lang.NumberFormatException: For input string: "63000 " at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.valueOf(Integer.java:766) at org.jutils.jhardware.info.processor.unix.UnixProcessorInfo.parseInfo(UnixProcessorInfo.java:68) at org.jutils.jhardware.info.processor.AbstractProcessorInfo.getInfo(AbstractProcessorInfo.java:29) at org.jutils.jhardware.info.processor.AbstractProcessorInfo.getInfo(AbstractProcessorInfo.java:25) at org.jutils.jhardware.HardwareInfo.getProcessorInfo(HardwareInfo.java:48)
There is a newline character in the temperature String that causes a NumberFormatException.
jHardware 0.6.3
WindowsMemoryInfo is using "FreePhysicalMemory" for total memory, while it is supposed to use "TotalPhysicalMemory" instead.
Related code snippet from WindowsMemoryInfo -
memoryDataMap.put("MemFree",
WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("FreePhysicalMemory"));
memoryDataMap.put("MemTotal", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("FreePhysicalMemory"));
Tests run: 7, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 49.295 sec <<< FAILURE!
getDisplayInfo(org.jutils.jhardware.HardwareInfoTest) Time elapsed: 0.421 sec <<< ERROR!
java.lang.NullPointerException
at org.jutils.jhardware.info.display.AbstractDisplayInfo.buildFromDataMap(AbstractDisplayInf
o.java:53)
at org.jutils.jhardware.info.display.AbstractDisplayInfo.getInfo(AbstractDisplayInfo.java:36
)
at org.jutils.jhardware.info.display.AbstractDisplayInfo.getInfo(AbstractDisplayInfo.java:28
)
at org.jutils.jhardware.HardwareInfo.getDisplayInfo(HardwareInfo.java:106)
at org.jutils.jhardware.HardwareInfoTest.getDisplayInfo(HardwareInfoTest.java:230)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java
:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.jav
a:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Results :
Tests in error:
getDisplayInfo(org.jutils.jhardware.HardwareInfoTest)
Tests run: 7, Failures: 0, Errors: 1, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:07 min
[INFO] Finished at: 2017-06-26T16:42:33+08:00
[INFO] Final Memory: 23M/271M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-t
est) on project jHardware: There are test failures.
I'm the lead maintainer for OSHI, a project that looks to have similar goals to yours in providing Java access to operating system/hardware information. The main difference appears to be that OSHI depends on JNA and native code, while you're primarily focused on command-line scripting. Additionally OSHI works on OS X.
A brief review of your code shows some bits I'd like to use as inspiration for features in OSHI. Similarly I'd be interested in helping contribute a mac OS X port to your code. Let me know how best we can coordinate our efforts.
I'll be adding a link to your project from my README.
I can't connect to the download webpage.
On a linux machine where sudo output is not english (e.g. variable LANG is set to de_DE.UTF-8), the method HardwareInfoUtils.isSudo() does not work properly
SEVERE: Error calling WMI4Java
com.profesorfalken.wmi4java.WMIException:Permission denied
Windows 8.1 64Bit Profesional
I install jhardware use maven, it have jSensor.jar, but when i call HardwareInfo.getProcessorInfo().getMhz(), i get ClassNotFoundException com.profesorfalken.jsensors.JSensors Error, platform is windows and IDE is eclipse, jHardware version is 0.8.4
In HardwareInfoUtils:48, Files.lines(path) is invoked without try-with-resources which is causing resource leak on file handles.
Fix involves wrapping HardwareInfoUtils.readFile(MEMINFO) with try-with-resources block in UnixMemoryInfo.getMemoryData() to automatically close file handles and avoid resource leak.
BEFORE
private static String getMemoryData(){
Stream<String> streamMemoryInfo = HardwareInfoUtils.readFile(MEMINFO);
final StringBuilder buffer = new StringBuilder();
streamMemoryInfo.forEach((String line) ->
buffer.append(line).append("\r\n")
);
return buffer.toString();
}
AFTER
private static String getMemoryData(){
final StringBuilder buffer = new StringBuilder();
try (Stream<String> streamMemoryInfo = HardwareInfoUtils.readFile(MEMINFO)) {
streamMemoryInfo.forEach((String line) ->
buffer.append(line).append("\r\n")
);
}
return buffer.toString();
}
This exception occurs on my linux mint 17.3, ASUS Zenbook.
Caused by: java.lang.NumberFormatException: For input string: "3400.0" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.valueOf(Integer.java:766) at com.profesorfalken.jsensors.manager.SensorsManager.getSensors(SensorsManager.java:106) at com.profesorfalken.jsensors.manager.SensorsManager.getCpu(SensorsManager.java:66) at com.profesorfalken.jsensors.manager.SensorsManager.getComponents(SensorsManager.java:54) at com.profesorfalken.jsensors.SensorsLocator.getComponents(SensorsLocator.java:34) at com.profesorfalken.jsensors.JSensors.components(JSensors.java:73) at org.jutils.jhardware.util.TemperatureUtils.getCpuTemperatureByjSensors(TemperatureUtils.java:41) at org.jutils.jhardware.util.TemperatureUtils.getCpuTemperatureForLinux(TemperatureUtils.java:92) at org.jutils.jhardware.info.processor.unix.UnixProcessorInfo.parseInfo(UnixProcessorInfo.java:53) at org.jutils.jhardware.info.processor.AbstractProcessorInfo.getInfo(AbstractProcessorInfo.java:29) at org.jutils.jhardware.info.processor.AbstractProcessorInfo.getInfo(AbstractProcessorInfo.java:25) at org.jutils.jhardware.HardwareInfo.getProcessorInfo(HardwareInfo.java:52)
it looks like something that you expect to be an int is on my system a float.
The ifconfig command is deprecated in many linux distributions and some already replaced it completly with the ip
command.
On non-english Windowsversions the network information are incomplete, only the adapter name is identified correctly. The reason for this is that WindowsNetworkInfo searchs for english strings, which are not present in non-english versions.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.