Connect and share knowledge within a single location that is structured and easy to search. I created a jar file containing all my compiled stuff. Additionally my ant build script copies the required libs into a subfolder "libs".
The structure looks like this:. You use either -jar or -cp , you can't combine the two. If you want to put additional JARs on the classpath then you should either put them in the main JAR's manifest and then use java -jar or you put the full classpath including the main JAR and its dependencies in -cp and name the main class explicitly on the command line. With this in place, java -jar MyProgram.
When the -jar option is used the -cp option is ignored. The only way to set the classpath is using manifest file in the jar. It is easier to just use the -cp option, add your jar file to that, then explicitly call the main class.
You cannot specify a folder of jar file but must specify each jar file individually in the classpath it is worth writing a simple shell script to do this for you if there are a significant number of jars.
It is a bit tricky. The following script is an attempt to get the classpath from the manifest of the jar and then allow to add extra classpath entries. I had mixed results with this but want to share the script nevertheless so it might be made fully functional here. For quick, one-off tests of an app, you can simply symlink the needed dependency JAR files into the directory containing the main app JAR file.
I am using Java 6. You can try java -Djava. If you really need to specify all the. There's a commons project called Commons Launcher which basically lets you specify your startup script as an ant build file if you see what I mean. Check out this StackOverflow issue for more information. The workaround is to put a semicolon right after the wildcard. Tried it with another program too, rather than the built-in echo , with the same result.
I believe that it's javac which is trying to expand it, and it behaves differently whether there is a semicolon in the argument or not. First, it may be trying to expand all arguments that look like paths. And only then it would parse them, with -cp taking only the following token. Note that com. That's all a guess. All the above solutions work great if you develop and run the Java application outside any IDE like Eclipse or Netbeans. Your source code in Eclipse is having the following package hierarchy: edu.
But when you try running this using Command Prompt after compiling Main. This is because you have placed the Main. Long Form: I've made this explicit to the point that I hope even interlopers to java can make use of this.
There are three options on 'Library handling' eclipse Juno offers:. Typically I'd use opt2 and opt1 was definitely breaking , however native code in one of the jars I'm using I discovered breaks with the handy "jarinjar" trick that eclipse leverages when you choose that option. Even after realizing I needed opt3, and then finding this StackOverflow entry, it still took me some time to figure it out how to launch my main outside of eclipse, so here's what worked for me, as it's useful for others If you named your jar: "fooBarTheJarFile.
For Java Newbies: 'package. The pitfall to notice: is that having 'fooBarTheJarFile. You need to explicitly declare '-jar', and redeclare the location of that jar. For Java 13 on macOS Mojave …. If all your. Verify with pwd.
For the -classpath you must first list the JAR file for your app. Lastly, pass the full package name of the class with your main method. You need to add them all separately. Alternatively, if you really need to just specify a directory, you can unjar everything into one dir and add that to your classpath.
I don't recommend this approach however as you risk bizarre problems in classpath versioning and unmanagability. Scripted for Linux, could have a similar one for windows too. Think of a jar file as the root of a directory structure. Yes, you need to add them all separately. I have multiple jars in a folder.
The below command worked for me in JDK1. Please note that to include in quotes if you have a space in the classpath. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Including all the jars in a directory within the Java classpath Ask Question. Asked 13 years, 2 months ago. Active 11 months ago. Viewed 1.
Many Java integrated development environments have global or project-specific settings that accomplish the same result. But these settings are totally IDE-specific and won't be discussed here. Another alternative is to make a. You could use the autoexec. This is the default operation. The ServiceName is the name of the executable without exe suffix, meaning Tomcat9. List of services that this service depend on. Dependent services are separated using either or ; characters. User account used for running executable.
Use either auto i. One of jvm , Java or exe. Class that contains the startup method. List of parameters that will be passed to either StartImage or StartClass. Class that will be used on Stop service signal. List of parameters that will be passed to either StopImage or StopClass. Defines the service log filename prefix. Defines the logging level and can be either Error , Info , Warn or Debug. Redirected stdout filename.
And the reference has to be a relative or absolute directory to where you run the java -jar MyJar. HOW TO? When you specify -jar then the -cp parameter will be ignored. From the documentation : When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
App is the fully qualified name of the class from the JAR that has the main String[] method The jar and dependent jar should have execute permissions. You can do these in unix shell: java -cp MyJar.
0コメント