| |

VerySource

 Forgot password?
 Register
Search
Author: xenon1

How to call an unpackaged class under a packaged class

  [Copy link]

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-28 21:45:01
| Show all posts
[Quote=Quote the reply ofasd8582885on the 4th floor:]
Compressed directly into zip format, all files are in the root package, and then directly imported into eclipse lib, OK!
[/Quote]
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-28 22:15:01
| Show all posts
[color=#FF00FF] Pack it yourself

Or add the file directory to the CLASSPATH[/color]
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-28 22:30:01
| Show all posts
It's hard to say about packaging, because there must be a package statement in each .class file, if not, it's okay. if so. You just decompile it, find the package statement declared by each .class file, and then create a directory according to the statement, and then put the .class files in the created directory one by one. Note that the directory name must be consistent with the defined package. Then pack them together, so there should be no problem
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-28 22:45:02
| Show all posts
Put it in the same folder as the .class with the package class!
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-28 23:00:01
| Show all posts
Put the folder containing the entire .class file into a jar package, or compress it into a zip format, and import the external JAR in your class library tag!
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-28 23:15:01
| Show all posts
Yes, try a jar package
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-28 23:30:02
| Show all posts
up down
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-28 23:45:01
| Show all posts
[Quote=quote the reply ofasd8582885on the 3rd floor:]
Put the folder containing the entire .class file into a jar package, or compress it into a zip format, and import the external JAR in your class library tag!
[/Quote]
Never encountered it before, and thinkasd8582885should be feasible
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-29 00:00:01
| Show all posts
Assuming that the unpackaged library provided by the manufacturer is a separate folder
Assuming that the unpackaged class library provided by the manufacturer is in multiple folders, put them all in one folder

Pack the .class into a jar, or not to type


1. If you don't use an IDE, add this jar or folder name to the classpath.
2. If you use IDE, then add this jar or folder name to the class library, the IDE has this configuration.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-29 00:15:01
| Show all posts
[b]And when the code is placed in a class under the package, it always fails to compile. [/b]

You can simply do
1 Put those classes without packages on the root,
2 Your classes are stored in the package directory
3 Just keep up and run

/Company.class
/com/mycompany/MyCom.class

that's it

If you are running in Eclipse, please refer to the practice on the 6th floor and add the path of the class to the build path.
[Java Build Path] [Libraries] [Add Class Folder]

Of course, it’s better to package it into a jar
But the last step is changed to [Add Librairy]!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list