Determine which JAR file a class is from

Yes. It works for all classes except classes loaded by bootstrap classloader. The other way to determine is: Class klass = String.class; URL location = klass.getResource(“https://stackoverflow.com/” + klass.getName().replace(‘.’, “https://stackoverflow.com/”) + “.class”); As notnoop pointed out klass.getResource() method returns the location of the class file itself. For example: jar:file:/jdk/jre/lib/rt.jar!/java/lang/String.class file:/projects/classes/pkg/MyClass$1.class The getProtectionDomain().getCodeSource().getLocation() method returns the location … Read more

How to build sources JAR with Gradle?

task sourcesJar(type: Jar, dependsOn: classes) { classifier=”sources” from sourceSets.main.allSource } task javadocJar(type: Jar, dependsOn: javadoc) { classifier=”javadoc” from javadoc.destinationDir } artifacts { archives sourcesJar archives javadocJar }

Add JAR files to a Spark job – spark-submit

ClassPath: ClassPath is affected depending on what you provide. There are a couple of ways to set something on the classpath: spark.driver.extraClassPath or it’s alias –driver-class-path to set extra classpaths on the node running the driver. spark.executor.extraClassPath to set extra class path on the Worker nodes. If you want a certain JAR to be effected … Read more

Run class in Jar file

Use java -cp myjar.jar com.mypackage.myClass. If the class is not in a package then simply java -cp myjar.jar myClass. If you are not within the directory where myJar.jar is located, then you can do: On Unix or Linux platforms: java -cp /location_of_jar/myjar.jar com.mypackage.myClass On Windows: java -cp c:\location_of_jar\myjar.jar com.mypackage.myClass

Create aar file in Android Studio

If your library is set up as an Android library (i.e. it uses the apply plugin: ‘com.android.library’ statement in its build.gradle file), it will output an .aar when it’s built. It will show up in the build/outputs/aar/ directory in your module’s directory. You can choose the “Android Library” type in File > New Module to … Read more

Access restriction: The type ‘Application’ is not API (restriction on required library rt.jar)

This happened to me as well, and the answers given here already were not satisfying, so I did my own research. Background: Eclipse access restrictions Eclipse has a mechanism called access restrictions to prevent you from accidentally using classes which Eclipse thinks are not part of the public API. Usually, Eclipse is right about that, … Read more

java.lang.NoClassDefFoundError: Could not initialize class XXX

My best bet is there is an issue here: static { //code for loading properties from file } It would appear some uncaught exception occurred and propagated up to the actual ClassLoader attempting to load the class. We would need a stacktrace to confirm this though. Either that or it occurred when creating PropHolder.prop static … Read more

Controlling Maven final name of jar artifact

For Maven >= 3 <packaging>jar</packaging> <build> <finalName>WhatEverYouLikey</finalName> </build> See bug report/documentation. (Credits to Matthew’s and his comment) For older Maven versions You set the finalName property in the plugin configuration section: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.2</version> <configuration> <finalName>myJar</finalName> </configuration> </plugin> As indicated in the official documentation.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)