How to Invoke a main class in a jar file from my project
Hi
I am a new user of the Sun Java Studio enterprise. I would like to know how i can invoke a main method in a jar file associated to the project.
regards
Nisanth
Could you please clarify: do you want to run your project or a project from an independent jar?
In the first case just select Run Project from the project context menu or select a class with main method and click Run File in the class context menu.
Regarding the second case:
- I don't think there is such a feature in the IDE (running third party jars is not an IDE function). Could you explain why you need this?
Similar Messages
-
Don't know how to make my main class import a jar file
OK, the title doesn't make much sense but here are my create-jar.bat and manifest files:
create-jar.bat:
jar cvmf manifest.txt dassimul-admin.jar player/ admin/ com/ connector/ common/ *.class
manifest.txt:
Main-Class: admin.DASAdmin
the problem is that in connector/ folder there is the jdbc mysql connector driver (.jar file).
in Eclipse I can add this jar to the Java Build Path, so the program runs.
When I double-click the dassimul-admin.jar file, I get a Class Not Found Exception
C:\MYWORK\dassimul>java -jar dassimul-admin.jar
FATAL ERROR WHILE LOADING SQL DRIVER: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I think that the problem lies in the fact that admin.DASAdmin can't see and import the jar file in connector/ folder... am I right?It looks like you are putting the mysql jar file inside the dassimul jar. That won't work unless you write custom code. You should use the Class-Path attribute of the manifest to define a relative path(s) to the other jar(s) that you need to use.
[http://java.sun.com/docs/books/tutorial/deployment/jar/index.html] -
How do I list all classes in a Jar file?
How do I list all classes in a Jar file?
Its no problem if the jar file contains classes, but I have an EAR file, which contains a jar-file, and I want to list all classes in that jar-file.
I would like to do something like this:
java.util.jar.JarFile jarfile = new java.util.jar.JarFile( new File("/meYear.ear"), true );
java.util.jar.JarEntry jar = jarfile.getJarEntry( "myJar.jar" );
// Cast it to a new JarFile:
java.util.jar.JarFile newJar = (java.util.jar.JarFile)jar;
But the method getEntry returns something like jarFile$JarEntry, if I try to class cast it I get an classCastException. -
Is it possible to call a class in a jar file from JNI environment?
Hi
Is it possible to call a class in a jar file from JNI environment?
Thanks in advance.Could you explain a bit more what you are trying to do? (In other words, your question is vague.)
o If your main program is written in C, you can use JNI to start a JVM, load classes from the jar of your choice, and call constructors and methods of the objects defined in the jar.
o If your main program is java, and has been laoded from a jar, a JNI routine can call back into java to use the constructors and methods of classes defined in the jar(s). -
How to include the inner classes in a jar file in netbeans ide
Dear java friends
how to say to netbeans ide that it has to include the
inner classes in the jar file.
(i have one single applet class
with two inner classes that show up
in the build/classes file but not in the jar).
The applet works in the viewer but not
in the browser (I believe because the
xxx$yyy etc should be in the jar)
willemjavFirst, please stop posting the same question multiple times:
Duplicate of http://forum.java.sun.com/thread.jspa?threadID=5269782&messageID=10127496#10127496
with an answer.
Second, If your problem is that you can't do this in NetBeans, you need to post to somewhere that provides NetBeans support - like the NetBeans website's mailing list. These forums do not support NetBeans (or any other IDE) - they are Java language forums. -
Hi
I have created a ja file containing my whole project.
the jar file contains a java class which contains a main method.
now i want to run this java class present in my jar file from the command prompt. is it possible to do it. can we run a java file which is inside the jar file.
i don't want to extract the jar file to run the java class.
Please let me know what needs to be done in this case.
Thanks & Regards
Vikengnow i want to run this java class present in my jar
file from the command prompt. is it possible to do
it. can we run a java file which is inside the jar
file.
java -jar MyJar.jarYou need to set the Main-Class attribute in the manifest, though. -
How to load all the classes in a JAR file at runtime?
Any clues o:
"How can I force JVM to load all the classes in a specified JAR at once?"
Thanx!
-RajeevWell I was thinking may be there exists an option with "java", when I
am starting an application from a jar file, I could force it to load all
the classes in the JAR. I don't want to do it programically. Is there such
an option available?? Or in other words can I ask JVM to not do the dynamic
loading for the JAR??
Thanx.
List all JarEntries and convert the paths to fully
qualified class files
e.g file in jar
[1] /com/mycompany/proj/X.class
should become
[2] com.mycompany.proj.X
then for each entry issue
Class.forName( [2] ); -
How to access all the classes in a jar file
hai
i have a custom built JAR file which has many classes(Translets) in it . i want to access the classes inthe JAR file in a JSP page or an servlet. I have tried setting the classpaths etc , but nothing has happened.
Where should the jar file be Palced - i am using Tomcat Server.
How Can i Access the class files .. Very Urgent .. Please Help me ..
Peter IyerWhat is showing a file not found error? The web browser? if so, that's probably not a problem with the jar file.
Also, have you expanded your jar file to make sure that you jarred it up correctly? -
How to tell if a class within a jar file is being accessed?
Hello,
I have written a web app using NetBeans 5.5 and some external libraries.
Rome 0.9 and a Rome module georss-rome.jar.
Everything works fine with the integrated Netbeans tomcat 5.5...
When I try to deploy this as a war using Tomcat 5.5 standalone It will not work properly. To make things worse, I get no error.
In my code, I instantiate a class in the georss module by doing the following:
GeoRSSModule geoRssModule = GeoRSSUtils.getGeoRSS(entry);
if(geoRssModule != null)
...do something;
}I then check for null and if not null I do stuff with methods within that jar.
Basically I pass a rss feed or a georss feed. If its a georss feed then geoRssModule would not be null.
As I said, this works fine within integrated tomcat but does nothing (no expected action) with standalone which leads me to believe that this is a deployment/jar/classpath issue.
To me it seems that the class GeoRSSModule is never actually instantiated, but I never get any errors or expected output.
I set tomcat logging.properties to FINEST for all types of logging.
Is there a way to determine if the jar is even being accessed for that class file?
TIA!
BTW, I dont have the module source.
I also verified that the jars (rome.jar and georss-rome.jar) are being deployed to webapps/myapp/WEB-INF/lib
Message was edited by:
gfortyGeoRSSModule geoRssModule = GeoRSSUtils.getGeoRSS(entry);Try placing logging statements before and after this statement so that you can track execution. Make sure that your code at least gets to this particular line where you instantiate the GeoRSSModule object. Then place a logging statement afterwards to see if an object was indeed created.
What helps me in situations like this is that I also use the NetBeans attached debugger listening on your standalone Tomcat installation. This allows you to trace your execution on the server side, one line at a time, giving you a clearer understanding of program flow. -
How to run 1 or more main classes in a jar?
Hi there,
I have 2 or more main classes in a java project. How do I create more than one application entry point in my MANIFEST.INF? I create my jar file from my java project using Eclipse, and it asked me to "Select the class of the application entry point". I was only able to select one main class.
I noticed the MANIFEST.INF file that eclipse generated looks like:
Manifest-Version: 1.0
Main-Class: Automobile
When I tried to run my other classes not specify in the MANIFEST.INF it failed and only look for the Automobile class:
java -jar /tmp/Auto.jar TestMeYour app. can have as many entry points as you like, as atmguy demonstrated. But you can only specify one in the manifest,which - if you think about it - makes perfect sense. How is the machine to determine - from you clicking on the jar - which entry point you meant to invoke?
-
Could not find the main class (with every jar)
This isn't a developer question. I get the error Could not find the main class with every jar I try to open (for example the jar downloaded from https://gjar.dev.java.net/ gives the same problems - and I don't think there is something wrong with that JAR). It isn't a problem with the jar or MANIFEST because the same jar works fine on my laptop. So there is something wrong with my JRE installation, but what?
I tried to remove and reinstall the JRE 6 Update 18 but that didn't work. When I run the JAR with command line java -jar "file.jar" it works fine, but if I dubbelclick on it I get the error message (and it's irritating me).
I'm a bit desperate so I hope that someone here can help me ;)
Thanks in advancedhai T.B.M ... Sorry to post here... I know that i posted my question in wrong thread..but i dont have another solution to contact with you.. I had seen your answers which are really excellent and helped to do my project..
Now i am having very less time to complete my project and i am very new to JMF.. I am not getting output in JMF video capture ..please check the code and guide me where i gone wrong.......please pardon me once again to post here.. Heres my code
import javax.media.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import javax.media.protocol.*;
import java.io.*;
import javax.media.control.StreamWriterControl;
public class webcam implements ActionListener,ControllerListener
boolean eomReached = false;
boolean realized = false;
JFrame f;
BorderLayout bd1;
CaptureDeviceInfo device;
MediaLocator m1;
Player player;
Component videoScreen;
JButton b1,b2;
Processor processor;
DataSource ds=null;
DataSink fileWriter=null;
JLabel status=new JLabel("");
public webcam()
try
JFrame f=new JFrame();
JPanel p =new JPanel();
JPanel p1=new JPanel();
device=CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture (Win32):0");
m1=device.getLocator();
System.out.println("1");
processor.configure();
processor = Manager.createProcessor(m1);
processor.setContentDescriptor(new
FileTypeDescriptor(FileTypeDescriptor.MSVIDEO));
ds=processor.getDataOutput();
player.addControllerListener(this);
MediaLocator dest = new MediaLocator("file://foo.avi");
fileWriter = Manager.createDataSink(ds, dest);
fileWriter.open();
ds.connect();
ds.start();
player=Manager.createPlayer(m1);
player.addControllerListener(this);
blockingRealize();
videoScreen=player.getVisualComponent();
b1=new JButton("START");
b2=new JButton("STOP");
bd1=new BorderLayout();
p.setLayout(bd1);
p1.add(b1);
p1.add(b2);
p.add("South",p1);
p.add("East",videoScreen);
f.getContentPane().add(p);
f.setVisible(true);
f.setSize(500,500);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1.addActionListener(this);
b2.addActionListener(this);
catch(Exception e){}
public void actionPerformed(ActionEvent e)
if(e.getSource()==b1)
try{
processor.start();
player.start();
fileWriter.start();
catch(Exception e1){}
if(e.getSource()==b2)
try{
player.stop();
processor.stop();
processor.close();
fileWriter.close();
catch(Exception e2){}
public static void main(String args[])
webcam obj=new webcam();
public synchronized void blockingRealize() {
player.realize();
while (!realized) {
try {
wait();
} catch (java.lang.InterruptedException e) {
status.setText("Interrupted while waiting on realize...exiting.");
System.exit(1);
public synchronized void controllerUpdate (ControllerEvent event) {
System.out.println("myPlayer generated "+event.toString());
if (event instanceof RealizeCompleteEvent) {
realized = true;
notify();
} else if (event instanceof EndOfMediaEvent) {
eomReached = true;
} -
How to invoke system editor by double click a file(windows)?
how to invoke system editor by double click a file(windows)?
Just like that, double click a file named a.doc, windows will open it by word.exe.I try that:
exec("cmd /c start winword \"c:\dir\a b.doc\"");
like this posting(http://forum.java.sun.com/thread.jspa?forumID=57&threadID=634576 ), and It is ok.
But now I make a file list with different files, .pdf,.xls,.doc and so on, I wanna double click to open one with its default system editor.
if no space:
exec("cmd /c start " + file);
will invoke the default editor to open it. if space, it can't do it.
And now I rename all files, replace space to _. -
Accessing classes in external jar files
I have a jar file called main. I want it to be able to acces the classes in another jar file say test.jar how do i do this.
Thank youok, if i have this right...
you have 2 directories that hold 2 .jars, right?
plugins/ -------- build/plugins .jar
systemModuals/ ------- DiaryUI and Loader .jar
Your main JAR is diary?
Diary.jar
you want Diary to run with the jars inside plugins and systemmoduals?
you set the "class-path:" tag like this....
write this manifest file. save it as Manifest.txt and put it in your home dir.
Main-Class: YourMainClass
Class-Path: Diary.jar plugins/this.jar systemmoduals/diaryui.jar
<make sure to hit enter, go to the next line>
command line to your parent directory.
jar cmf Manifest.txt Diary.jar build/main/*.class
you should be set to go.
use
jar xf META-INF/MANIFEST.MF
to read the present manifest that netbeans has created
if necessary -
How to call a jar file from oracle forms (6i)
Hi,
I'm working with oracle 6i. I want to know that how to call a .jar file from forms menu. when I use HOST('<path>\test.jar') it is working in 'Client Server' any way. but the problem is I use application server in order to run my form. so my form is in the server and I run the form via clients web browser. in that case above solution will not work. if any body knows how to overcome this problem please reply.
thanks.
dumindaI created a bean area and set the class name as implementation class. within that java bean class I called to a bat file which consists of the execution command of the jar file ( because i don't know how to call .jar file from my bean class directly).
then i tried to run it in application server. its still not running.
can you tell me what i have to do within my bean class? or can you suggest any solution?
thank you. -
How do you know the version of a JAR file ?
how do you know the version of a JAR file ?
is it what is written on MANIFEST.MF ?
for example i have a JAR file
whose MANIFEST.MF has this
Manifest-Version: 1.0
Created-By: Ant 1.4.1so, whats the version of this JAR ? 1.0 ?anyway, that was JSTL..jar.
Now, come to another JAR file....
whose MANIFEST.MF has......
Manifest-Version: 1.0
Created-By: Apache Ant 1.5.1
Extension-Name: Struts Framework
Specification-Title: Struts Framework
Specification-Vendor: Apache Software Foundation
Specification-Version: 1.1
Implementation-Title: Struts Framework
Implementation-Vendor: Apache Software Foundation
Implementation-Vendor-Id: org.apache
Implementation-Version: 1.1
Class-Path: commons-beanutils.jar commons-collections.jar commons-dig
ester.jar commons-logging.jar commons-validator.jar jakarta-oro.jar s
truts-legacy.jarso, How do you believe whats the version now ? do u go with the comment "Manifest-Version: 1.0" or "Specification-Version: 1.1" ?
definitely, you would go with the "Specification-Version: 1.1" and declare this JAR as STRUTS 1.1
hmmm, so, if nothing is mentioned like above should we follow the MANIFEST version as the JSTL version ? in my earlier example i did not find any comment on ""Specification-Version" ......so , if anybody gives me that JAR , how do i decide whether its 1.0 specification or 1.1 specifucation compliant ?
can you tell whats the JSTL version of my earler example JAR file ?
Maybe you are looking for
-
Can't get Transport Mode to Work
Just messing around in a lab with a few routers. Trying to bring up transport mode first on an IPSEC tunnel. All seems correct, but it constantly comes up in Tunnel Mode. I can't see why? Can anyone see anything obvious? Enclosed are configs and a Wi
-
Automatic testing of some external options
Hello, while executing one test case I need to do svn update and edit some file outside my launched application. I already got some ideas from https://www.eclipse.org/forums/index.php/t/805353/ One possibility would be to write a script and call it i
-
ArrayOutOfBound exception thrown in JAI API
Hi I am getting exception ArrayOutOfBound exception for one of my image sample that i tried. The code snippet is src is a BufferedImage. IndexColorModel icm = (IndexColorModel)src.getColorModel(); int numBands = 3; if(icm.hasAlpha()) numBands = 4; by
-
SQL Server 2012 Express Edition SP1 Limitations
Our software company is working on many project where are used several versions of SQL Server (2005, 2008, 2008R2, 2012). Our ICT department applies a procedure that involves the installation of a developer version of the product (each product versio
-
Transaction control of app module implementation , from a SLSB
Hi, We are using a Session bean , to invoke app module implementation - service methods to manipulate VOs. The service method of app module is having control of transactions , like commit . We want to have this control from stateless session bean. Co