classpath

read excel file(which is in classpath ) via apache poi

可紊 提交于 2019-11-30 04:46:12
问题 I am trying to read (using apache poi) .xlsx file which is not in file system but in classpath. I am using maven - so it is in resources folder. my code is - InputStream resourceAsStream = MyReader.class.getClassLoader().getResourceAsStream("test.xlsx"); Workbook wb = new XSSFWorkbook(resourceAsStream); I am getting this exception. Caused by: java.lang.IllegalArgumentException: MALFORMED at java.util.zip.ZipCoder.toString(ZipCoder.java:58) ~[?:1.7.0_51] at java.util.zip.ZipInputStream.readLOC

How to read several resource files with the same name from different JARs?

梦想的初衷 提交于 2019-11-30 04:16:50
If there are two JAR files in the classpath, both containing a resource named "config.properties" in its root. Is there a way to retrieve both files similar to getClass().getResourceAsStream() ? The order is not relevant. An alternative would be to load every property file in the class path that match certain criterias, if this is possible at all. You need ClassLoader.getResources(name) (or the static version ClassLoader.getSystemResources(name) ). But unfortunately there's a known issue with resources that are not inside a "directory". E.g. foo/bar.txt is fine, but bar.txt can be a problem.

importing external jar files

给你一囗甜甜゛ 提交于 2019-11-30 04:03:46
I have written a Java code which imports an external jar file. How can I compile and run it on the command-line? Thanks in advance! Compiling from the command-line: javac -cp path_to_jar1.jar:path_to_jar2.jar Example.java Running: java -cp .:path_to_jar1.jar:path_to_jar2.jar Example For Windows, use ; as a path-separator (instead of : ). 来源: https://stackoverflow.com/questions/4421730/importing-external-jar-files

Overriding a class file from a library JAR in a Java web app

别说谁变了你拦得住时间么 提交于 2019-11-30 03:22:38
问题 In my Java web app, I have these files: /WEB-INF/classes/com/example/Foo.class /WEB-INF/lib/example.jar <-- contains the class "com.example.Foo" Will the class defined in the classes directory be used instead of the class defined in example.jar ? Thanks. 回答1: The answer depends upon your container, it is container dependent. In general, /WEB-INF/classes is preferred to classes in a jar file in WEB-INF/lib. For Tomcat, the order is the following: Therefore, from the perspective of a web

How to set Java classpath in Linux?

折月煮酒 提交于 2019-11-30 01:43:51
问题 I downloaded apache-log4j-1.2.16.zip and unziped it. I then renamed it as LOG4J_HOME and placed it in /home/appnetix folder which is my folder. I tried setting the classpath in the terminal using the following command : [appnetix@Sanjeev ~]$ set classpath=%path%;LOG4J_HOME/log4j-1.2.16.jar; That returned: bash: LOG4J_HOME/log4j-1.2.16.jar: Permission denied I tried doing this: [appnetix@Sanjeev ~]$ set classpath=%path%;//home/appnetix/LOG4J_HOME/log4j-1.2.16.jar; But I got this: bash: //home

How to walk through Java class resources?

帅比萌擦擦* 提交于 2019-11-30 00:25:40
I know we can do something like this: Class.class.getResourceAsStream("/com/youcompany/yourapp/module/someresource.conf") to read the files that are packaged within our jar file. I have googled it a lot and I am surely not using the proper terms; what I want to do is to list the available resources, something like this: Class.class.listResources("/com/yourcompany/yourapp") That should return a list of resources that are inside the package com.yourcompany.yourapp.* Is that possible? Any ideas on how to do it in case it can't be done as easily as I showed? Note: I know it is possible to know

In Maven, how output the classpath being used?

五迷三道 提交于 2019-11-29 23:33:31
For my current purposes I have a Maven project which creates a war file, and I want to see what actual classpath it is using when creating the war . Is there a way to do that in a single command -- without having to compile the entire project? One idea is to have Maven generate the target/classpath.properties file and then stop at that point. To get the classpath all by itself in a file, you can: mvn dependency:build-classpath -Dmdep.outputFile=cp.txt Or add this to the POM.XML: <project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency

Loading classes not present in the classpath

五迷三道 提交于 2019-11-29 22:58:39
问题 Let's say I've compiled a Groovy script using Groovyc, which has generated one or more .class files in the file system. From a Java application, how do I add those classes to the classpath dynamically in order to load them and call their methods? The goal is to pre-compile Groovy scripts and store them into the database, so evaluation can be performed from compiled versions of the scripts. 回答1: You can create an instance of URLClassLoader to load new classes from a directory: URL dirUrl = new

Is it possible to have the System ClassLoader load .class files specified at run time?

雨燕双飞 提交于 2019-11-29 21:16:39
问题 I am writing a static analysis tool for an assignment, it analyses Java bytecode using the ASM library. One of the parts of ASM that we use requires (or at least, appears to require) that the class be loaded from the ClassLoader. We were hoping the tool would be able to analyse .class files without requiring them on the classpath. We already load the .classes from a specified directory at run time and read them in using an InputStream. This is acceptable for ASM in most cases. There are some

How do I compile a Hive UDF

痞子三分冷 提交于 2019-11-29 21:16:24
问题 I am trying to compile this UDF: package com.dataminelab.hive.udf; import org.apache.hadoop.hive.ql.exec.UDF; import org.apache.hadoop.io.Text; import java.security.*; /** * Calculate md5 of the string */ public final class Md5 extends UDF { public Text evaluate(final Text s) { if (s == null) { return null; } try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(s.toString().getBytes()); byte[] md5hash = md.digest(); StringBuilder builder = new StringBuilder(); for (byte b :