I'm having trouble getting the import of all the required .jar files working correctly.
My end goal is simply to read in an excel spreadsheet (more specifically .xlsx files) to check whether the speed of Apache POI will work for future applications.
My question is why am I getting thrown the error...
java.lang.NoClassDefFoundError: org/apache/poi/openxml4j/exceptions/InvalidFormatException
...when I can see in the class InvalidFormatException at /org/apache/poi/openxml4j/exceptions/ in the 'file poi-ooxml-3.9-20121203.jar'?
I haven't done programming in Java in a while and I'm hoping for my own sanity that I've made a stupid mistake. My code seems to be compiling correctly but I have the above error message when I try run the program. I have done some research into my issue but haven't been able to find someone in my situation. They usually just forget/don't have a required .jar file. Maybe I'm in the same boat but hopefully you'll be able to tell me.
I'll give a breakdown of my logic. Here is the code in TestExcel.java
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
public class TestExcel
{
public static void main(String[] args)
{
InputStream inp;
try
{
inp = new FileInputStream("cost.xlsx");
Workbook wb;
try {
wb = WorkbookFactory.create(inp);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
}
catch (InvalidFormatException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
Here is the file 'c_test' used to compile and run the java code:
javac -classpath "/home/robsco/Webdev/java/poi/*" TestExcel.java
java TestExcel
Here is the directory listing of the classpath above:
robsco#roblaptop:~/Webdev/java/poi$ ls -al
total 26616
drwxrwxr-x 2 robsco robsco 4096 Aug 18 18:13 .
drwxrwxr-x 6 robsco robsco 4096 Aug 18 18:12 ..
-rwxr-xr-- 1 robsco robsco 52915 Sep 18 2009 commons-logging-1.1.jar
-rwxr-xr-- 1 robsco robsco 313898 Apr 5 2009 dom4j-1.6.1.jar
-rwxr-xr-- 1 robsco robsco 121070 Apr 5 2009 junit-3.8.1.jar
-rwxr-xr-- 1 robsco robsco 358180 Apr 5 2009 log4j-1.2.13.jar
-rwxrw-r-- 1 robsco robsco 14841622 Aug 18 13:15 ooxml-schemas-1.1.jar
-rwxr-xr-- 1 robsco robsco 1869113 Nov 26 2012 poi-3.9-20121203.jar
-rwxr-xr-- 1 robsco robsco 30446 Nov 26 2012 poi-excelant-3.9-20121203.jar
-rwxr-xr-- 1 robsco robsco 936648 Nov 26 2012 poi-ooxml-3.9-20121203.jar
-rwxr-xr-- 1 robsco robsco 4802621 Nov 26 2012 poi-ooxml-schemas-3.9-20121203.jar
-rwxr-xr-- 1 robsco robsco 1226511 Nov 26 2012 poi-scratchpad-3.9-20121203.jar
-rwxr-xr-- 1 robsco robsco 2666695 Apr 5 2009 xmlbeans-2.3.0.jar
and the output of executing 'c_test':
robsco#roblaptop:~/Webdev/java$ ./c_test
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/openxml4j/exceptions/InvalidFormatException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2521)
at java.lang.Class.getMethod0(Class.java:2764)
at java.lang.Class.getMethod(Class.java:1653)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.openxml4j.exceptions.InvalidFormatException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
I am using:
OS: Lubuntu 12.10 x86
java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
robsco#roblaptop:~/Webdev/java/poi$ javac -version
javac 1.7.0_25
The problem is with how you're launching your program. I see you currently have a shell script of:
javac -classpath "/home/robsco/Webdev/java/poi/*" TestExcel.java
java TestExcel
That compiles with all the jars, but doesn't run with them, so your program won't have its dependencies available. (Unlike with some c programs, compiling with Java won't inline the depdendencies, nor will it add local links to the files. There are tools that will do that for you if you really need it though)
If you change your shell script to be:
javac -classpath "/home/robsco/Webdev/java/poi/*" TestExcel.java
java -classpath ".:/home/robsco/Webdev/java/poi/*" TestExcel
It should work fine. Note the addition of the current directory in the classpath in order for 'java' to find your class (in this case TestExcel).
Alternately, you could do something a little icky with environment variables, using the CLASSPATH envvar that Java checks, eg
export CLASSPATH=.:`ls -1d --color=no /home/robsco/Webdev/java/poi/* | xargs echo | sed 's/ /\:/g'`
javac TestExcel.java
java TestExcel
Related
I need to use Groovy to copy a "template" file and replace some text (a variable) with current values and then save the file in a new file.
bay_equipment.each{
hname="Network-${it['hostname']}-${it['function']}"
nodeName="${it['hostname']}"
nodeIP="${it['ip_address']}"
fname="${it['hostname']}-${it['function']}-Network.cfg"
def src= new File("../config-files/nagios-switch-bayg20.cfg")
def dst= new File("../dest-files/$fname")
dst << src.text
//everything work ups to here
//now trying to open the dst file and make modifications then save it.
//This string <%=#deviceType%>-<%=#deviceGroup%>-<%=#nodeName%> needs to be replaced with hname variable and likewise the <%=#nodeIP%> with nodeIP
dst = (dst =~ /<%=#deviceType%>-<%=#deviceGroup%>-<%=#nodeName%>/).replaceFirst("$hname")
dst = (dst =~ /<%=#nodeIP%>/).replaceFirst("$nodeIP")
dst.write(dst)
}
I'm getting an error when I run it:
Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.String.write() is applicable for argument types: (String) values: [../dest-files/u100en00700-BAYG20-Network.cfg]
Possible solutions: wait(), wait(long), with(groovy.lang.Closure), trim(), size(), toSet()
groovy.lang.MissingMethodException: No signature of method: java.lang.String.write() is applicable for argument types: (String) values: [../dest-files/u100en00700-BAYG20-Network.cfg]
Possible solutions: wait(), wait(long), with(groovy.lang.Closure), trim(), size(), toSet()
at nsr_nagios$_run_closure4.doCall(nsr_nagios:53)
at nsr_nagios.run(nsr_nagios:38)
For an example of how you can work with this, the following code:
def equipment = [
[hostname: 'foo', function: "bar", ip_address: '1.2.3.4'],
[hostname: 'alice', function: "raven", ip_address: '5.6.7.8']
]
equipment.each {
def binding = [
hname: "Network-${it['hostname']}-${it['function']}",
nodeName: it.hostname,
nodeIP: it.ip_address,
fname: "${it['hostname']}-${it['function']}-Network.cfg"
]
def srcData = new File("src-file.txt").text
def template = new groovy.text.StreamingTemplateEngine().createTemplate(srcData)
new File(binding.fname).text = template.make(binding)
}
given the following source file:
<%= hname %>-<%= nodeName %>-<%= nodeIP %>
will create two files, both templated. Example execution sequence:
─➤ ls -la
total 24
drwxrwxr-x 2 mbjarland mbjarland 4096 Mar 4 17:55 .
drwxr-xr-x 112 mbjarland mbjarland 12288 Mar 4 17:47 ..
-rw-rw-r-- 1 mbjarland mbjarland 634 Mar 4 17:55 solution.groovy
-rw-rw-r-- 1 mbjarland mbjarland 42 Mar 4 17:55 src-file.txt
─➤ cat src-file.txt
<%= hname %>-<%= nodeName %>-<%= nodeIP %>
─➤ groovy solution.groovy
─➤ ls -la
total 32
drwxrwxr-x 2 mbjarland mbjarland 4096 Mar 4 17:56 .
drwxr-xr-x 112 mbjarland mbjarland 12288 Mar 4 17:47 ..
-rw-rw-r-- 1 mbjarland mbjarland 33 Mar 4 17:56 alice-raven-Network.cfg
-rw-rw-r-- 1 mbjarland mbjarland 27 Mar 4 17:56 foo-bar-Network.cfg
-rw-rw-r-- 1 mbjarland mbjarland 634 Mar 4 17:55 solution.groovy
-rw-rw-r-- 1 mbjarland mbjarland 42 Mar 4 17:55 src-file.txt
─➤ cat foo-bar-Network.cfg
Network-foo-bar-foo-1.2.3.4
─➤ cat alice-raven-Network.cfg
Network-alice-raven-alice-5.6.7.8
─➤
where the template engine is a groovy built in class for doing just these kinds of things.
In my Python3 program, I take a bunch of paths and do things based on what they are. When I evaluate the following symlinks (snippet):
lrwxrwxrwx 1 513 513 5 Aug 19 10:56 console -> ttyS0
lrwxrwxrwx 1 513 513 11 Aug 19 10:56 core -> /proc/kcore
lrwxrwxrwx 1 513 513 13 Aug 19 10:56 fd -> /proc/self/fd
the results are:
symlink console -> ttyS0
file core -> /proc/kcore
symlink console -> ttyS0
It evaluates core as if it were a file (vs a symlink). What is the best way for me to evaluate it as a symlink vs a file? code below
#!/usr/bin/python3
import sys
import os
from pathlib import Path
def filetype(filein):
print(filein)
if Path(filein).is_file():
return "file"
if Path(filein).is_symlink():
return "symlink"
else:
return "doesn't match anything"
if __name__ == "__main__":
file = sys.argv[1]
print(str(file))
print(filetype(file))
The result of is_file is intended to answer the question "if I open this name, will I open a file". For a symlink, the answer is "yes" if the target is a file, hence the return value.
If you want to know if the name is a symlink, ask is_symlink.
I am new to Syntaxnet and i tried to use pre-trained model of Turkish language through the instructions here
Point-1 : Although I set the MODEL_DIRECTORY environment variable, tokenize.sh didn't find the related path and it gives error like below :
root#4562a2ee0202:/opt/tensorflow/models/syntaxnet# echo "Eray eve geldi." | syntaxnet/models/parsey_universal/tokenize.sh
F syntaxnet/term_frequency_map.cc:62] Check failed: ::tensorflow::Status::OK() == (tensorflow::Env::Default()->NewRandomAccessFile(filename, &file)) (OK vs. **Not found: label-map**)
Point-2 : So, I changed the tokenize.sh through commenting the MODEL_DIR=$1 and set my Turkish language model path like below to go on :
PARSER_EVAL=bazel-bin/syntaxnet/parser_eval
CONTEXT=syntaxnet/models/parsey_universal/context.pbtxt
INPUT_FORMAT=stdin-untoken
MODEL_DIR=$1
MODEL_DIR=syntaxnet/models/etiya-smart-tr
Point-3 : After that when I run it as told, it gives error like below :
root#4562a2ee0202:/opt/tensorflow/models/syntaxnet# echo "Eray eve geldi" | syntaxnet/models/parsey_universal/tokenize.sh
I syntaxnet/term_frequency_map.cc:101] Loaded 29 terms from syntaxnet/models/etiya-smart-tr/label-map.
I syntaxnet/embedding_feature_extractor.cc:35] Features: input.char input(-1).char input(1).char; input.digit input(-1).digit input(1).digit; input.punctuation-amount input(-1).punctuation-amount input(1).punctuation-amount
I syntaxnet/embedding_feature_extractor.cc:36] Embedding names: chars;digits;puncts
I syntaxnet/embedding_feature_extractor.cc:37] Embedding dims: 16;16;16
F syntaxnet/term_frequency_map.cc:62] Check failed: ::tensorflow::Status::OK() == (tensorflow::Env::Default()->NewRandomAccessFile(filename, &file)) (OK vs. **Not found: syntaxnet/models/etiya-smart-tr/char-map**)
I had downloaded the Turkish package through tracing the link pattern indicated like download.tensorflow.org/models/parsey_universal/.zip
and my language mapping file list like below :
-rw-r----- 1 root root 50646 Sep 22 07:24 char-ngram-map
-rw-r----- 1 root root 329 Sep 22 07:24 label-map
-rw-r----- 1 root root 133477 Sep 22 07:24 morph-label-set
-rw-r----- 1 root root 5553526 Sep 22 07:24 morpher-params
-rw-r----- 1 root root 1810 Sep 22 07:24 morphology-map
-rw-r----- 1 root root 10921546 Sep 22 07:24 parser-params
-rw-r----- 1 root root 39990 Sep 22 07:24 prefix-table
-rw-r----- 1 root root 28958 Sep 22 07:24 suffix-table
-rw-r----- 1 root root 561 Sep 22 07:24 tag-map
-rw-r----- 1 root root 5234212 Sep 22 07:24 tagger-params
-rw-r----- 1 root root 172869 Sep 22 07:24 word-map
QUESTION-1 :
I am aware that there is no char-map file in the directory so I got the error written # Point-3 above. So, does anyone have an opinion about how the Turkish language test could be done and the result was shared as %93,363 for Part-of-Speech for example?
QUESTION-2:
How can I find the char-map file for Turkish language?
QUESTION-3:
If there is no char-map file, must I train through tracing the steps indicated as SyntaxNet's Obtain Data & Training?
QUESTION-4:
Is there a way to generate word-map, char-map... etc. files? Is it the well known word2vec approach that can be used to generate map files which will be able to be processed wt. Syntaxnet tokenizers?
Try this https://github.com/tensorflow/models/issues/830 issue - it contains an (at this moment) temporary solution.
Running built-in fuse HelloFS example file system, shows a hello.txt file on root.
Opening this file show an error as "...The file changed on disk do you want to reload the file. Reload/cancel"
How can I remove this error.
I am facing the same error in my custom File System because I had taken HelloFS as starting point. To make question simple I quoted HelloFS code because the same error is in helloFS also.
example code, log and screenshot of error are as below:
HelloFS java Code:
package net.fusejna.examples;
import java.io.File;
import java.nio.ByteBuffer;
import net.fusejna.DirectoryFiller;
import net.fusejna.ErrorCodes;
import net.fusejna.FuseException;
import net.fusejna.StructFuseFileInfo.FileInfoWrapper;
import net.fusejna.StructStat.StatWrapper;
import net.fusejna.types.TypeMode.NodeType;
import net.fusejna.util.FuseFilesystemAdapterFull;
public class HelloFS extends FuseFilesystemAdapterFull
{
public static void main(final String... args) throws FuseException
{
if (args.length != 1) {
System.err.println("Usage: HelloFS <mountpoint>");
System.exit(1);
}
new HelloFS().log(true).mount(args[0]);
}
private final String filename = "/hello.txt";
private final String contents = "Hello World!\n";
#Override
public int getattr(final String path, final StatWrapper stat)
{
if (path.equals(File.separator)) { // Root directory
stat.setMode(NodeType.DIRECTORY);
return 0;
}
if (path.equals(filename)) { // hello.txt
stat.setMode(NodeType.FILE).size(contents.length());
return 0;
}
return -ErrorCodes.ENOENT();
}
#Override
public int read(final String path, final ByteBuffer buffer, final long size, final long offset, final FileInfoWrapper info)
{
// Compute substring that we are being asked to read
final String s = contents.substring((int) offset,
(int) Math.max(offset, Math.min(contents.length() - offset, offset + size)));
buffer.put(s.getBytes());
return s.getBytes().length;
}
#Override
public int readdir(final String path, final DirectoryFiller filler)
{
filler.add(filename);
return 0;
}
}
error: ...The file changed on disk do you want to reload the file. Reload/cancel
log:
Mar 24, 2014 12:16:15 AM HelloFS statfs
INFO: [/] Method succeeded. Result: 0
Mar 24, 2014 12:16:33 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:36 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS getattr
INFO: [/] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS open
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS read
INFO: [/hello.txt] Method succeeded. Result: 13
Mar 24, 2014 12:16:45 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS flush
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS lock
INFO: [/hello.txt] Method succeeded. Result: -38
Mar 24, 2014 12:16:45 AM HelloFS release
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:46 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:46 AM HelloFS getattr
INFO: [/] Method succeeded. Result: 0
Mar 24, 2014 12:16:48 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Please Guide me how to fix this
I am not as familiar with the Java version of FUSE (I mostly do C++/Python), but based on your trace, I'd say that your editor application is the one releasing the file handle. Maybe it's doing something like open/read/close, and then holding it in cache. Try opening the file in something even simpler, like vi, or using cat on it.
The thing about "the contents have changed on disk" is probably your editor responding to a continuously changing timestamp in your stat structure. Try setting your StatWrapper.mtime (in your getattr function) to some fixed time, like unix epoch, and see if that helps.
The example file systems are a good jumping off point, but in order to be easy to understand, there's often a lot they don't implement.
I encountered another problem while learning to work with slick library.
I created a simple little map with 5x5 blocks with size 50x50 pixel.
I tried everything but I still get the same error.
Here my class:
public class PlayState extends BasicGameState{
int stateID = -1;
private TiledMap map;
public PlayState(int stateID){
this.stateID = stateID;
}
#Override
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
map = new TiledMap("src/resources/map.tmx","src/resources");
}
#Override
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
map.render(0, 0);
}
#Override
public void update(GameContainer gc, StateBasedGame sbg, int arg2) throws SlickException {
}
#Override
public int getID() {
return stateID;
}
}
and here my error:
Tue Jul 30 13:34:09 CEST 2013 INFO:Slick Build #237
Tue Jul 30 13:34:09 CEST 2013 INFO:LWJGL Version: 2.9.0
Tue Jul 30 13:34:09 CEST 2013 INFO:OriginalDisplayMode: 1600 x 900 x 32 #60Hz
Tue Jul 30 13:34:09 CEST 2013 INFO:TargetDisplayMode: 1280 x 720 x 0 #0Hz
Tue Jul 30 13:34:09 CEST 2013 INFO:Starting display 1280x720
Tue Jul 30 13:34:09 CEST 2013 INFO:Use Java PNG Loader = true
Tue Jul 30 13:34:09 CEST 2013 INFO:Controllers not available
Tue Jul 30 13:34:09 CEST 2013 WARN:class org.newdawn.slick.opengl.PNGImageData failed to read the data
java.io.IOException: Transparent color not support in custom PNG Decoder
at org.newdawn.slick.opengl.PNGImageData.loadImage(PNGImageData.java:78)
at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:62)
at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:43)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:292)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:254)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:187)
at org.newdawn.slick.Image.<init>(Image.java:192)
at org.newdawn.slick.tiled.TileSet.<init>(TileSet.java:124)
at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:661)
at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:122)
at main.states.PlayState.init(PlayState.java:23)
at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
at main.Main.main(Main.java:40)
Tue Jul 30 13:34:09 CEST 2013 ERROR:Unsupport tiled map type: base64,zlib (only gzip base64 supported)
org.newdawn.slick.SlickException: Unsupport tiled map type: base64,zlib (only gzip base64 supported)
at org.newdawn.slick.tiled.Layer.<init>(Layer.java:133)
at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:676)
at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:122)
at main.states.PlayState.init(PlayState.java:23)
at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
at main.Main.main(Main.java:40)
Tue Jul 30 13:34:09 CEST 2013 ERROR:Failed to parse tilemap
org.newdawn.slick.SlickException: Failed to parse tilemap
at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:695)
at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:122)
at main.states.PlayState.init(PlayState.java:23)
at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
at main.Main.main(Main.java:40)
Caused by: org.newdawn.slick.SlickException: Unsupport tiled map type: base64,zlib (only gzip base64 supported)
at org.newdawn.slick.tiled.Layer.<init>(Layer.java:133)
at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:676)
... 6 more
I just got this error myself - and solved it. You need to make sure your map properties layer format is set to Base64 (gzip compressed). Looks like that's the format slick expects.
As far as the PNG warnings, apparently slick doesn't like interlaced PNG files, so save as a non-interlaced image