I use java instrument(premain) to change bytecode,i used losts of jars,like asm,spring,guava.When i package this agent to a jar and run this jar on a springboot's,it always tell me java.lang.NoClassDefFoundError.I know i can add Boot-Class-Path to the manifest file or use instrument's api to add jar,but is there an quick way to add jars to javaagent's classpath?
Related
Here is the make file i am using to generate and JAVA module which i am importing in another module. While compiling it, the build breaks saying
error: 'out/target/common/obj/JAVA_LIBRARIES/android.hardware.automotive.vehicle#2.0-java_intermediates/classes.dex.toc', needed by 'out/target/common/obj/JAVA_LIBRARIES/vendor.harman.hardware.automotive.vehicle.fca_r1#1.0-java_intermediates/with-local/classes.dex', missing and no known rule to make it
Any suggestion on how to generate a .toc file in general?
Anything specific to be added in the make file?
Usually such toc file will be auto generated during fullbuild, but if it is missing when you build single module you can manually generate the classes.dex.toc with the following command:
dexdump2 classes.dex >> classes.dex.toc
If you want to know the details, please read the sourcecode of android build system: _transform_dex-to-toc
https://android.googlesource.com/platform/build/+/f972a4a980660d2347ace8fdc7c668403c0e9697/core/definitions.mk
I am writing a library for clojure which involves native code. How can I bundle the shared library (aka native dependencies) when I deploy the clojure libraries to public repositories (like clojars)?
Further Info:
My project structure looks roughly like:
src/
native/ - C code , C Object files and compiled shared libs
java/ - Java stuff
clojure/ - Clojure stuff
I am currently using leineingen. I have tried doing:
:jvm-opts [~(str "-Djava.library.path=src/native/:"
(System/getenv "$LD_LIBRARY_PATH"))]
It works if I am in the project. However, if I include this project as a dependency, I will get a UnsatisfiedLink error.
The answer depends on your exact use-case. In the simplest situation, you need to:
bundle the native lib inside the library jar, for example by including the native/ folder in :resource-paths in your project.clj.
when you use your library, you can specify a :native-prefix option to indicate a path inside your library jar from which native libraries should be extracted. For example, if your library contains a resource "mylib.so" in the root folder, you can specify it like this: [com.foo/bar "1.0.1" :native-prefix ""]
you should also specify where the extracted libs should go, using the :native-path option in your project.clj.
finally, you should add the :native-path you have specified to java.library.path, using :jvm-opts like you said.
These options are documented in the sample leiningen project.clj.
Now the reason I said it depends on your use-case is that if you want to create an uberjar that contains native libs, things start getting more messy. The main reason is that you can't directly link to a lib that is zipped inside your jar. If you're lucky, you'll be able to use the loadLibraryFromJar method in the NativeUtils class. However, I remember having ClassLoader-related issues that prevented me from using System/load. Instead I had to make sure the library was present in one of the paths that the JVM looks for, so that System/loadLibrary finds it correctly. Here is what I ended up doing:
manually extract the native lib from the uberjar at runtime to a temporary folder, with (-> my-lib io/resource io/input-stream (io/copy my-temp-file))
update the java.library.path system property at runtime to add the temporary folder to it, using System/setProperty
finally, use this reflection trick to force the library path to be updated
This is painful to setup, but after that it works pretty well.
I am getting an exception:
Cannot find symbol: FileUploadException;
I have a piece of code which uses
FileUploadException
The library that needs importing is:
org.apache.commons.fileupload.FileUploadException
The path to my project is :
D:\Projects\website
In the project folder I have each in its folder:
Tomcat, Derby, Website
I have copied:
commons-fileupload.jar and commons-io.jar
into both:
Tomcat/lib and Website/Web-INF/lib
---------------I tried this--------------
just importing the library on its own
import org.apache.commons.fileupload.FileUploadException;
adding the jars to the class path upon build:
javac -cp .;D:Projects\website\Tomcat\lib\commons-fileupload.jar;D:\Projects\website\Tomcat\lib\commons-io.jar com/otrocol/app/*.java
adding them to the Environment variables CLASSPATH
D:Projects\website\Tomcat\lib\commons-fileupload.jar;D:\Projects\website\Tomcat\lib\commons-io.jar
I also tried adding the jars where my .java files are as #Scot Ship suggested
----mentions---
I am not using any IDE
The code contains more unrecognized symbols, but I'm trying to solve one at a time
First time using apache, tomcat, jsp.. please be gentle
Vlad, the web container will automatically look for JARs inside
/WEB-INF/lib
even without any developer intervention. Take note that it's all caps WEB-INF. As long as your JAR is there, it will be in your web application's classpath.
Try to display this in one of your servlets or JSP:
System.getProperty("java.class.path")
and you'll get a better view of what classes and JARs were actually loaded.
Update: After reviewing your question, it appears you're facing issues in compiling the files to begin with and you're doing it outside an IDE.
Take note that when you use -cp in javac like this:
javac -cp .;D:Projects\website\Tomcat\lib\commons-fileupload.jar;D:\Projects\website\Tomcat\lib\commons-io.jar com/otrocol/app/*.java
Whatever value you have set in the CLASSPATH environment variable becomes ignored.
Be absolutely sure that the class FileUploadException is indeed inside one of the JARs you're trying to import: you can view the JAR directly using an unarchiving tool.
Also, change the com/otrocol/app/*.java to com\otrocol\app*.java - you should be using your system delimiter (not that this may affect your problem).
Create a simple HelloWorld in the same location as the file you're compiling, add the SystemOut mentioned above, and compile it the same way you're doing for the concerned file.
Read this http://commons.apache.org/proper/commons-fileupload/faq.html#class-not-found. Probably you have the fileupload jar but you also need commons-io.jar in your classpath as well.
I am using one third party jar in my code. In the jar file , in one of the classes, when I opened the class using de-compiler, the code below is written:
java.net.URL fileURL = ClassLoader.getSystemResource("SOAPConfig.xml");
Now I am using this in my webapplication, where should I place this SOAPConfig.xml so that it will find the fileURL.
Note: I have tried putting this XML in WEB-INF/classes folder. But it is not working. Your help will be appreciated.
In Addition: In the explaination you have given, It is telling me not to use this code snippet inside the third party jar in this way...What is the exact usage of this statement
ClassLoader.getSystemResource will load the resource from the system classloader, which uses the classpath of the application as started from the command line. Any classloaders created by the application at runtime (i.e. the one that looks in WEB-INF/classes) are not on the system classpath.
You need to
Look through the script that starts your server, find out which directories are on the classpath there, and put your SOAPConfig.xml in one of those. If necessary, change the classpath in the script to look in a separate directory that's just used for your config file.
Track down the person who used ClassLoader.getSystemResource in the library, kick them squarely in the nuts, and tell them never to do that again.
I need to add a class to a .jar library but I can't figure out how to do it.
I have a library named netty-3.1.5.GA.jar but for some reason its missing a class I need
(HttpTunnelClientChannelFactory.java).
I have found that class on a repository but not as part of the library. So how can I 'inject' it? The class I need to add is using other classes that exist in the library.
You don't need to add it to the jar, you need to add it to the classpath of whatever it is you're running.
You can use the jar tool to update the jar file: you will need to manually create the appropriate package directory though. Try this:
jar uf netty-3.1.5.GA.jar HttpTunnelClientChannelFactory.class
will add it to the root package. If you need it to be set up in a package directory you should create the directory structure and then add the file with a path.
EDIT: that should be .class, not .java.