how to run external jar library in eclipse - java

I have just installed eclipse IDE for java and i am unable to execute code from external libraries, i know that we can't execute library code from unnamed package into a named package file, So i've put them both in default package, now i am able to access file from my external JAR library but i'm not able to get through this error, stating cannot connect to VM and some other boot layer error and i have no idea how to get through this...

The error occurs because of me adding jar library files to MODULEPATH instead of CLASSPATH. You have to add jar files to your CLASSPATH. If you already add jar files to MODLEPATH you have to remove from there and add jar files to CLASSPATH
as on : Error occurred during initialization of boot layer

Related

Creating a jar from maven project Intellij

I created a new maven project in IntelliJ and set packaging to jar and when I build it, there is a jar file target folder. But when I run the file I get the error as
no main manifest attribute, in QeToolHelper-0.1-SNAPSHOT.jar
I have created jar file using maven-assembly-plugin. I have added these lines in pom.xml for that.
Tried few methods described in other similar questions but to no avail.
Have you looked at SpringBoot and associated plugins. It can be used to build a standalone java applications.
With regards to your specific issue, that error is symtomatic of a failure to declare main class in your manifest. The main-class attribute in the manifest tells the jvm what class to load from the built jar. Looks like the settings in your maven config are failing to generate the resources correctly.
I was able to solve this issue by creating jar package from maven.
Running the build package created the jar in target directory.

Spring Boot 1.5.3 -- IllegalStateException

After deploying my project in IDE, all ok. But when I make 'package' at Maven, and tried to execute 'war' archive at the console, I get this exception:
Unable to open nested entry
'WEB-INF/lib/spring-aspects-4.3.8.RELEASE.jar'. It has been compressed
and nested jar files must be stored without compression. Please check
the mechanism used to create your executable jar file
At Spring Boot 1.5.2 was all good.
Looks like spring-aspects-4.3.8.RELEASE.jar that inside WEB-INF/lib/ is not extracted after compilation and your application can't extract classes from *.jar when you executing app.
Use maven dependencies instead direct *.jar files or specified plugin that will extract classes from *.jar's and add them to your app.
If you can't find public repository that provide required dependencies then use this instruction to add your external JAR files into your local maven repository. Then just add such dependency and build app again.

Spring application Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

Why application is not able to read the class from the build path? I did added ojdbc6.jar in the build path of the application.
Now when I kept this jar in the WEB-INF/lib directory, it worked fine.
Can someone please explain why it was not read from the project build path.
When you add it on the build path in your IDE , it is used for compiling the code (if there is a dependency on it).
Unless you package this and deploy on the server , the server has no reference to these files that were used for compilation. When you place it on WEB-INF/lib and package it , the jar file is also packaged in your .war file that is deployed and hence at runtime you will not get a Class missing or Driver missing error.

How to use Netbeans Jar file in Eclipse Project

I have developed a web service client in Netbeans through WSDL file, i have build the project and get jar file. When i run that jar file, it work fine but now i have to use this jar file in my eclipse project. But when i use this jar file i get error.
"THe type javax.xml.bind.annotation.XmlAccesstype.cannot be resolved. "
Attach is the screenshot.
How can i solve this problem.
You have to check your classpath and probably add you WS libraries in it. Open grepcode.com and paste your missing class name in it. You will see the dependency missing.

I need some help concerning using 2 jar files in Java

Well I have 2 .jar files. The main jar file is the jar file for my whole project and the other .jar file being the MySql JDBC Connector.
Well basically whats happening right now is that when I build the project I have the one main .jar file with everything but the MySql JDBC Connector .jar file is inside the main jar file when it builds in NetBeans.
Now when I am just running the project from within NetBeans the MySql JDBC driver can be found inside the src/com/game/mysql folder that I have it in. But when I build the project the Java application cannot locate the JDBC driver from within the main jar file.
When I open the main jar file with WinRar I can see that the JDBC jar file is still in its /com/game/mysql/ folder. But why cant the Java application access it?
I have heard that nested .jar files are not supported in Java so Im thinking this might be the reason although Im not sure if thats true. Is there a way that I can make it so that the application can find the JDBC .jar file within the main jar file?
Also I have done the thing in NetBeans where you add the .jar file through right clicking project -> properties -> Library -> Add Folder/Jar. Thats what makes it work in the NetBeans run but still not the App build.
I have heard that nested .jar files are not supported in Java
More precise, classes in a JAR file which is packaged as a child JAR inside a main JAR are indeed by default invisible to classes in the main JAR.
You have basically 2 options:
Ship your application with 2 loose JARs: your.jar and mysql.jar and define the relative path to the mysql.jar in the Class-Path entry of the MANIFEST.MF file of your.jar.
Class-Path: mysql.jar
When you put both JARs in the same folder and execute your.jar by java -jar your.jar, then it will work.
Let your IDE repackage all loose classes of mysql.jar inside your.jar or add a special classloader which preloads the classes of any embedded JARs. Since I don't do Netbeans, I can't tell whether it supports it and if so, how to do it. In Eclipse, however, this is definitely possible. See also this answer.

Categories