I have created a web application in java and is working fine. But i want to Convert few classes in JAR format, so that the code inside the jar is not visible to others.
I have totally 5 classes. 3 classes (CreateFile,ProcessFile,HouseWork) belong to a package "FilePackage" remaining two classes are SFTPEngine and ExecEngine they belong to Package "PuttyEngine".
I selected all these classes and gave export as JAR and named it mytool.jar.
Now i deleted all these classes from eclipse and added the jar. In the Eclipse IDE after configuring the BuildPath no error was displayed. when I run the application on tomcat server from the IDE itself I get ClassNotFoundException
How Do I export those classes into a JAR file and use them. These classes use functions from other classes as well. ie SFTPEngine class will access fucntions from others classes and other classes also wil be accesing the functions in SFTPEngine class.
I am not using any build tool. Cause I cannot use them in my office , I need to get permission from admin, so is there any way to do this work without build tools like ANT or MAVEN
In Eclipse, click on your web project / Properties / Tab "Deployment Assembly".
Add your JAR here.
After that, in the server Tab, when you expand the server, then you can expand the web project, and you should see your JAR.
Make sure you include your jar under webapps/ under Tomcat installation directory if you're running Tomcat outside Eclipse.
Related
I want to migrate running java application to Jdev12c. Can i use all the jar used in Eclipse as it is. I have eclipse related jars also i.e.
org.apache.commons.logging-1.0.4.v201101211617.jar
org.eclipse.persistence.core-2.5.0-RC2.jar
org.eclipse.persistence.jpa-2.5.0.jar
org.eclipse.persistence.oracle-2.5.0.jar
can i use these all jars in Jdev directly. and also apache logger file will work in Jdev or not. also do i need to change something in classes and code?
I have folders in the application and which have files. I am also using .property file. so can i directly use this all.
JDeveloper has ability to import code from WAR file or a Maven project (import menu under file menu).
Or you can just create project from existing code.
You'll need to point to the jars in the project properties->libraries and class path
I'm developing a Netbeans RCP application doing some EJB connections deployed on a GlassFish server. I used the package-appclient the jar containing the needed dependencies and i added the gf-client.jar jar file to my class path my adding the following line to my project.properties file:
run.args.extra=-cp:a ./appclient/glassfish/lib/gf-client.jar
The repository is located at the root of my application.
The above works when i'm compiling/running the application within the Netbeans IDE. But now i'd like to be able to create a independent application.
What happen to the project.properties file after the built of the application? The extra arguments i have added to this file to add gf-client.jar to class path will not be viable anymore. What changes i need to do?
the project.properties file is only used by the IDE and has no meaning when deploying application on server.
You have several options when deploying to a server:
Create a manifest file which points to the required jar.
Copy the jar under the server lib folder, in that case it will be known to all applications running on the server
If your application is packed as a WAR file, put the jar under the lib folder of the application.
there are several other options but theses are the main ones.
Options 2-3 are the easiest.
Any jar file that you need to use in your NetBeans Platform application you can add to your module as a Wrapped JAR. You can do this by:
Right click on the module that needs access to this jar
Choose "Properties" from the context menu
Choose the "Libraries" Category
Click the "Wrapped JARs" tab
Click the "Add JAR" button
Make sure you "Clean and Build" the module before running again
If you have other modules that need access to the packages in this jar then you'll need to make the necessary packages publicly available to these other modules (not to be confused with the public keyword):
Choose the "API Versioning" Category (below the Libraries category)
Select the check box next to each package you want to expose to other modules
Make sure you "Clean and Build" the module before running again
For more detailed information see the NetBeans FAQ DevFaqWrapperModules
For reference, if you need to add command line options to your app's deployed instance you can do this by editing the app.conf file in NetBeans' harness. This file is located in <NB_Install_Dir>/harness/etc/app.conf and will be packaged with your application. However, editing this file will change every app.conf file for every application you build. If you build more than one application then you'll need to setup this application to use a custom harness DevFaqNbPlatformAndHarnessMixAndMatch
I keep server and client code in the same project of Eclipse. Libraries for both of them are included. Images for the client are also added to the build path.
Now I want to generate jars for server and client, that they include only required libraries, and server jar does not have images included.
Is there a way to do this without maven, etc?
Right-click on the project and go to Export. Select jar from the selection tree and in the next tab, remove the code/resources that you don't want included in the jar. Better still if you keep them in separate projects (even if there is no client java code, you can create a resource project).
However, what you're describing sounds a lot like a WAR file. Contrary to a jar, a WAR file is a deployable jar meant to be added to a web hosting application like Tomcat. I don't know if that's suitable for your needs, but more often than not, you want to have both server and client code together. If your project is dependent upon another project, that project will automatically create a jar that will be included in the WAR.
You can divide your sources into three source (and output) folders within the same project:
src-shared
src-server
src-client
Then create a build.xml (Ant buildfile) which creates a jar from bin-shared + bin-server and a jar from bin-shared + bin-client.
Note: One danger of keeping it in the same project is that you can accidentally use client classes from server classes, or vice versa, which will fail at runtime. To fix this, make three projects instead of three source folders.
Summary
Classes from 3rd party jar files are accessible when added to build path while running a standalone JUnit test, but "ClassNotFoundException" when accessed through plain old java objects from within a dynamic web project.
IDE used: Eclipse
Web Server: Apache 7
Details
My project required a lot of 3rd party jars, namely sqlite, eclipse jdt & jsoup. I had created this project as a standalone project and all the classes from the jars were accessible fine.
But now I have copied the entire "src" folder into a "dynamic web project". I have created a folder "jars" which contains all these 3rd party jars and ensure that all of these are added to the build path by following these steps:
Project properties --> Java Build Path --> Libraries --> Add jars --> Select all the jar files from jars folder.
These jars are accessible fine when I run a standalone JUnit test inside the web project. Note that this junit test does not require a server by any means.
But when I try to "Run on Server.." , I keep on getting ClassNotFoundException like these for all the 3rd party classes:
java.lang.ClassNotFoundException: org.sqlite.JDBC
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1672)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1517)
I'm sure this has got to do something with my lack of knowledge of how applications are deployed on the web.
The runtime classpath can be different from the build classpath. Create an explicit launch configuration. The default will start with the build classpath but you may have to manually tweak it to include those 3rd party jars.
I've run into this problem before with Eclipse and the Web Server Tools project. Check your .settings files and other files for configuring the plugins that you're using with your project. You may have to remove some filters in the Eclipse view. WST constructs its build path differently, so it may not be using the jars that you've included in your project.
I figured it out. I just had to put all the jars in the WEB-INF/lib directory. I assumed that Eclipse would do all the required settings for me when I asked it to use the mentioned jars. But I guess there are somethings that are not automated very well.
I'm new to Java. I have to modify this Web Servlet that is running on my Tomcat. The Webapps folder contains several files and directories, but only one .JAR file. I managed to decompile it using Java Decompiler JD-GUI, but when I create the project in Eclipse from the decompiled source and try to Validate it, Eclipse shows me around 389 errors. Errors like
HttpServlet cannot be resolved to a type
And I don't even know which Eclipse button rebuilds the .JAR file. Can anyone help me?
Your eclipse project will need to include the libraries that the servlet relies on to work.
If you create the Eclipse project as a Dynamic Web Project it will set up some of the basic structure needed, including the relevant libraries. You may need to include other libraries if the original code relies on them, but from your description it seems fairly unlikely.
You can create a JAR file from the Eclipse File Menu. click Export..., and select Java->Jar file.
Many projects will use ANT which allows you to define scripts to perform tasks needed to compile, package, deploy and test a project.
you create the Eclipse project as a Dynamic Web Project it will set up some of the basic structure needed, including the relevant libraries. You may need to include other libraries if the original code relies on them,
create a JAR file from the Eclipse
File Menu
click Export..., and select Java->Jar
file.